gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:32:19 24 4
gpt4 key购买 nike

我遇到了这个线程,这正是我想要的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com