簡體   English   中英

Google Charts LogScale無法正常工作

[英]Google Charts LogScale not working

我正在使用Google Charts制作條形圖,並且試圖使該圖在垂直軸上使用對數刻度,但由於某些原因它無法正常工作。 我試過使用logScale和scaleType,但是它們都不起作用。

這是我的代碼:

google.charts.load('current', {
  'packages': ['bar']
});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Vendor', 'Nootropics Depot', 'Pure Nootropics', 'Peak Nootropics', 'Absorb Health'],
    ['ALCAR', 0.07, 0.20, 0.12, 0.24],
    ['Agmatine', 0.13, null, 0.23, null],
    ['Coluracetam', 13.80, 27.49, null, null],
    ['Oxiracetam', 0.47, 0.37, 0.58, 0.63],
    ['Phenibut', 0.22, null, 0.59, 0.60],
    ['Phenylpiracetam', 2.83, 3.33, 5.30, null],
    ['Polygala', 0.42, null, null, null],
    ['Pramiracetam', 1.67, 2.22, 1.60, 2.60],
    ['PRL-8-53', 23.99, null, null, null],
    ['Rhodiola Rosea 3% Rosavins', 0.23, 0.60, 0.32, 0.26],
  ]);

  var formatter = new google.visualization.NumberFormat({
    suffix: 'tablets',
    negativeColor: 'red',
    negativeParens: true
  });
  formatter.format(data, 0);
  var formatter = new google.visualization.NumberFormat({
    prefix: '$',
    negativeColor: 'red',
    negativeParens: true
  });
  formatter.format(data, 1);
  formatter.format(data, 2);
  formatter.format(data, 3);
  formatter.format(data, 4);

  var options = {
    chart: {
      title: 'Cheapest price per gram',
    },
    bars: 'vertical', // Required for Material Bar Charts.
    hAxis: {
      format: 'decimal',
    },
    vAxis: {
      title: 'Price',
      format: '$#',
      minValue: 0.1,
      logScale: true,
    },
    height: 400,
    colors: ['#1b9e77', '#d95f02', '#7570b3']
  };

  var chart = new google.charts.Bar(document.getElementById('chart_div'));

  chart.draw(data, google.charts.Bar.convertOptions(options));

}

JSFiddle頁面: https ://jsfiddle.net/rm8vr1p8/

不太確定我在做什么錯。 我什至嘗試更改垂直軸的值,但它不起作用。 我想念什么?

材質圖表不支持幾個選項,包括...
{hAxis,vAxis,hAxes.*,vAxes.*}.logScale

請參閱-> 物料圖特征奇偶校驗的跟蹤問題


材質 = google.charts.Bar packages: ['bar']

經典 = google.visualization.ColumnChart packages: ['corechart']


經典圖表有一個選項類似於 材料 ...
theme: 'material

請參閱以下工作片段...

 google.charts.load('current', { packages: ['corechart'] }).then(function () { var data = google.visualization.arrayToDataTable([ ['Vendor', 'Nootropics Depot', 'Pure Nootropics', 'Peak Nootropics', 'Absorb Health'], ['ALCAR', 0.07, 0.20, 0.12, 0.24], ['Agmatine', 0.13, null, 0.23, null], ['Coluracetam', 13.80, 27.49, null, null], ['Oxiracetam', 0.47, 0.37, 0.58, 0.63], ['Phenibut', 0.22, null, 0.59, 0.60], ['Phenylpiracetam', 2.83, 3.33, 5.30, null], ['Polygala', 0.42, null, null, null], ['Pramiracetam', 1.67, 2.22, 1.60, 2.60], ['PRL-8-53', 23.99, null, null, null], ['Rhodiola Rosea 3% Rosavins', 0.23, 0.60, 0.32, 0.26], ]); var formatter = new google.visualization.NumberFormat({ suffix: 'tablets', negativeColor: 'red', negativeParens: true }); formatter.format(data, 0); var formatter = new google.visualization.NumberFormat({ prefix: '$', negativeColor: 'red', negativeParens: true }); formatter.format(data, 1); formatter.format(data, 2); formatter.format(data, 3); formatter.format(data, 4); var options = { theme: 'material', title: 'Cheapest price per gram', hAxis: { format: 'decimal' }, vAxis: { title: 'Price', format: '$#', minValue: 0.1, logScale: true }, height: 400, colors: ['#1b9e77', '#d95f02', '#7570b3'] }; var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); chart.draw(data, options); }); 
 <script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM