Google チャートを使用して縦棒グラフを描画しました。ここで、チャートが使用している実際の vAxis.maxValue を知りたいと思います。この値は設定していないことに注意してください。チャート自体が設定しています。しかし、私はそれが使用した値を知りたいです。これどうやってするの?
1 に答える
1
グーグルがその最大軸と最小軸の値をどのように決定するかを説明する場所はどこにも見つかりませんでした(時々それらは非常に奇妙です)。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;
于 2013-01-11T02:58:40.560 に答える