dongzanghong4379 2011-11-09 00:42
浏览 28
已采纳

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

I have some data in mysql that I load up in php and draw a line chart using the google chart api.

Here is part of the code:

// ... 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;

So that works fine, except that my "value1" or "v1" data will generally range from a minimum of 10 to a maximum of 90. My "value2" or "v2" data will start off at 0, and over time will increment - potentially to 100,000 or more.

I am trying to figure out how to either set the google chart up so it will display it somehow, OR potentially alter the data in the array so it displays properly.

Currently, it would draw a line, starting a 0, then hour by hour it would climb a little, forming a staircase-like shape. The problem is, it eventually goes past 99, and you have no more line, or similar.

Just looking for some thoughts.

  • 写回答

2条回答 默认 最新

  • dqmchw0071 2011-11-14 12:57
    关注

    I ended up adding some logic to my php code to check the previous value in the loop, and set the value to "10" if it increased, "0" if it stayed the same. I can not see the amount it increased (though I am sure mathematically I could calculate that), but in my case all I care about is to know during that time IF it incremented. On my chart, I see a line ranging from 0, jumping to 10 for a few ticks, then going back down to 0.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障