highcharts - highcharts mapchart:重新加载图表后不显示颜色
问题描述
我是新来的高图表。
下面是我在创建 mapChart 时在函数中的部分代码,它的作用是仅将匹配区域(带有 cur_state)显示为红色,而将其他区域显示为蓝色。
chart: {
backgroundColor: null,
map: 'countries/au/au-all',
events: {
load: function () {
// place1
this.series[0].data = this.series[0].data.map((el) => {
// place2
if (el['hc-key'] == region_dict[cur_state][1]) {
el.color = "#ff0000";
return el;
}
el.color = "blue"
return el
})
this.update({
series: [{
data: this.series[0].data
}]
})
}
}
},
当 cur_state 的值发生变化时,我想起了包含地图图形的函数,希望相应的区域有颜色更新。
这是我第一次调用该函数:
经过测试,发现第一次创建图表时会执行place1和place2,重新创建图表时只执行place1。
我的另一部分代码具有与此类似的结构:https ://jsfiddle.net/gh/get/library/pure/highslide-software/highcharts.com/tree/master/samples/mapdata/countries/au/au-all
我怎样才能达到预期的结果?
感谢您的帮助
解决方案
在您的情况下,最好的解决方案似乎是使用渲染事件并更改 SVG 级别的颜色。例子:
chart: {
...,
events: {
render: function() {
this.series[0].points.forEach(function(point) {
if (point['hc-key'] == state) {
point.graphic.attr({
fill: 'red'
});
}
});
}
}
}
现场演示: https ://jsfiddle.net/BlackLabel/x69pLcyo/
API参考:
https://api.highcharts.com/highcharts/chart.events.render
https://api.highcharts.com/class-reference/Highcharts.SVGElement#attr
推荐阅读
- cmake - 如何在 CMake 中将变量写入父母的父范围?
- javascript - 如何设置 useEffect 以在第一次使用 eslint-react-hooks 渲染时从 API 获取数据?
- azure-cosmosdb - CosmosDb 首次连接可能需要很多秒
- java - 将 @Value 与 Gauge 框架一起使用
- amazon-web-services - AWS Cognito + aws-amplify:会话状态始终让用户保持登录状态?
- kubernetes - Istio 上消息的模式匹配
- iframe - 为什么我不能在 iframe 中嵌入这个网站?
- google-bigquery - BQ 删除数据集的最快方法
- ruby-on-rails - 无法急切地加载多态关联:item
- ruby-on-rails-4 - Rails 自定义错误页面工作和不工作