在 HighCharts 散点图中更改线条颜色时出现控制台错误
console error when changing line color in a HighCharts scatterplot
我领养了 solution to change the line color when hovering a series in a HighCharts scatterplot (JSFiddle demo here):
$(function () {
$('#container').highcharts({
chart: {
type: 'scatter',
},
plotOptions: {
scatter: {
lineWidth:1,
marker: {
radius: 1,
symbol:'circle',
fillColor: '#800000',
states: {
hover: {
enabled: true,
radius:0,
radiusPlus:2,
lineColor: '#ff0000',
fillColor: '#ff0000'
}
}
},
events: {
mouseOver: function () {
this.chart.series[this.index].update({
color: 'red'
});
},
mouseOut: function () {
this.chart.series[this.index].update({
color: "#b0b0b0"
});
}
}
}
},
series: [{
name: 'A',
color: "#b0b0b0",
data: [[38,42],[39,39],[35,45],[35,54],{x:36,y:35,marker:{radius:8,symbol:'circle'}}
]
}, {
name: 'B',
color: "#b0b0b0",
data: [[46,56],[47,67],[48,69],[50,55],{x:52,y:57,marker:{radius:8,symbol:'circle'}}
]
}]
});
});
该脚本有效,但 运行 网络控制台我看到系列的每次悬停都会导致 TypeError: g.firePointEvent is not a function error
。
在我的另一个脚本中,错误是 TypeError: hoverPoint.firePointEvent is not a function
。
这是 HighCharts 的错误还是可以避免?
问题是由在您执行操作之前调用的更新引起的。结果,您尝试在更新点结束之前参考更新点。解决方案是使用 attr() 方法并更改路径上的 SVG 颜色。
events: {
mouseOver: function() {
this.chart.series[this.index].graph.attr({
stroke: 'red'
});
},
mouseOut: function() {
this.chart.series[this.index].graph.attr({
stroke: '#b0b0b0'
});
}
}
演示:
我领养了
$(function () {
$('#container').highcharts({
chart: {
type: 'scatter',
},
plotOptions: {
scatter: {
lineWidth:1,
marker: {
radius: 1,
symbol:'circle',
fillColor: '#800000',
states: {
hover: {
enabled: true,
radius:0,
radiusPlus:2,
lineColor: '#ff0000',
fillColor: '#ff0000'
}
}
},
events: {
mouseOver: function () {
this.chart.series[this.index].update({
color: 'red'
});
},
mouseOut: function () {
this.chart.series[this.index].update({
color: "#b0b0b0"
});
}
}
}
},
series: [{
name: 'A',
color: "#b0b0b0",
data: [[38,42],[39,39],[35,45],[35,54],{x:36,y:35,marker:{radius:8,symbol:'circle'}}
]
}, {
name: 'B',
color: "#b0b0b0",
data: [[46,56],[47,67],[48,69],[50,55],{x:52,y:57,marker:{radius:8,symbol:'circle'}}
]
}]
});
});
该脚本有效,但 运行 网络控制台我看到系列的每次悬停都会导致 TypeError: g.firePointEvent is not a function error
。
在我的另一个脚本中,错误是 TypeError: hoverPoint.firePointEvent is not a function
。
这是 HighCharts 的错误还是可以避免?
问题是由在您执行操作之前调用的更新引起的。结果,您尝试在更新点结束之前参考更新点。解决方案是使用 attr() 方法并更改路径上的 SVG 颜色。
events: {
mouseOver: function() {
this.chart.series[this.index].graph.attr({
stroke: 'red'
});
},
mouseOut: function() {
this.chart.series[this.index].graph.attr({
stroke: '#b0b0b0'
});
}
}
演示: