2

我遇到了这个线程,这正是我想要的 Google Charts API:始终在图表中显示数据点值,但那里给出的答案适用于使用硬编码值时。

就我而言,我使用 MySQL 数据来填充图表,因此无法确定在何处以及如何准确使用该role:annonation属性。我正在使用以下代码来绘制图表。

PHP

$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);

Javascript

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);

    }
4

1 回答 1

0

我自己想通了。我所要做的就是将其添加到选项中:

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']         
};

来源:谷歌图表 API

于 2013-05-28T11:08:05.490 回答