html - 设置 google-charts、图表的背景。不做任何事

标签 html web google-visualization

我使用 google-charts API 绘制了一个柱形图。当我将背景设置为图表时,它没有执行任何操作。

enter image description here

google.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = google.visualization.arrayToDataTable(<?php echo $str ?>);

    var options = {
    title: 'Business Optimization Per Predicted Conversion Rate',
    bar: {groupWidth: "70%"},
    backgroundColor: 'red',
    colors: ['purple','red'],
    fontSize:20,
    legend: { position: "none" },
    width: 900,

    };

  var chart = new google.charts.Bar(document.getElementById('chart_div_1'));
  chart.draw(data, options);
}

我在选项标签中具体写了背景需要是红色的,发生了什么?

最佳答案

而不是这样做:

chart.draw(data, options);

尝试这样做:

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

这里发生的情况是,您可能正在使用 Material 图表,并且定义选项的方式已经改变。

请参阅 google charts documentation regarding this, here 中的此注释:

The Material Charts are in beta. The appearance and interactivity are largely final, but the way options are declared is not. If you are converting a Classic Column Chart to a Material Column Chart, you'll want to replace this line:

chart.draw(data, options);

...with this:

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

关于html - 设置 google-charts、图表的背景。不做任何事,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29206710/

相关文章:

javascript - Android Honeycomb 模拟器上的 Google 图表轴渲染问题

html - 具有灵活滚动溢出的两列

web - 如何从其他 RESTAS 模块访问 RESTAS 子模块的上下文

html - 如何禁用 Google 幻灯片演示文稿 IFrame 导航

html - CSS 中的媒体查询

jquery - Bootstrap 卡覆盖另一张卡(图片)

javascript - 从 Google 电子表格数据构建/填充网页上的下拉菜单

jquery - 带选项卡的 Google 图表 - 图表区域不正确

html - HTML 中字符串的不可见分隔符

html - 如何通过 golang 创建的 HTML 页面发送图像链接