2016-10-31 81 views
1

我試圖做谷歌圖表對數刻度圖(實際上是一個semilogy情節,是準確的),並試圖
vAxis: { scaleType: 'log' }
沒有成功。我也看到了谷歌的例子(https://jsfiddle.net/api/post/library/pure/),但還沒有弄清楚我誤解的地方。 爲了重現我的問題,我採用了簡單的折線圖,其中我修改了一些條目值,使其看起來像f(x) = 1/x中的值一樣,就像我的實際數據分佈一樣。谷歌圖表數刻度

<html> 
<head> 
    <script type="text/javascript" src="https://www.google.com/jsapi"></script> 
    <script type="text/javascript"> 
     google.load("visualization", "1", {packages:["linechart"]}); 
     google.setOnLoadCallback(drawChart); 
     function drawChart() { 
      var data = google.visualization.arrayToDataTable([ 
       ['Index', 'Value'], 
       ['1', 100000], 
       ['2', 2170], 
       ['3', 960], 
       ['4', 560], 
       ['5', 520], 
       ['6', 500], 
       ['7', 480], 
       ['8', 460], 
       ['9', 440], 
       ['10', 430], 
       ['11', 420], 
       ['12', 410], 
       ['13', 400], 
       ['14', 395], 
       ['15', 390], 
       ['16', 388], 
       ['17', 396], 
       ['18', 387], 
       ['19', 385], 
       ['20', 384] 
      ]); 

      var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
      chart.draw(data, {width: 400, height: 240, legend: 'bottom', title: 'Company Performance', vAxis: {scaleType: 'log'}}); 
     } 
    </script> 
</head> 

<body> 
<div id="chart_div"></div> 
</body> 
</html> 

我的最後一個選項參數vAxis: {scaleType: 'log'}被忽略。我ahve試圖與離散和連續數據(第1列都像上面或數字沒有「」字符串)我的情節看起來像使用更新後的庫(loader.js)以下

log chart test

回答

1

的一個似乎使差異

<script src="https://www.gstatic.com/charts/loader.js"></script>

的,而不是...

<script src="https://www.google.com/jsapi"></script>

加,從release notes ...

谷歌排行榜的版本仍然通過jsapi裝載機可不再被持續更新。從現在起請使用新的gstatic裝載機(loader.js)。

看到下面的工作片段...

google.charts.load('current', { 
 
    callback: function() { 
 
    var data = google.visualization.arrayToDataTable([ 
 
     ['Index', 'Value'], 
 
     ['1', 100000], 
 
     ['2', 2170], 
 
     ['3', 960], 
 
     ['4', 560], 
 
     ['5', 520], 
 
     ['6', 500], 
 
     ['7', 480], 
 
     ['8', 460], 
 
     ['9', 440], 
 
     ['10', 430], 
 
     ['11', 420], 
 
     ['12', 410], 
 
     ['13', 400], 
 
     ['14', 395], 
 
     ['15', 390], 
 
     ['16', 388], 
 
     ['17', 396], 
 
     ['18', 387], 
 
     ['19', 385], 
 
     ['20', 384] 
 
    ]); 
 

 
    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
 
    chart.draw(data, {width: 400, height: 240, legend: 'bottom', title: 'Company Performance', vAxis: {scaleType: 'log'}}); 
 
    }, 
 
    packages: ['corechart'] 
 
});
<script src="https://www.gstatic.com/charts/loader.js"></script> 
 
<div id="chart_div"></div>

這裏是同一個圖表,沒有選項 - >vAxis: {scaleType: 'log'}

google.charts.load('current', { 
 
    callback: function() { 
 
    var data = google.visualization.arrayToDataTable([ 
 
     ['Index', 'Value'], 
 
     ['1', 100000], 
 
     ['2', 2170], 
 
     ['3', 960], 
 
     ['4', 560], 
 
     ['5', 520], 
 
     ['6', 500], 
 
     ['7', 480], 
 
     ['8', 460], 
 
     ['9', 440], 
 
     ['10', 430], 
 
     ['11', 420], 
 
     ['12', 410], 
 
     ['13', 400], 
 
     ['14', 395], 
 
     ['15', 390], 
 
     ['16', 388], 
 
     ['17', 396], 
 
     ['18', 387], 
 
     ['19', 385], 
 
     ['20', 384] 
 
    ]); 
 

 
    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
 
    chart.draw(data, {width: 400, height: 240, legend: 'bottom', title: 'Company Performance'}); 
 
    }, 
 
    packages: ['corechart'] 
 
});
<script src="https://www.gstatic.com/charts/loader.js"></script> 
 
<div id="chart_div"></div>

+0

非常感謝! Google文檔有時會讓所有頻繁的更改感到困惑。 – Jimx

+0

@WhiteHat,你能告訴我如何在氣泡圖中使用時間序列的對數刻度?我無法在任何時間序列的例子中找到對數刻度,我嘗試了下面的鏈接,但無法使它適用於x軸上的時間序列,並且具有對數刻度。 https://developers.google.com/chart/interactive/docs/customizing_axes#axis-scale –