我可以从Google Column Chart获取vAxis.maxValue吗? [英] Can I get the vAxis.maxValue from a Google Column Chart

查看:95
本文介绍了我可以从Google Column Chart获取vAxis.maxValue吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google图表绘制了柱状图。现在我想知道该图表使用的实际vAxis.maxValue。请注意,我没有设置这个值,图表已经设置了它自己。但我想知道它使用了什么价值。我怎样才能做到这一点?

I have drawn a column chart using Google charts. Now I want to know what actual vAxis.maxValue the chart is using. Note, I have not set this value, the chart has set it itself. But I want to know what value it has used. How can I do this?

推荐答案

我还没有找到解释google如何确定其最大值和最小值的地方他们很奇怪)。在Excel中,不可能计算(这取决于字体大小,图表大小,线条粗细等)。

I haven't found anywhere that explains how google determines its max and min axis values (sometimes they are very weird). In Excel it is impossible to calculate (it depends on the font size, chart size, line thickness, etc.).

处理这种问题的最简单方法是写一个函数来确定你自己的最大/最小轴的值。下面的代码可能会有帮助(这是逻辑做到这一点,根据需要调整你的应用程序):

The easiest way to handle issues like this is to write a function to determine your own max/min axis values. The following code may help (this is the logic to do it one way, adjust as needed for your application):

// Take the Max/Min of all data values in all graphs (these are just arbitrary numbers)
var totalMax = 345;
var totalMin = -123;

// Figure out the largest number (positive or negative)
var biggestNumber = Math.max(Math.abs(totalMax),Math.abs(totalMin));

// Round to an exponent of 10 appropriate for the biggest number
var roundingExp = Math.floor(Math.log(biggestNumber) / Math.LN10);
var roundingDec = Math.pow(10,roundingExp);

// Round your max and min to the nearest exponent of 10
var newMax = Math.ceil(totalMax/roundingDec)*roundingDec;
var newMin = Math.floor(totalMin/roundingDec)*roundingDec;

// Determine the range of your values
var range = newMax - newMin;

// Define the number of gridlines (default 5)
var gridlines = 5;

// Determine an appropriate gap between gridlines
var interval = range / (gridlines - 1);

// Round that interval up to the exponent of 10
var newInterval = Math.ceil(interval/roundingDec)*roundingDec;

// Re-round your max and min to the new interval
var finalMax = Math.ceil(totalMax/newInterval)*newInterval;
var finalMin = Math.floor(totalMin/newInterval)*newInterval;

这篇关于我可以从Google Column Chart获取vAxis.maxValue吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆