2012-02-03 179 views
3

我需要生成具有向下钻取功能的交互式图表。我遇到了HighCharts,它非常好,很酷,但数据似乎是静态的。有什么办法可以在HighChart中动态数据和动态数据下钻。HighCharts:向下钻取动态数据

data = [{ 
        y: 55.11, 
        color: colors[0], 
        drilldown: { 
         name: null, 
         categories: null, 
         data: null, 
         color: colors[0] 
        } 
       }, { 
        y: 21.63, 
        color: colors[1], 
        drilldown: { 
         name: 'Firefox versions', 
         categories: ['Firefox 2.0', 'Firefox 3.0', 'Firefox 3.5', 'Firefox 3.6', 'Firefox 4.0'], 
         data: [0.20, 0.83, 1.58, 13.12, 5.43], 
         color: colors[1] 
        } 
       }]; 

其中y的值被赋予静态值。我需要它是动态的,并为每个值分配一个明细。它可以在HighCharts中完成,还是有其他工具可以使用?

回答

1

这里是东西,你可以作为一个起点使用:

var level = 0; 
var refreshChart = function(){ 
    new Highcharts.Chart({ 
     chart: { 
      renderTo: 'chart' 
     }, 

     xAxis: { 
      categories: getXAxisValues() 
     }, 

     series: [ 
        { 
         data: getSeries1() 
        }, 
        { 
         data: getSeries2() 
        } 
      ], 

     plotOptions: { 
      series: { 
       point: { 
        events: { 
         click: function() { 
          level = 1; 
          refreshChart(); 
         } 
        } 
       } 
      } 
     } 
    }); 
}; 

var getSeries1 = function(){ 
    if(level == 0) 
     // returns series data as described in highcharts documentation 
    else 
     // return some other data 
} 

// similar to getXAxisValues() if you have it and for getSeries2 if you have another serie 
+0

感谢,我可以定义这些数据的深入分析? – Ianthe 2012-02-03 08:27:29

+0

,正如您可以在getSeries1中看到的一样,取决于当前级别,您生成数据,因此当级别为1时,将生成来自“详细信息”级别的数据(如果这是您钻取的含义)。 – 2012-02-03 15:20:24

+0

我不确定我是否正确理解你。但我需要的是,如何动态分配深入到每个y值,就像我可以在我的示例中看到的一样,每个y值都有一个[深入]标记 – Ianthe 2012-02-10 01:10:06