2013-04-27 90 views
1

我畫highchart原樣如何繪製HighChart x軸動態

options.series.push({ name: this.SubCity, data: this.Data }); 

,其中數據是一系列的數據陣列。

我也有AS-

Categ['Jan-Mar', 'Apr-Jun', 'Jul-Sep', 'Oct-Dec'] 

爲X軸基本分類數組我的圖表繪製正確,但問題與x軸類別 是我不知道如何動態設置的類別。

爲了更清楚,我加入一些代碼 -

var PriceTrend = JSON.parse(Data); 
var AvgRate = new Array(); 
var Categories = new Array(); 

$(PriceTrend).each(function (index) 
     { 
      MaxRate.push(this.Max); 
      MinRate.push(this.Min); 
      AvgRate.push((this.Max + this.Min)/2); 
      Categories.push(this.Quarter); 
     }); 


     TrendData.push({ SeriesID: SeriesID, Data: AvgRate, Visible: true, SubCity: SubCity, Categ: Categories }); 

     DisplayTrend(); 


function DisplayTrend() 
{ 
options.series = []; 

$(TrendData).each(function (Index) 
{ 
    if (this.Visible) 
    { 
     options.series.push({ name: this.SubCity, data: this.Data }); 
    } 
}); 
chart = new Highcharts.Chart(options); 

}

+0

您是否嘗試過使用setCategories? http://api.highcharts.com/highcharts#Axis.setCategories() – 2013-04-29 13:35:47

回答

4

您正在尋找Axis.update()方法。

Highcharts.charts[0].xAxis[0].update({categories:['some','new','categories']}, true); 

這是example

animated x axis update

1

是的,你可以做到這一點,因爲只有fiew個月。 http://api.highcharts.com/highcharts#Chart.addAxis() http://jsfiddle.net/wvaGt

chart.addAxis({ // Secondary yAxis 
     id: 'rainfall-axis', 
     title: { 
      text: 'Rainfall' 
     }, 
     lineWidth: 2, 
     lineColor: '#08F', 
     opposite: true 
    }); 
    chart.addSeries({ 
     name: 'Rainfall', 
     type: 'column', 
     color: '#08F', 
     yAxis: 'rainfall-axis', 
     data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4] 
    }); 

希望它會幫助別人。