highcharts - Coloring a region programmatically based by user selection with Highmaps
问题描述
I have an application where user can select a region by clicking. Then the map rewrites itself and zoomsTo() to the selected area. So far everything else works, but I haven't get any idea how to color the selected area programmatically. The area (or different statistics) may also be selected from a drop-down list, so I have to redraw the map in any case.
var mapChart=$('#mapcontainer').highcharts();
mapChart.get(jQuery( "#selected-region" ).val()).zoomTo();
mapChart.mapZoom(5);
I have tried things along the line:
mapChart.get(jQuery( "#selected-region" ).val()).color="rgb(255,0,0)";
but so far no breakthrough :/
Any ideas?
hank
解决方案
使用 jquery 选择点不是最好的解决方案。Highcharts 提供点事件,例如click
您可以访问单击点实例的位置,或者您可以使用chart.get()方法通过点 id 选择一个点。
要更改选定区域的颜色,您必须在选择点(区域)时定义颜色属性:
series: [{
states: {
select: {
color: '#a4edba'
}
}
}]
现在您必须在单击或选定的点上调用select()方法,以及您调用的zoomTo()
方法:
series: [{
point: {
events: {
click: function() {
var point = this;
point.zoomTo();
point.select();
}
}
},
states: {
select: {
color: '#a4edba'
}
}
}]
});
推荐阅读
- symfony - symfony3 从命令访问 entitymanager
- python - 有没有办法让这把石头剪刀布更有代码效率?(更少的行,以更好的方式)
- javascript - 如何在点击事件中设置回流功能?
- c# - 从 parallel.for 循环调用 Pythonnet
- javascript - 在 NodeJs 中缓存网络请求一小时?
- html - 整个网站在移动视图的右侧有白边
- javascript - 如何在一个元素中查找多个单词,然后让警报告诉我找到了哪些单词?
- c++ - 如何使用 boost::vf2_subgraph_iso 获取边缘映射
- javascript - 将数据从js发送到rails
- python - 在python中分别为每个类从时间列创建10分钟的时间段