2017-06-05 28 views
0

我有以下代碼。在給定的一天中,它會顯示平均等待時間和最長等待時間(以秒爲單位)。情節線目前給出這兩個值的平均值。我想是一般只是考慮到平均時間所以對於由用戶選擇的特定時期,行會顯示平均該期間Highcharts addPlotLine爲一組值

var seriesOptionsChatChart = [], 
seriesCounterChatChart = 0, 
namesChatChart = ['ChatChartAVG','ChatChartMAX']; 

function createChartChatChart() { 

    Highcharts.stockChart('chart27', { 

     rangeSelector: { 
      buttons: [{ 
       type: 'day', 
       count: 1, 
       text: '1d' 
      },{ 
       type: 'day', 
       count: 5, 
       text: '5d' 
      }, { 
       type: 'week', 
       count: 1, 
       text: '1w' 
      }, { 
       type: 'month', 
       count: 1, 
       text: '1m' 
      }, { 
       type: 'month', 
       count: 3, 
       text: '3m' 
      }, { 
       type: 'year', 
       count: 1, 
       text: '1y' 
      }, { 
       type: 'all', 
       text: 'All' 
      }], 
      selected: 3 // all 
     }, 
    credits: { 
      enabled: false 
     }, 
      chart: { 
      zoomType: 'x', 
      events: { 
       load: computeAvg, 
       redraw: computeAvg 
      } 
     }, 

     yAxis: { 

      plotLines: [{ 
       value: 0, 
       width: 2, 
       color: 'silver' 
      }], 
      title: { 
       text: 'Seconds' 
      } 
     }, 

     plotOptions: { 
      series: { 
       showInNavigator: true, 
       turboThreshold:0 
      } 
     }, 

     tooltip: { 
      pointFormat: '<span style="color:{series.color}">Seconds</span>: <b>{point.y}</b><br/>', 
      split: true 
     }, 

     series: seriesOptionsChatChart 
    }); 
} 

$.each(namesChatChart, function (i, name) { 

    $.getJSON('/' + name.toLowerCase(), function (data) { 

     if (name=='ChatChartMAX') { 
      seriesColour = '#D50000'; 
     } 
     else { 
      seriesColour = '#1DA2B6'; 
     } 

     seriesOptionsChatChart[i] = { 
      name: name, 
      data: data, 
      color: seriesColour, 
     }; 
     seriesCounterChatChart += 1; 
     if (seriesCounterChatChart === namesChatChart.length) { 
      createChartChatChart(); 
     } 
    }); 
}); 


function computeAvg() { 
    var chart = this, 
     series = chart.series, 
     yAxis = chart.yAxis[0], 
     xAxis = chart.xAxis[0], 
     extremes = xAxis.getExtremes(), 
     min = extremes.min, 
     max = extremes.max, 
     plotLine = chart.get('avgLine'), 
     sum = 0, 
     count = 0; 

    Highcharts.each(series, function (serie, i) { 
     if(serie.name !== 'Navigator') { 
      Highcharts.each(serie.data, function (point, j) { 
       if (point.x >= min && point.x <= max) { 
        sum += point.y; 
        count++; 
       } 
      }); 
     } 
    }); 

    yAxis.removePlotLine('avgLine'); 
    yAxis.addPlotLine({ 
     value: (sum/count), 
     color: '#52B184', 
     width: 2, 
     id: 'avgLine', 
     label: { 
      text: (sum/count).toFixed(2), 
      verticalAlign: 'middle', 
      align: 'right', 
      rotation: 0, 
     }   
    }); 

} 
+1

你能不能用固定數據發佈你的問題的實例,比如jsFiddle? –

+0

你正在改變圖表,它應該更新情節 –

+0

我只希望它專注於一個特定的系列,並且他們都是 – pee2pee

回答

0

改變if(serie.name !== 'Navigator') {專注於系列I想要