如何修改Google Charts中BLACK系列柱状图的颜色?当前为绿色
修改Google Charts中BLACK系列柱状图颜色的方法
你当前使用的是Google Charts的Material条形图,{role: 'style'}属性仅对经典版图表(corechart模块的BarChart)生效,Material图表不支持该属性,所以之前的尝试没效果。可以通过以下两种方式设置BLACK系列的颜色:
方法1:统一配置所有系列颜色
在options中添加colors数组,数组元素顺序与你定义的系列(CYAN、MAGENTA、YELLOW、BLACK)一一对应,把第四个元素设为黑色即可:
var options = { chart: { title: "Stan tonerów z <?php echo $date ?>", titleTextStyle:{fontSize:76,}, subtitle: '' }, bars: 'horizontal', colors: ['#00FFFF', '#FF00FF', '#FFFF00', '#000000'] // 依次对应四个系列的颜色 };
方法2:单独指定BLACK系列颜色
通过series对象精准设置目标系列的颜色,BLACK是第4个系列(索引从0开始,对应索引3):
var options = { chart: { title: "Stan tonerów z <?php echo $date ?>", titleTextStyle:{fontSize:76,}, subtitle: '' }, bars: 'horizontal', series: { 3: { color: '#000000' } // 仅修改BLACK系列的颜色 } };
如果后续需要使用{role: 'style'}来设置颜色,需要切换为经典版图表,初始化图表时使用new google.visualization.BarChart(document.getElementById('你的图表容器ID')),而非Material版本的google.charts.Bar。
内容的提问来源于stack exchange,提问作者Szymanoooo
相关产品推荐
相关产品推荐

