[英]Highcharts shared tooltip between charts with multiple series and shared tooltip
I'm trying to set shared tooltip between charts. 我正在尝试设置图表之间的共享工具提示。 It works nice only if tooltip doesn't have shared: true
, if I set shared: true
I get error: 仅当工具提示未shared: true
时才有效shared: true
,如果我设置了shared: true
,则会出现错误:
TypeError: 'undefined' is not an object (evaluating 'a[0].category') highcharts.js:3259
I prepared example: http://jsfiddle.net/CAKQH/24408/ 我准备了示例: http : //jsfiddle.net/CAKQH/24408/
If you move cursor on first chart - it works nice, also if you comment shared: true
it works, but if you move cursor on second chart you'll get an error. 如果将光标移到第一张图表上-很好用,也可以在注释shared: true
可以,但是如果将光标移到第二张图表上,则会出现错误。
Did someone faced this error? 有人遇到这个错误了吗? Help me to solve it, please. 请帮我解决。
The problem occurs because you have shared: true
on one chart, while having it default (false) on the other. 发生此问题的原因是您shared: true
在一张图表上为shared: true
,而在另一图表上为默认(false)。 This is a problem because the tooltip.refresh
method will take different paths and use the input differently based the chart having shared set to true or false. 这是一个问题,因为tooltip.refresh
方法将采用不同的路径,并根据共享设置为true或false的图表使用不同的输入。
You can find this branching in the source code on line 8806, for the tooltip.refresh
method: 您可以在源代码的 8806行中找到有关tooltip.refresh
方法的tooltip.refresh
:
// shared tooltip, array is sent over
if (shared && !(point.series && point.series.noSharedTooltip)) {
....
}
// single point tooltip
else {
....
}
You can handle this by doing a branching inside your syncTooltip
method to handle the different cases like this ( example JFiddle ): 您可以通过在syncTooltip
方法内进行分支来处理这种情况( 例如JFiddle )来解决此问题:
function syncTooltip(container, p) {
var i = 0;
for (; i < charts.length; i++) {
if (container.id != charts[i].container.id) {
if(charts[i].tooltip.shared) {
charts[i].tooltip.refresh([charts[i].series[0].data[p]]);
}
else {
charts[i].tooltip.refresh(charts[i].series[0].data[p]);
}
}
}
}
This way you can freely set shared to true or false on both charts. 这样,您可以在两个图表上自由地将shared设置为true或false。
Unfortunately your plotOptions.series.point.events.mouseOver
-event doesn't capture points that are "selected" through the shared: true
functionality, so you will have to find an alternate event to properly capture this situation. 不幸的是,您的plotOptions.series.point.events.mouseOver
-event不能捕获通过shared: true
功能“选择”的点,因此您将不得不找到一个替代事件来正确捕获这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.