Highcharts Shared Tooltip不会出现带定位的多轴图表

时间:2016-06-21 07:21:26

标签: highcharts tooltip

我有一个包含多个y轴的图表。我使用top选项将一个图表移动到底部。当我将鼠标悬停在图表上移动到底部时,不显示共享工具提示。当我将鼠标悬停在条形图上方的空间时。条和100之间的空间(在Y轴上),工具提示不会出现。将鼠标悬停在右侧或左侧的空间处,不会出现工具提示。

我不想让图表处于默认位置。当我将两个图表分开时,它看起来更干净。当图表向下移动时,我可以使共享工具提示工作吗?

我的代码: yAxis: [{ top: 148 }, { top: 0 }], tooltip: { shared: true, crosshairs: { color: 'rgba(27,161,218,0.5)', dashStyle: 'solid', zIndex: -1 } },

这是小提琴:multi-axes graph with positioning

任何意见都表示赞赏。 感谢

1 个答案:

答案 0 :(得分:-1)

使用同步图表。

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
    }]
  });
};
});