[英]Highcharts - series color on shadow
I would like to use the series color in the shadow color. 我想在阴影颜色中使用系列颜色。
If I hardcode the colors in each series individually I can achieve that, but I was wondering there is a way to do it automatically, without hardcore the color in each series? 如果我对每个系列中的颜色分别进行硬编码,我可以实现,但是我想知道是否有一种方法可以自动完成,而不必对每个系列中的颜色进行硬核化?
Hardcode the color individually: https://jsfiddle.net/jzcwb3vn/ 分别对颜色进行硬编码: https : //jsfiddle.net/jzcwb3vn/
Highcharts.theme = {
colors: ['#3498db', '#e74c3c'],
plotOptions: {
line: {
lineWidth: 3,
marker: {
enabled: false
}
}
}
};
// Apply the theme
Highcharts.setOptions(Highcharts.theme);
Highcharts.chart('container', {
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
shadow: {
width: 8,
opacity: 0.2,
color: '#3498db'
}
}, {
data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5],
shadow: {
width: 8,
opacity: 0.2,
color: '#e74c3c'
}
}]
});
Without the hardcode color: https://jsfiddle.net/jzcwb3vn/2/ 没有硬色: https : //jsfiddle.net/jzcwb3vn/2/
Highcharts.theme = {
colors: ['#3498db', '#e74c3c'],
plotOptions: {
line: {
lineWidth: 3,
shadow: {
width: 8,
opacity: 0.2
},
marker: {
enabled: false
}
}
}
};
// Apply the theme
Highcharts.setOptions(Highcharts.theme);
Highcharts.chart('container', {
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5]
}]
});
One way of doing this is using the load function to set the color of the shadow, after each series has gotten it's color. 一种实现方法是在每个系列获得阴影的颜色之后,使用加载功能设置阴影的颜色。 Like this:
像这样:
chart: {
events: {
load: function() {
let allSeries = this.series;
for(var i = 0; i < allSeries.length; i++) {
allSeries[i].update({shadow: {color: allSeries[i].color}}, false);
}
this.redraw();
}
}
},
Highcharts.theme = { colors: ['#3498db', '#e74c3c'], plotOptions: { line: { lineWidth: 3, marker: { enabled: false }, shadow: { width: 8, opacity: 0.2, } } } }; // Apply the theme Highcharts.setOptions(Highcharts.theme); Highcharts.chart('container', { chart: { events: { load: function() { let allSeries = this.series; for(var i = 0; i < allSeries.length; i++) { allSeries[i].update({shadow: {color: allSeries[i].color}}, false); } this.redraw(); } } }, series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4], }, { data: [216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5], }] });
#container { min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto }
<script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/data.js"></script> <div id="container"></div>
Working example: https://jsfiddle.net/jzcwb3vn/4/ 工作示例: https : //jsfiddle.net/jzcwb3vn/4/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.