【问题标题】:Highcharts Shared Tooltip not appearing for multi-axes chart with positioning具有定位的多轴图表未显示 Highcharts 共享工具提示
【发布时间】:2016-06-21 07:21:26
【问题描述】:

我有一个带有多个 y 轴的图表。我已使用顶部选项将一张图表移至底部。当我将鼠标悬停在移动到底部的图表上时,不会出现共享工具提示。当我将鼠标悬停在条形图上方的空间上时。条和 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

任何意见表示赞赏。 谢谢

【问题讨论】:

  • 对我来说,您的 jsfiddle 运行良好,两个系列都打印在工具提示中。你能更新代码来介绍这个问题吗?
  • @SebastianBochan,将鼠标悬停在条形图上方的空间上。条和 100 之间的空间(在 Y 轴上),工具提示不会出现。将鼠标悬停在栏右侧或左侧的空间上,不会出现工具提示。抱歉不够清楚。
  • 为你的 y 轴设置了 top 值,但没有设置高度,这会搞砸一堆事情。这是一个非常令人困惑的设置,我很困惑你试图用它来完成什么。另外,您没有任何系列连接到第二个 y 轴。如果你能弄清楚你真正想要这个图表做什么,我们可以找到一种方法来正确设置它,并在这个过程中清除工具提示问题。例如,如果你只坚持一个 y 轴,一切似乎都可以正常工作:jsfiddle.net/jlbriggs/mL36s92d/1

标签: highcharts tooltip


【解决方案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
    }]
  });
};
});

【讨论】:

  • 感谢@Stringfellow,我现在可以得到这两个图的十字准线,但对我来说,这两个图都在不同的数据点上。为了显示工具提示,我无权访问第二张图的数据点。
猜你喜欢
  • 1970-01-01
  • 2014-03-04
  • 2018-12-07
  • 2012-03-01
  • 1970-01-01
  • 2015-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多