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

报告相同问题?

悬赏问题

  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动