可以同步工具提示和放大为任意数量的图表,其具有id="container"
含元素内:
<div id="container">
<div class="row">
<highchart id="chart1" config="chartConfig" class="span10"></highchart>
</div>
<div class="row">
<highchart id="chart2" config="chartConfig2" class="span10"></highchart>
</div>
<div class="row">
<highchart id="chart3" config="chartConfig3" class="span10"></highchart>
</div>
</div>
具有以下JS功能:
/**
* In order to synchronize tooltips and crosshairs, override the
* built-in events with handlers defined on the parent element.
*/
$('#container').bind('mousemove touchmove touchstart', function(e) {
var chart,
point,
i,
event;
for (i = 0; i < Highcharts.charts.length; i = i + 1) {
chart = Highcharts.charts[i];
event = chart.pointer.normalize(e.originalEvent); // Find coordinates within the chart
point = chart.series[0].searchPoint(event, true); // Get the hovered point
if (point) {
point.highlight(e);
}
}
});
/**
* Override the reset function, we don't need to hide the tooltips and crosshairs.
*/
Highcharts.Pointer.prototype.reset = function() {
return undefined;
};
/**
* Highlight a point by showing tooltip, setting hover state and draw crosshair
*/
Highcharts.Point.prototype.highlight = function(event) {
this.onMouseOver(); // Show the hover marker
this.series.chart.tooltip.refresh(this); // Show the tooltip
this.series.chart.xAxis[0].drawCrosshair(event, this); // Show the crosshair
};
/**
* Synchronize zooming through the setExtremes event handler.
*/
function syncExtremes(e) {
var thisChart = this.chart;
if (e.trigger !== 'syncExtremes') { // Prevent feedback loop
Highcharts.each(Highcharts.charts, function(chart) {
if (chart !== thisChart) {
if (chart.xAxis[0].setExtremes) { // It is null while updating
chart.xAxis[0].setExtremes(e.min, e.max, undefined, false, {
trigger: 'syncExtremes'
});
}
}
});
}
}
(从http://www.highcharts.com/demo/synchronized-charts来源)
然后只需设置syncExtremes
函数在setExtremes
回调。
$scope.chartConfig = {
...
xAxis: {
events: {
setExtremes: syncExtremes
},
...
}
这里有3个图表一的jsfiddle例如:http://jsfiddle.net/nLguvp7m/4/
谢谢。 JS小提琴不起作用。你能解决它吗? –
在Firefox和Chrome中,它仍然不适用于我。跨多个图表同步不会发生。控制台中没有错误,截图http://www.tiikoni.com/tis/view/?id=cfd40f8 –
对不起。你能更新工具提示的同步吗? –