Charts 更改google时间线图表行中的背景颜色
参考: 在上图中,备用行具有背景色。 亚当斯是灰色的,而华盛顿和杰斐逊是白色的。Charts 更改google时间线图表行中的背景颜色,charts,google-visualization,Charts,Google Visualization,参考: 在上图中,备用行具有背景色。 亚当斯是灰色的,而华盛顿和杰斐逊是白色的。 我想根据与行相关的一个数据值为背景上色。没有标准选项来更改行的背景色 但是颜色可以在图表的'ready'事件中手动更改 背景行将使用元素绘制。 当事件激发时,通过测试以下属性来查找元素 x-所有值都将为零-->x=“0” 笔划-只有整个背景将具有除“无”之外的笔划属性 然后将fill属性设置为您选择的颜色 // make sure rect is a background row if ((rect.ge
我想根据与行相关的一个数据值为背景上色。没有标准选项来更改行的背景色 但是颜色可以在图表的
'ready'
事件中手动更改
背景行将使用
元素绘制。当事件激发时,通过测试以下属性来查找元素
x
-所有值都将为零-->x=“0”
笔划
-只有整个背景
将具有除“无”之外的笔划属性
然后将fill
属性设置为您选择的颜色
// make sure rect is a background row
if ((rect.getAttribute('x') === '0') && (rect.getAttribute('stroke') === 'none')) {
// determine existing color
if (rect.getAttribute('fill') === '#ffffff') {
rect.setAttribute('fill', 'cyan');
} else {
rect.setAttribute('fill', 'magenta');
}
}
请参阅以下工作片段
google.charts.load('current'{
软件包:[“时间线”]
}).然后(函数(){
var container=document.getElementById('chart');
var chart=newgoogle.visualization.Timeline(容器);
var dataTable=new google.visualization.dataTable();
addColumn({type:'string',id:'President'});
addColumn({type:'date',id:'Start'});
addColumn({type:'date',id:'End'});
dataTable.addRows([
[华盛顿,新日期(1789年3月30日),新日期(1797年2月4日)],
['Adams',新日期(1797年2月4日),新日期(1801年2月4日)],
['Jefferson',新日期(1801,2,4),新日期(1809,2,4)]
]);
google.visualization.events.addListener(图表'ready',函数(){
var rects=container.getElementsByTagName('rect');
Array.prototype.forEach.call(rects,function(rect){
//确保rect是背景行
if((rect.getAttribute('x')=='0')&&(rect.getAttribute('stroke')=='none')){
//确定现有颜色
if(rect.getAttribute('fill')='#ffffff'){
rect.setAttribute('fill','cyan');
}否则{
rect.setAttribute('fill','magenta');
}
}
});
});
图表绘制(数据表);
});代码>
当我们在React组件中使用google图表的时间线时,有没有办法改变背景颜色?