2
A
回答
2
你應該使用以下參數gridlines:{count}
,例如打
hAxis: {
minValue: 1.00,
maxValue: 5.00,
baseline: 3.00,
viewWindowMode:'explicit',
viewWindow:
{
max: 5.00,
min: 1.00
},
gridlines:{count:11}
},
vAxis: {
minValue: 1.00,
maxValue:5.00,
baseline:3.00,
viewWindowMode:'explicit',
viewWindow:
{
max:5.00,
min:1.00
},
gridlines:{count:11}
}
0
此問題已經回答here。
而這正是它說:
如果你只是想號碼顯示爲整數,那麼它的 簡單:
function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ ['x', 'Cats', 'Blanket 1', 'Blanket 2'], ['A', 1, 1, 0.5], ['B', 2, 0.5, 1], ['C', 4, 1, 0.5], ['D', 8, 0.5, 1], ['E', 7, 1, 0.5], ['F', 7, 0.5, 1], ['G', 8, 1, 0.5], ['H', 4, 0.5, 1], ['I', 2, 1, 0.5], ['J', 3.5, 0.5, 1], ['K', 3, 1, 0.5], ['L', 3.5, 0.5, 1], ['M', 1, 1, 0.5], ['N', 1, 0.5, 1] ]); // Create and draw the visualization. new google.visualization.LineChart(document.getElementById('visualization')). draw(data, {curveType: "function", width: 500, height: 400, vAxis: {maxValue: 10, format: '0'}} ); }
如果你去google playground你會注意到該軸標籤 是0,2.5,5,7.5,10.通過添加格式: '0' 到vAxis,它 將只顯示整數,所以我的標籤成爲0,3,5,8,10。 但是顯然這不是因爲8個顯示理想爲中途 5和10之間,它是沒有,因爲數實際上是7.5 和只是被倒圓。
你改變軸刻度/標籤的能力受到限制。要做到 你問會採取JavaScript的一個特殊位創建 適當的規模和網格線的數量,以防止摔東西 下降到時髦的數字內容。
基本上,你要確保你的最大值和最小值, 和網格線的數量,可以很容易地劃分,這樣你將只有 得到整數。要做到這一點,你需要創建一些時髦的新的邏輯 。下面是一些示例代碼,將讓你得到一個 適當的最小/最大軸值:
// Take the Max/Min of all data values in all graphs 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;
有幾個問題在這裏(不幸)。第一個是我使用的網格線的數量來確定最小/最大值是 - 你 想弄清楚你應該有多少個網格線必須使用好的 整數。最簡單的方法來做到這一點,我想,是因爲 如下(僞代碼只):
// Take the Max/Min of all data values in all graphs var totalMax = 3; var totalMin = -1; // 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; // Calculate the best factor for number of gridlines (2-5 gridlines) // If the range of numbers divided by 2 or 5 is a whole number, use it for (var i = 2; i <= 5; ++i) { if (Math.round(range/i) = range/i) { var gridlines = i } }
然後,設置網格線選項(vAxis.gridlines)以上 變量,你的最大至newMax,你的分鐘到newMin。這應該 給你整個號碼軸標籤。
注意:如果你的數字是非常小的,然後上面的功能可能無法 工作。該功能還沒有經過測試,所以請檢查對一些 例子在你自己的時間,讓我知道,如果它不能正常工作。
1: http://code.google.com/apis/ajax/playground/?type=visualization#line_chart
相關問題
- 1. 連續軸谷歌圖表加載CSV?
- 2. 谷歌圖表:上BARCHART
- 3. 谷歌-圖表上護欄
- 4. 谷歌圖表線:如何使用連續座標軸正確連接點
- 5. 谷歌圖表不顯示
- 6. 谷歌圖表:不顯示
- 7. 谷歌表格腳本連續/嵌套正則表達式
- 8. 谷歌圖表和谷歌表不同時顯示
- 9. 在谷歌加載谷歌圖表
- 10. setRadius圓上給出了谷歌地圖用戶體驗不好
- 11. JavaScript驗證了谷歌表單/谷歌表
- 12. 與谷歌圖表
- 13. 谷歌圖表 - BoxPlot
- 14. 谷歌圖表計
- 15. 谷歌圖表vAxis
- 16. 谷歌圖表API
- 17. 從谷歌圖表
- 18. 谷歌地圖不能在設備1加1(棉花糖)
- 19. 谷歌地圖javascript api不能在多個連接上工作
- 20. 在黑莓上使用谷歌圖表
- 21. 谷歌圖表上的滾動條
- 22. 谷歌圖表折線圖
- 23. 谷歌地圖不顯示在Firefox上
- 24. 谷歌圖表不顯示數據
- 25. 「空」是不是與谷歌圖表
- 26. 谷歌圖表不給輸出
- 27. 谷歌圖表條不同顏色
- 28. LineWidth不會更改谷歌圖表
- 29. 谷歌圖表傳奇不會消失
- 30. 谷歌圖表不顯示軸標籤
但最大值可以是任何東西,最小爲1,但最大可能是無窮大。 – Frank 2013-02-14 17:28:36
我想在這種情況下,您需要一個函數來計算和縮放網格線的值 – 2013-02-14 17:31:06
我在下面的答案中包含了一個函數。希望能幫助到你。 – jmac 2013-02-15 00:24:05