如何使用php和谷歌图表api来绘制一个随时间增加的数字


How to chart a number that increases over time using php and google chart api

我在mysql中有一些数据,我在php中加载并使用谷歌图表api绘制折线图。

下面是部分代码:

// ... do a sql query , then loop and create a chart ...
while($row=mysql_fetch_array($result))
{
$values[0][]=$row['v1'];
$values[1][]=$row['v2'];
}
$width=600;
$height=500;
$scaleMin=0;
$scaleMax=99;
$chart = new GoogleChart('lc', $width,$height );
$chart->setAutoscale(GoogleChart::AUTOSCALE_OFF);
// ... other google chart setup code
$line = new GoogleChartData($values[0]);
$line->setAutoscale(false);
$line->setScale($scaleMin,$scaleMax);
$line->setLegend('value1');
$chart->addData($line);
$line = new GoogleChartData($values[1]);
$line->setAutoscale(false);
$line->setScale($scaleMin,$scaleMax);
$line->setLegend('value2');
$chart->addData($line);
// ... more lines and chart set up ...
header('Content-Type: image/png');
echo $chart;

所以这工作得很好,除了我的"value1"或"v1"数据通常范围从最小10到最大90。我的"value2"或"v2"数据将从0开始,随着时间的推移将增加-可能增加到100,000或更多。

我正试图弄清楚如何设置谷歌图表,所以它会以某种方式显示它,或潜在地改变数组中的数据,所以它显示正确。

目前,它会画一条线,从0开始,然后一小时一小时地往上爬,形成一个类似楼梯的形状。问题是,它最终超过99,你没有更多的线,或类似的。

只是在寻找一些想法。

嗯,我认为最好的答案是缩放这些值或使用替代图表(如条形图等)
这是我从谷歌图表API文档中得到的链接。http://code.google.com/p/googlechartphplib/wiki/Autoscaling
http://code.google.com/intl/fr-FR/apis/chart/image/docs/data_formats.html scaled_values

我最终在php代码中添加了一些逻辑来检查循环中的前一个值,并将值设置为"10",如果它增加,则设置为"0",如果它保持不变。我看不到它增加了多少(尽管我确信我可以用数学方法计算出来),但在我的情况下,我所关心的是知道在这段时间内它是否增加了。在我的图表上,我看到一条线,从0跳到10,然后又回到0。