[英]Google Charts API : Display Data Points (PHP + MySQL)
我碰到了這個線程,正是我想要的Google Charts API:始終在Graph中顯示數據點值,但是使用硬編碼值時,此處給出的答案仍然適用。
就我而言,我使用MySQL數據填充圖表,因此無法弄清楚在何處以及如何准確使用role:annonation
屬性。 我正在使用以下代碼繪制圖表。
$table = array();
$table['cols'] = array(
array('label' => 'Month', 'type' => 'string'),
array('label' => 'Benchmark', 'type' => 'number')
);
$rows = array();
foreach($someArray as $mnth=>$array)
{
$temp = array();
$temp[] = array('v' => (string) $mnth);
$temp[] = array('v' => (int) $benchMark);
foreach($array as $pt)
{
$temp[] = array('v' => (int) $pt);
}
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
google.load('visualization', '1', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable(<?php echo $jsonTable; ?>);
var options = {
title: 'TNS',titleTextStyle: {color: "green"}, hAxis: {title: "MONTH", titleTextStyle: {color: "green"}}, vAxis: {title: "Percentage", titleTextStyle: {color: "green"},viewWindowMode: 'explicit',
viewWindow: {
max: 110,
min: 0
}},
is3D: 'true',
height:600,
colors: ['black', 'red', 'green', 'blue', 'yellow']
};
var chart = new google.visualization.LineChart(document.getElementById('tns1'));
chart.draw(data, options);
}
我自己弄清楚了。 我要做的就是將其添加到選項中:
pointSize: 10
這樣我的配置選項就變成了
var options = {
title: 'TNS',titleTextStyle: {color: "green"}, hAxis: {title: "MONTH", titleTextStyle: {color: "green"}}, vAxis: {title: "Percentage", titleTextStyle: {color: "green"},viewWindowMode: 'explicit',
viewWindow: {
max: 110,
min: 0
}},
pointSize: 10, // <----- this is what did the trick
is3D: 'true',
height:600,
colors: ['black', 'red', 'green', 'blue', 'yellow']
};
消息來源: Google Chart API
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.