Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Highchart步骤折线图工具提示在没有数据时显示旧数据_Javascript_Highcharts - Fatal编程技术网

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

Javascript Highchart步骤折线图工具提示在没有数据时显示旧数据,javascript,highcharts,Javascript,Highcharts,关于以下内容 我已经创建了一个带有阶梯线的图表 step: true 当序列没有数据时,我试图在工具提示中显示旧数据。例如,在2015年7月1日鼠标悬停时,我有数据,因此工具提示显示数据。但是如果你向前移动,工具提示不会显示任何东西 HighChart是否支持在没有数据时显示最新的旧数据。您应该使用tooltip.formatter,然后使用循环查找具有相同x的点。如果不存在,则从步骤序列中提取最后一点。简单演示: 工具提示:{ 分享:错, 格式化程序:函数(){ var x=这个.x, s

关于以下内容

我已经创建了一个带有阶梯线的图表

 step: true
当序列没有数据时,我试图在工具提示中显示旧数据。例如,在2015年7月1日鼠标悬停时,我有数据,因此工具提示显示数据。但是如果你向前移动,工具提示不会显示任何东西


HighChart是否支持在没有数据时显示最新的旧数据。

您应该使用tooltip.formatter,然后使用循环查找具有相同x的点。如果不存在,则从步骤序列中提取最后一点。简单演示:

工具提示:{
分享:错,
格式化程序:函数(){
var x=这个.x,
series=this.series.chart.series,
stepSeries=系列[1],
lastPointStepSerie=stepSeries.points[stepSeries.points.length-1],
each=Highcharts.each,
txt=''+Highcharts.dateFormat('%A,%b%d,%Y',this.x)+'
'; 每个系列、功能(s、i){ 每个(s.点,函数(p,j){ 如果(p.x==x){ txt+='\u25CF'+s.name+':'+p.y+'
} }); }); 如果(x>lastPointStepSerie.x){ txt+='\u25CF'+stepSeries.name+':'+lastPointStepSerie.y+'
} 返回txt; } },
总结如果突出显示蓝色系列的最后一个点,您还希望打印黑色系列的最后一个点,对吗?否。对于蓝色系列,我有数据。对于黑色系列,我没有数据。因此,我只想打印黑色系列的最后一点,因为它是一条阶梯线。蓝线不是阶梯线。嗯,有点不清楚。当您将鼠标悬停在蓝色系列和黑色存在上时,将打印两个值。这是正确的。当您将鼠标悬停在蓝色系列上,其下方不是黑点(无值),则应显示最后一个黑色。是否正确?是的,这是正确的。是的,您建议的解决方案工作正常。请将其添加为此问题的答案,以便其他人也能从中受益。谢谢!!
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><br/>';

    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><br/>'
        }
      });
    });

    if(x > lastPointStepSerie.x) {
        txt += '<span style="color:' + lastPointStepSerie.color + '">\u25CF</span> ' + stepSeries.name + ': <b>' + lastPointStepSerie.y + '</b><br/>'
    }

    return txt;
  }
},