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