Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw HighChart XAxis dynamically

I am drawing a highchart as-

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

where data is an array for series data.

I also have an array for xAxis Categeries as-

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

my chart is drawing correctly but problem with the xAxis categories is I don't know how to set categories dynamically .

for more clarity i am adding some code-

 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);

}

like image 342
Pradeep Avatar asked Apr 27 '13 06:04

Pradeep


2 Answers

You are looking for the Axis.update() method.

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

Here's an example.

animated x axis update

like image 155
Mark Avatar answered Nov 12 '22 13:11

Mark


Yes you can do it since only fiew months. 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]
    });

Hope it will help someone.

like image 22
Ser Avatar answered Nov 12 '22 13:11

Ser