嘿,我知道如果我想为特定点着色,我可以使用当前标记的 fillColor
属性来完成。
但是当我悬停点时,颜色恢复为图形的默认颜色,如何防止这种效果?
我希望点在两种情况下(悬停事件和非悬停事件)都是红色的,
要使这种效果发生,我需要更改每个点的什么属性?
我在下面添加了一个演示,演示是这样的:当你点击图表的 Canvas 时,一个新的图表正在生成,第一个点是红色的,但是当我悬停它时,它恢复到默认颜色。
$(function () {
$('#container').highcharts({
chart: {
type: 'spline',
margin: [70, 50, 60, 80],
events: {
click: function (e) {
// find the clicked values and the series
var x = e.xAxis[0].value,
y = e.yAxis[0].value,
series = this.series[0];
var chart = this;
this.addSeries({
data: [{ x:x, y:y, marker:{radius: 5 , fillColor: "red" }},{x:(x*2), y:(y*2)}]
})
}
}
},
title: {
text: 'User supplied data'
},
subtitle: {
text: 'Click the plot area to add a point. Click a point to remove it.'
},
xAxis: {
gridLineWidth: 1,
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60
},
yAxis: {
title: {
text: 'Value'
},
minPadding: 0.2,
maxPadding: 0.2,
maxZoom: 60,
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
series: {
lineWidth: 1,
point: {
events: {
'click': function () {
if (this.series.data.length > 1) {
this.remove();
}
}
}
}
}
},
series: [{
data: [[20, 20], [80, 80]]
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 700px; margin: 0 auto"></div>
最佳答案
在设置标记 fillColor 的状态选项中添加:
marker: {
radius: 5,
fillColor: 'red',
states: {
hover: {
fillColor: 'red',
}
}
}
关于javascript - 如何在 HighCharts 中给点上色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38222677/