谷歌图表日志规模

时间:2016-10-31 23:38:04

标签: javascript plot charts google-visualization

我正在尝试在谷歌图表中做一个对数比例图(实际上是一个半月形图,准确)并尝试过   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'}将被忽略。我已尝试使用离散和连续数据(第一列既可以是上面的字符串也可以是没有''的数字)我的情节看起来像下面那样

log chart test

1 个答案:

答案 0 :(得分:1)

使用更新的库(loader.js)似乎有所作为

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

而不是......

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

加上release notes ...

  

通过jsapi加载程序保留的Google图表版本不再一致更新。从现在开始,请使用新的gstatic加载程序(loader.js)。

请参阅以下工作代码段...

&#13;
&#13;
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']
});
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
&#13;
&#13;
&#13;

这是相同的图表,没有选项 - &gt; vAxis: {scaleType: 'log'}

&#13;
&#13;
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']
});
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
&#13;
&#13;
&#13;