Yuriy
Yuriy

Reputation: 457

Highcharts how to pass data from server into chart

This is code from example Highcharts:

$(document).ready(function () {
            $(function () {
                $('#container').highcharts({
                    chart: {
                        type: 'column',
                        margin: 75,
                        options3d: {
                            enabled: true,
                            alpha: 10,
                            beta: 25,
                            depth: 70
                        }
                    },
                    title: {
                        text: '@Model.FirstName'
                    },
                    plotOptions: {
                        column: {
                            depth: 25
                        }
                    },
                    xAxis: {
                        categories: Highcharts.getOptions().lang.shortMonths
                    },
                    yAxis: {
                        title: {
                            text: null
                        }
                    },
                    series: [{
                        name: 'Sales',
                        data: [2, 3, null, 4, 0, 5, 1, 4, 6, 3]
                    }],
                    credits: {
                        enabled: false
                    },
                });
            });
        });

I want to pass series "data: [2, 3, null, 4, 0, 5, 1, 4, 6, 3]" and categories: "Highcharts.getOptions().lang.shortMonths" from server. How can i do it?

Upvotes: 0

Views: 448

Answers (1)

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93611

You can request data via Ajax and call chart.addSeries

function requestData() {
    $.ajax({
        url: 'myserverurl',
        type: "GET",
        dataType: "json",
        success: function(data) {
            chart.addSeries({
              name: "somename",
              data: data.mydata
            });
        },
        cache: false
    });
}

Upvotes: 2

Related Questions