2015-11-13 77 views
1

我有两组数据在使用Highcharts的折线图中。我需要能够自定义工具提示格式化程序,但是无论何时拖动一个点,工具提示都非常糟糕(类似于一堆闪烁的开关)。Highcharts draggable glitchy tooltip

这里是的jsfiddle:http://jsfiddle.net/utnz2b9e/39/

我谈论的行为可以在图表的右边拖动蓝色点时可以看到。拖动时,十字准线在该点与另一个系列的最后一个非空数据点的x值之间来回跳动。另外,工具提示会闪烁并且很难查看。

使用Javascript -

var planChart; 
var startDates = ["Fri, 11/6/15", "Sat, 11/7/15", "Sun, 11/8/15", "Mon, 11/9/15", "Tue, 11/10/15", "Wed, 11/11/15", "Thu, 11/12/15", "Fri, 11/13/15", "Sat, 11/14/15", "Sun, 11/15/15", "Mon, 11/16/15", "Tue, 11/17/15", "Wed, 11/18/15", "Thu, 11/19/15", "Fri, 11/20/15"]; 

$(function() { 
    planChart = { 
     chart: { 
      renderTo: 'container', 
      animation: false 
     }, 
     title: { 
      text: '' 
     }, 
     xAxis: { 
      categories: startDates, 
      crosshair: true, 
     }, 
     yAxis: [{ // Primary yAxis 
      labels: { 
       style: { 
        color: '#20709e' 
       }, 
       formatter:function() { 
        return Highcharts.numberFormat(this.value, 0, '', ','); 
       } 
      }, 
      title: { 
       text: 'Data', 
       margin: 30, 
       style: { 
        color: '#20709e' 
       } 
      } 
     }, { // Secondary yAxis 
      gridLineWidth: 0, 
      labels: { 
       style: { 
        color: '#B9B9B9' 
       }, 
       formatter:function() { 
        return Highcharts.numberFormat(this.value, 0, '', ','); 
       } 
      }, 
      title: { 
       text: '', 
      }, 
      opposite: true 
     }], 

     plotOptions: { 
      series: { 
       connectNulls: true, 
       stickyTracking: false, 
       marker: { 
        enabled: true, 
        symbol: 'circle' 
       } 
      }, 
      line: { 
       cursor: 'ns-resize' 
      } 
     }, 

     tooltip: { 
      shared: true, 
      formatter: function() { 
       var tooltipString = this.x + '<br/>'; 
       this.points.forEach(function(point) { 
        if (point.series.index == 0) { 
         var y = Math.round(point.y); 
         var roundingFactor = Math.min(100, Math.pow(10, y.toString().length - 2)); 
         tooltipString += '<span style="color:' + point.color + '">\u25CF</span> ' + '<b> ' + Math.ceil(point.y/roundingFactor) * roundingFactor + '</b><br/>'; 
        } else if (point.series.index == 1) { 
         var y = Math.round(point.y); 
         var roundingFactor = Math.min(100, Math.pow(10, y.toString().length - 2)); 
         tooltipString += '<span style="color:' + point.color + '">\u25CF</span> ' + '<b> ' + Math.ceil(point.y/roundingFactor) * roundingFactor + '</b><br/>'; 
        } 
       }) 
       return tooltipString; 
      } 
     }, 

     credits: { 
      enabled: false 
     }, 

     series: [{ 
      name: '1', 
      data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, null, 18.3, 13.9, 9.6, 7.0, 7.0, 7.0], 
      draggableY: true, 
      yAxis: 0, 
      dragMinY: 0, 
      style: { 
       color: '#20709e' 
      } 
     }, { 
      name: '2', 
      data: [null, null, 20, 30, 40, 40, 30, 34, 43, null, null, null, null, null, null], 
      draggableY: true, 
      yAxis: 0, 
      dragMinY: 0, 
      style: { 
       color: '#20709e' 
      } 
     }] 
    } 
    $('.actualPlansPlot').highcharts(planChart); 
    }); 
} 

回答

0

我的建议是添加animation: falsetooltip { }性能。

见API:http://api.highcharts.com/highcharts/tooltip.animation

这将阻止它试图每个位置移动时做动画,调整点的时候会导致一个不错的平稳过渡。

作为一个方面说明:如果你没有数字格式,并与一些点大量小数,并没有其他点结束了,你还是会发现一些闪烁。这可以通过应用一些一致的数字格式来解决。