2016-03-04 84 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

那么该怎么办请帮忙 –