Google Chart (Material) - Type Bar - Data in arrayToDataTable with role style KO?

眉间皱痕 提交于 2019-12-13 18:08:34

问题


I want to use a google bar chart (material design) with the options provided in the arrayToDataTable to customize the color of the bar.

Example:

return google.visualization.arrayToDataTable([
      ['1', '2', {role: 'style'}],
      ['1', 1000, '#000000'],
      ['2', 1170, '#000000'],
      ['3', 660, '#000000'],
      ['4', 1030, '#000000']
    ]);

As you can see, if I refer to the documentation, the bar should be in black.
It is not.
Moreover, this third column is not added (so something catch it as an role, but do not execute associated behavior).

I saw multiples topics about it nevertheless they were working with old packages (not material design).

Thanks for the help guys.

Update 1:

  • Replaced #00000 color to #000000 (doesn't solve the problem, I just forgot a 0 when writing this example)

回答1:


unfortunately, column roles do not work with material charts

along with several configuration options

recommend using core chart instead

there is a configuration option that will style a core chart as material

theme: 'material'

but it's not exact, see following working snippet...

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

function drawChart(transparent) {
  var data = google.visualization.arrayToDataTable([
    ['1', '2', {role: 'style'}],
    ['1', 1000, '#000000'],
    ['2', 1170, '#000000'],
    ['3', 660, '#000000'],
    ['4', 1030, '#000000']
  ]);

  var options = {
    legend: 'none',
    theme: 'material'
  };

  var chartDiv = document.getElementById('chart_div');
  var chart = new google.visualization.ColumnChart(chartDiv);
  chart.draw(data, options);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

also, the style column value for black should have six zeroes vs. five

--> '#000000'

vs.

--> '#00000'



来源:https://stackoverflow.com/questions/40473417/google-chart-material-type-bar-data-in-arraytodatatable-with-role-style-ko

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!