php - 谷歌图表 API : Display Data Points (PHP + MySQL)

标签 php javascript

我遇到了这个线程,这正是我想要的 Google Charts API: Always show the Data Point Values in Graph但那里给出的答案在使用硬编码值时适用。

在我的例子中,我使用 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);

    }

最佳答案

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

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

关于php - 谷歌图表 API : Display Data Points (PHP + MySQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16786226/

相关文章:

php - 获取 date_default_timezone_set 的时区标识符?

php - 捕获时的 Auth.net 问题

php - wp_get_current_user null 如果我直接在某些 PHP 文件中访问它

javascript - Babel 加载器导致 npm build 崩溃

javascript - knockout 映射无法更新 observableArray

php - 我收到此错误错误 : Incorrect time value: '16:44:09 PM' for column 'time' at row 1 and I'm not sure why

php - Laravel Nova,找不到路线

javascript - HTML 表格 : Sticky column overlapping header

javascript - 我的欢迎信息令人困惑。 (不和谐.js)

javascript - 如何让滚动条始终位于聊天底部