首页 文章

Highchart步骤折线图工具提示在没有数据时显示旧数据

提问于
浏览
0

在以下JS Fiddle

我创建了一个带有步骤线的图表 .

step: true

当没有该系列的数据时,我试图在工具提示中显示旧数据 . 例如 . 在2015年7月1日的鼠标上,我有数据,所以工具提示显示数据 . 但是,如果你移动forwared工具提示不显示任何东西 .

如果没有数据,HighChart是否支持显示最新的旧数据 .

1 回答

  • 0

    您应该使用tooltip.formatter然后使用循环来查找具有相同x的点 . 如果不存在则从步骤系列中提取最后一个点 . 简单演示:http://jsfiddle.net/vs6scfch .

    tooltip: {
      shared: false,
      formatter: function() {
        var x = this.x,
                series = this.series.chart.series,
            stepSeries = series[1],
            lastPointStepSerie = stepSeries.points[stepSeries.points.length - 1], 
                each = Highcharts.each,
            txt = '<span style="font-size: 10px">' + Highcharts.dateFormat('%A, %b %d, %Y', this.x) + '</span>
    '; each(series, function(s,i) { each(s.points, function(p, j) { if(p.x === x) { txt += '<span style="color:' + p.color + '">\u25CF</span> ' + s.name + ': <b>' + p.y + '</b>
    ' } }); }); if(x > lastPointStepSerie.x) { txt += '<span style="color:' + lastPointStepSerie.color + '">\u25CF</span> ' + stepSeries.name + ': <b>' + lastPointStepSerie.y + '</b>
    ' } return txt; } },

相关问题