我正在尝试使用 Highcharts 对堆积条形图上的特定列产生亮度效果。
我想将效果开发为下图右侧的“解决方案”。
现在当鼠标悬停在一个系列或一个列上时,即 Apples-John,可以看到整个条的亮度发生变化
代码: HTML 是
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
代码:JavaScript 是
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Stacked column chart'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
yAxis: {
min: 0,
title: {
text: 'Total fruit consumption'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.percentage:.0f}%)<br/>',
shared: true
},
plotOptions: {
column: {
stacking: 'percent'
},
series: {
states: {
hover: {
brightness: -0.3
}
}
}
},
series: [{
name: 'John',
data: [5, 3, 4, 7, 2]
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1]
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5]
}]
});
What I want to do is to give brightness to four columns of John's when hovering any of John's columns: all of the skyblue columns; if I hover one of the Jane's columns, it is needed to change brightness of all Jane's columns: five black columns in a Jane group.
With some css you can achieve it , first add className in the series data like this(you can declare the name as you like right now I'm used the name as the className)
series: [{
name: 'John',
data: [5, 3, 4, 7, 2],
className:'John'
}, {
name: 'Jane',
data: [2, 2, 3, 2, 1],
className:'Jane'
}, {
name: 'Joe',
data: [3, 4, 4, 2, 5],
className:'Joe'
}]
Once you add the className , after rendering you will find the name in the Highcharts div, what you need to do is add the color which you wants to show on the hove use fill for that.
Example:
#container .highcharts-container .highcharts-series-group .John:hover rect{
fill: rgb(230, 44, 118);
}
Jsfiddle link: http://jsfiddle.net/karnan796/2fruqw7j/12/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句