我正在开发一个绘制一些图表的应用程序,并且我正在使用 Google Chart。在我拥有所有需要的数据后,我会动态地构建 URL。问题是 Google Chart 并不总是将图表的最大值和最小值固定为我提供的值。我根据购物车的数据计算最大值和最小值。我已将它们设置为始终为整数以避免任何问题。
我将用数字设置一个示例:(我用“注释(//)”将它写在不同的行中,以便可以轻松阅读,尽管它与任何注释在同一行)
http://chart.apis.google.com/chart?
cht=bvs& //chart type
chs=250x250& //chart size
chd=t:10,0|4.48,0|15,-58.42|0,4.73|0,73.44& //chart data
chco=4D89D9,C6D9FD,FF0000,00FF00,0000FF& //chart colors
chds=-59,80& //data scaling
chf=bg,s,edf5ff|c,s,f6e426& //chart fill color
chtt=my_title& //chart title
chdl=A|B|C|D|E& //chart legend
chdlp=r& //legend position
chxt=x,y& //chart axis
chxl=0:|Col_1|Col_2& //Axis labels
chxr=1,-59,80& //Axis range
chbh=r,1,0& //Bar thickness and spacing
chg=0,12.5 //Grid Lines
有了这个配置,我会得到这个图表。如您所见,零线超过零,因为数据尚未缩放是一个好方法。
但是如果我将图表的最大值和最小值更改为 -60,80,我会以一种很好的方式得到它
这将是这样的代码:
http://chart.apis.google.com/chart?
cht=bvs& //chart type
chs=250x250& //chart size
chd=t:10,0|4.48,0|15,-58.42|0,4.73|0,73.44& //chart data
chco=4D89D9,C6D9FD,FF0000,00FF00,0000FF& //chart colors
chds=-60,80& //data scaling (CHANGE IN THIS LINE)
chf=bg,s,edf5ff|c,s,f6e426& //chart fill color
chtt=my_title& //chart title
chdl=A|B|C|D|E& //chart legend
chdlp=r& //legend position
chxt=x,y& //chart axis
chxl=0:|Col_1|Col_2& //Axis labels
chxr=1,-60,80& //Axis range (CHANGE IN THIS LINE)
chbh=r,1,0& //Bar thickness and spacing
chg=0,12.5 //Grid Lines
这张图表似乎还可以:
谁能告诉我为什么 Google Chart 会这样?
谢谢