如何使用谷歌图表(google.visualization API)在折线图上设置特定线条的颜色?我正在可视化已经具有与每一行相关联的特定颜色的数据集(并且颜色关联很重要)。
我知道通过图表选项设置一般调色板,例如:
chart.draw(dataTable, { colors: ['red', '#ff9933', 'pink', /* ...etc... */ ] });
但我不想设置调色板,我想为特定的线条指定特定的颜色。理想情况下,我想将颜色放在数据表本身。
答案 0 :(得分:0)
您不能将颜色放在DataTable中,但您可以使用系列选项按数据系列分配颜色:
chart.draw(dataTable, {
series: {
0: {
// set the color of the first data series
color: 'red'
},
1: {
// set the color of the second data series
color: '#ff9933'
},
2: {
// set the color of the third data series
color: 'pink'
}
// etc
}
});
如果您的数据系列是动态的,您也可以动态构建颜色,并在绘制时将它们设置在选项中。