2017-10-09 1 views
1

と各エントリの2つの異なるバーを取得するにはどうすれば2つの異なるバーと、このような棒グラフを取得したい: Google bar chartGoogleのバーチャート - JSON

しかし、私はJSONでこれを行う方法を、知りません。各x軸のエン​​トリごとに赤色と青色の棒が必要です。

<?php 
$con = new mysqli($servername, $username, $password, $dbname); 

$query = "SELECT COUNT(CASE WHEN name_Gleitzeitrahmen = 'Ja' THEN 1 END) as Ja,COUNT(CASE WHEN name_Gleitzeitrahmen = 'Nein' THEN 1 END)as Nein,quarter(datum) as quartal FROM dashboard GROUP BY quartal"; 
$exec = mysqli_query($con,$query); 


$rows = array(); 
//flag is not needed 
$flag = true; 
$table = array(); 
$table['cols'] = array(

// Labels for your chart, these represent the column titles 
percentage and string will be used for column title 
array('label' => 'quartal', 'type' => 'string'), 
array('label' => 'Ja', 'type' => 'number'), 
array('label' => 'Nein', 'type' => 'number') 
); 

$rows = array(); 
while($r = mysqli_fetch_assoc($exec)) { 
$temp = array(); 
// the following line will be used to slice the Pie chart 
$temp[] = array('v' => (string) $r['quartal']); 

// Values of each slice 
$temp[] = array('v' => (int) $r['Ja']); 
$temp[] = array('s' => (int) $r['Nein']); 
$rows[] = array('c' => $temp); 
} 

$table['rows'] = $rows; 
$jsonTable = json_encode($table); 

?> 

実際のチャートは、次のようになります:

は、ここに私のコードですActual chart

フォーマットは次のようにする必要があります

function drawStuff() { 
    var data = new google.visualization.arrayToDataTable([ 
     ['Galaxy', 'Distance', 'Brightness'], 
     ['Canis Major Dwarf', 8000, 23.3], 
     ['Sagittarius Dwarf', 24000, 4.5], 
     ['Ursa Major II Dwarf', 30000, 14.3], 
     ['Lg. Magellanic Cloud', 50000, 0.9], 
     ['Bootes I', 60000, 13.1] 
    ]); 

答えて

0

が、私は今の答えを見つけました!

私はいくつかの組み合わせを試して、最終的に正しいものを見つけました。

ここでは、次のとおりです。

$rows = array(); 
//flag is not needed 
$flag = true; 
$table = array(); 
$table['cols'] = array(

// Labels for your chart, these represent the column titles 
// Note that one column is in "string" format and another one is in "number" format as pie chart only required "numbers" for calculating percentage and string will be used for column title 
array('label' => 'Quartal', 'type' => 'string'), 
array('label' => 'Anzahl Ja', 'type' => 'number'), 
array('label' => 'Anzahl Nein', 'type' => 'number') 
); 

$rows = array(); 
while($r = mysqli_fetch_assoc($exec)) { 
$temp = array(); 
// the following line will be used to slice the Pie chart 
$temp[] = array('v' => (string) $r['quartal']); 

// Values of each slice 
$temp[] = array('v' => (int) $r['Ja']); 
$temp[] = array('v' => (int) $r['Nein']); 
$rows[] = array('c' => $temp); 

}