[英]Google Charts API change color based on control selection
I have a google chart where I am trying to change the color based on the category control. 我有一个谷歌图表,我试图根据类别控件更改颜色。
My chart is a histogram which should change color based on the selection in the programmaticDropdown. 我的图表是一个直方图,应根据programmaticDropdown中的选择更改颜色。 Part of my code is shown below:
我的部分代码如下所示:
var dashboard = new google.visualization.Dashboard(
document.getElementById('programmatic_dashboard_div'));
programmaticDropdown = new google.visualization.ControlWrapper({
'controlType': 'CategoryFilter',
'containerId': 'programmatic_control_div',
'options': {
'filterColumnLabel': 'Type',
'ui': {'allowMultiple': false},
}
});
programmaticChart = new google.visualization.ChartWrapper({
'chartType': 'Histogram',
'containerId': 'programmatic_chart_div',
'options': {
'title': 'Issues by Month',
'legend': 'none',
'height':400,
'hAxis': {
'viewWindowMode':'explicit',
'viewWindow':{
'max':13,
'min':0
}
}
},
'view': { 'columns': [0, 1] }
});
dashboard.bind(programmaticDropdown, programmaticChart);
dashboard.draw(data);
}
Also, here is a link to the google chart controls documentation that has some UI information... can anyone help? 另外,这是指向Google图表控件文档的链接,其中包含一些UI信息...任何人都可以帮忙吗?
Thanks!!! 谢谢!!!
https://developers.google.com/chart/interactive/docs/gallery/controls?hl=en#controls-gallery https://developers.google.com/chart/interactive/docs/gallery/controls?hl=en#controls-gallery
Solved it!!! 解决了!!! To do this, I had to add an event listener and function to my code.
为此,我必须在代码中添加一个事件侦听器和函数。 See below.
见下文。
google.visualization.events.addListener(programmaticDropdown, 'statechange', changeTitle); google.visualization.events.addListener(programmaticDropdown,'statechange',changeTitle);
function changeTitle () {
var location = programmaticDropdown.getState().selectedValues[0];
if (location == "CLOSED") {
programmaticChart.setOption('colors', ['#e7711c']);
} else if (location == "OPEN") {
programmaticChart.setOption('colors', ['#ff0000']);
}
programmaticChart.draw();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.