2016-03-04 85 views
1

我有一個很高的圖表,它在刷新時動態地將數據推入系列,但每次顏色都會更改如何修復圖表的顏色。我使用角度js和我的高圖形配置對象是如下在HighCharts中修復圖表的顏色

var chartConfig = { 
      credits: { 
       enabled: false 
      }, 
      options: { 
       colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'], 
       chart: { 
        backgroundColor: '#EDEDED', 
        zoomType: 'x', 
        reflow: true 
       }, 
       credits: false 
      }, 
      series: [], 
      tooltip: { 
       headerFormat: '<span style="font-size:10px">{point.key}</span><table>', 
       pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' + 
        '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>', 
       footerFormat: '</table>', 
       shared: true, 
       useHTML: true 
      }, 
      legend: { 
       enabled: true 
      }, 
      series: [], 
      exporting: { 
       csv: { 
        dateFormat: '%Y-%m-%d' 
       } 
      }, 
      title: { 
       text: '', 
       style: { 
        display: 'none' 
       } 
      }, 
      xAxis: { 
       title: {} 
      }, 
      func: function(chart) { 
       $timeout(function() { 
        chart.reflow(); 
       }, 0); 
      } 
     }; 
+0

如果顏色改變,那麼你就沒有更新的系列 - 您要添加一個新的。顯示您如何更新數據以獲得更多幫助。 – jlbriggs

+0

我將系列數組設置爲null,然後再將值插入系列中 –

+0

每次刷新時,我都會調用一個Ajax來獲取數據,然後將其插入到系列數組中 –

回答

2

而不是設置chartConfig.series[index] = newSeries的,使用Highcharts對象,並通過@jlbriggs提到的方法。您可以按照highcharts-ng FAQ(第二點)中的描述訪問圖表原始對象。

爲了解釋這個問題:每次highcharts-ng在更新到達時重新創建系列。這意味着系列顏色將作爲chart.colors陣列的新索引。因此,而不是使用上述溶液,可以:

每個系列直接在選項
  • 分配顏色:

    chartConfig.series[index] = { data: [...], color: 'red' }; 
    
  • 設置chart.colors爲相同的長度系列的數你在圖表​​上使用:

    colors: ['#058DC7', '#50B432', '#ED561B'], // for example only three series on the chart 
    
+0

嘗試過使用chartConfig.series.update,但給出了一個錯誤,因爲chartConfig.series.update是不是功能 –

+0

在常見問題部分查看更多信息。不要在'chartConfig.series.update'上使用它 - 在選項中沒有'update()'這樣的方法。 –

+0

那麼該怎麼辦請幫忙 –