我使用Google图表绘制了一个柱形图。现在我想知道图表正在使用的实际vAxis.maxValue。注意,我没有设置此值,图表已自行设置。但我想知道它使用了什么价值。我怎么能这样做?
答案 0 :(得分:1)
我还没有找到解释google如何确定其最大和最小轴值的任何地方(有时它们非常奇怪)。在Excel中,无法计算(取决于字体大小,图表大小,线条粗细等)。
处理这类问题的最简单方法是编写一个函数来确定自己的最大/最小轴值。以下代码可能有所帮助(这是以单向方式执行的逻辑,根据应用程序的需要进行调整):
// 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;