我折線圖上工作,但有問題的是該行的格式不能被改變:谷歌線圖表轉換的TimeOfDay進行編號
function drawChart(){ var data = new google.visualization.DataTable(); data.addColumn('timeofday','quartal');
我想在橫軸一個簡單的數字格式(1,2,3,4作爲宿舍),但是當我將其更改爲「數字」時,圖表消失。
第二個問題是,圖表通過懸停線條'NaN:NaN'顯示。我認爲這是由錯誤的格式造成的。
JSON格式是這樣的:4 [1,0,1],[2],1,1],[[3],1,1],[[4],2,8]
無法理解爲什麼上面的1,[2],[3],[4]不能是數字。
這是我的實際圖表:
我已經以下代碼:
<?php
$conn = new mysqli($servername, $username, $password, $dbname);
$qry = "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";
$result = $conn->query($qry);
if($result === FALSE) {
echo mysqli_errno($result) .": ". mysqli_error($result) ."/n";
die(mysqli_error());
}
$i = 0; //iteration counter - start at 0
$totalRows = mysqli_num_rows($result); // we need this to know when to change the output
$targetRows = $totalRows - 1; //row indies start from 0, not 1.
foreach ($result as $row){
//$comTime = str_replace(":",",",$row['quartal']); // for each row, remove the : and put , in its place -> nur wenn Zeitformat vorhanden
$comTime = $row['quartal'];
if ($targetRows == $i) { // if the index is the same value as the target (ie, it's the last row)...
$temp = "[[".$comTime."],".($row['Ja']).",".($row['Nein'])."]". PHP_EOL;
} else {
$temp = "[[".$comTime."],".($row['Ja']).",".($row['Nein'])."],". PHP_EOL;
}
$i = $i + 1;
$rows[] = $temp;
}
$table = $rows;
$data = implode($table); //format the table as a single string, with line returns
echo $i;
echo $data;
?>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart(){
var data = new google.visualization.DataTable();
data.addColumn('timeofday','quartal'); //
data.addColumn('number','Ja'); //Typ number
data.addColumn('number','Nein');
data.addRows([
<?php echo $data; ?> //dump the result into here, as it's correctly formatted
]);
var options = {
title: 'Recorded Temperatures',
legend: { position: 'top' },
width: 900,
height: 500,
hAxis: { format:'hh:mm:ss'},
hAxis: { gridlines: { count: 4 } }
};
var chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(data, options);
}
</script>
謝謝你的快速回復,但我不想一個timeofday格式,我想要的只是一個數字,但只有一個timeofday可與該圖在此時此刻。 需要幫助以瞭解如何更改代碼以獲取x軸上的數字1,2,3,4。 – Ck2513
看到__EDIT__以上... – WhiteHat
非常感謝你,這正是我想要的! – Ck2513