[英]setting the color of a stacked bar (google charts)
我正在使用谷歌图表自定义此堆积条上某些部分的颜色
$(function() {
google.load('visualization', '1', { 'callback': drawChart, 'packages': ['corechart'] });
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Grade', 'NG (% of total Results)', 'F (% of total Results)', 'E (% of total Results)', 'D3 (% of total Results)',
'D2(% of total Results)', 'D1 (% of total Results)','C3 (% of total Results)','C2 (% of total Results)','C1 (% of total Results)', 'B3 (% of total Results)','B2 (% of total Results)', 'B1 (% of total Results)','A2 (% of total Results)', 'A1 (% of total Results)', { role: 'annotation' } ],
["English", 5, 5, 5,5, 5, 5, 5, 5,5, 5,5, 5,5 ,35, ''], //use german[2] index of variables for each percent
["Maths", 5, 5, 5,5, 5, 5, 5, 5,5, 5,5, 5,20 ,20, '']
]);
var view = new google.visualization.DataView(data);
var options = {
width: 600,
height: 400,
legend: { position: 'none'},
bar: { groupWidth: '75%' },
colors: ['#dfdfdf','#d4d4d4','#d2d2d2','#d8d8d8','#e3e3e3','#d4d4d4','#dcdcdc','d7d7d7','dadada','d9d9d9','d6d6d6'],
isStacked: true,
hAxis: {
viewWindowMode:'explicit',
viewWindow: {
max:101,
min:0
}
},
chartArea: {'height': '90%'}
};
var chart = new google.visualization.BarChart(document.getElementById("columnchart_values"));
chart.draw(view, options);
}
我想更改每个栏上一个区域的颜色,例如英语上的35值和数学上的最后20个值。 我无法使用样式角色列对其进行硬编码,因为我需要根据用户信息更改颜色的值。 我尝试了以下各种方法,但均无济于事。 谢谢。
data.setProperty(0,0,{
type: "string",
role: "style" }, 'red');
我认为这里的问题是您有14个不同的系列和2行。 如果您尝试使用series: { 4: { color: "blue"}}
按系列进行样式设置,则将更改两行的系列颜色。
如果您尝试向数据添加新列以进行如下样式设置:
var data = google.visualization.arrayToDataTable([
['Grade', 'NG (% of total Results)', 'F (% of total Results)', 'E (% of total Results)', 'D3 (% of total Results)',
'D2(% of total Results)', 'D1 (% of total Results)','C3 (% of total Results)','C2 (% of total Results)','C1 (% of total Results)', 'B3 (% of total Results)','B2 (% of total Results)', 'B1 (% of total Results)','A2 (% of total Results)', 'A1 (% of total Results)', { role: 'annotation' }, {type: 'string', role: 'style'} ],
["English", 5, 5, 5,5, 5, 5, 5, 5,5, 5,5, 5,5 ,35, '', 'color: #cfc'], //use german[2] index of variables for each percent
["Maths", 5, 5, 5,5, 5, 5, 5, 5,5, 5,5, 5,20 ,20, '', 'color: #0f0']
]);
data.setCell(1,16, "color: red");
您将只能为该行设置样式,而不能控制哪一列。
这些都不是您真正想要的。 我的直觉是,数据实际上并未以适合这种方式的方式进行格式化,但目前我没有任何想法。 我以为我会告诉你我能做些什么,也许即使我看不出那是什么,也足以让你走上正确的道路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.