gpt4 book ai didi

javascript - 更改 Google ComboChart 中的带颜色

转载 作者:行者123 更新时间:2023-11-29 23:45:45 24 4
gpt4 key购买 nike

我在此处找到了我之前关于图表的问题的答案 fill background color horizontally in google line chart on specified area

现在我的问题是改变区域颜色google combochart

可以找到代码here (抱歉嵌入导致错误)

function drawChart () {
var data = new google.visualization.DataTable();
data.addColumn('number', 'x');
data.addColumn('number', 'y');
data.addColumn('number', 'color band 1');
data.addColumn('number', 'color band 2');
data.addColumn('number', 'color band 3');
data.addColumn('number', 'color band 4');
data.addColumn('number', 'color band 5');

var y = 50;
// fill with 100 rows of random data
for (var i = 0; i < 100; i++) {
y += Math.ceil(Math.random() * 5) * Math.pow(-1, Math.ceil(Math.random() * 2));
if (y < 0) {
y = 10;
}
if (y > 100) {
y = 90;
}
// make the colored bands appear every 20
data.addRow([i, y, 20, 20, 20, 20, 20]);
}

var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));

chart.draw(data, {
height: 400,
width: 600,
isStacked: true,
vAxis: {
minValue: 0,
maxValue: 100
},
series: {
0: {
type: 'line'
},
1: {
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},
2: {
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},
3: {
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},
4: {
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},
5: {
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},
6: {
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
}
}
});

最佳答案

在每个系列中使用color选项...

1: {
color: '#f44336', // <-- add color option
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},
2: {
color: '#2196f3', // <-- add color option
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},
...

区域系列默认不透明
要查看真实颜色,请设置 --> areaOpacity: 1

1: {
areaOpacity: 1,
color: '#000000',
lineWidth: 0,
type: 'area',
visibleInLegend: false,
enableInteractivity: false
},

关于javascript - 更改 Google ComboChart 中的带颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44262133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com