看看使用同步圖表。
http://www.highcharts.com/demo/synchronized-charts
的的jsfiddle被更新爲使用同步圖表。 JSFiddle
$(function() {
$('#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'
});
}
}
});
}
}
var dataset = [{
"name": "Series 1",
"type": "column",
"data": [29.9, 71.5, 106.4]
}, {
"name": "Series 2",
"type": "line",
"data": [216.4, 194.1, 95.6]
}];
for (var i = 0; i < dataset.length; i++) {
var dataitem = dataset[i];
$("<div class=\"chart\">")
.appendTo('#container').highcharts({
title: {
text: dataitem.name
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar']
},
tooltip: {
crosshairs: {
color: 'rgba(27,161,218,0.5)',
dashStyle: 'solid',
zIndex: -1
}
},
series: [{
data: dataitem.data,
name: dataitem.name,
type: dataitem.type
}]
});
};
});
對我來說,你的jsfiddle工作得很好,兩個系列都印在了提示。你能否更新代碼來介紹這個問題? –
@SebastianBochan,懸停在條形圖正上方的空間中。條和100之間的空間(Y軸),工具提示不會出現。將鼠標懸停在工具欄右側或左側的空白處,工具提示不會出現。對不起,不夠清楚。 –
一堆東西正在被你的y軸設置一個* top *值而不是一個高度。這是一個非常混亂的設置,我很困惑你試圖用它來完成什麼。另外,你沒有任何連接到第二y軸的系列。如果您可以澄清您實際上希望此圖表執行的操作,我們可以找到正確設置它的方法,並清除過程中的工具提示問題。例如,如果你只是堅持一個單一的Y軸,一切似乎工作正常:http://jsfiddle.net/jlbriggs/mL36s92d/1/ – jlbriggs