简体   繁体   中英

Passing an array in HighChart Bar Series Data

I am using HighCharts for the data visualization as bar chart for one of the problems. However, I am facing problems with passing a series data/category as an array. Please help me with this

$.getJSON('TotalUsers.json', function(data) {
var valuesTotal = [];
var daysTotal = [];
$.each(data.day, function(key, obj) {
    valuesTotal.push('<li id="value-' + key + '">' + obj["@value"] + '</li>');
    daysTotal.push('<li id="day-' + key + '">' + obj["@date"] + '</li>');
});
});​

At the end of it, I am getting array which is valuesTotal = [53819,57558,61141];

I would like to pass this array in the category and series data of a stacked bar chart in HighGraphs like this

var chart; $(document).ready(function() {

    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'bar'
        },
        title: {
            text: 'Stacked Bar Chart Representation'
        },
        xAxis: {
            categories: [valuesActive];
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Active User Ratio'
            }
        },
        legend: {
            backgroundColor: '#FFFFFF',
            reversed: true
        },
        tooltip: {
            formatter: function() {
                return ''+
                    this.series.name +': '+ this.y +'';
            }
        },
        plotOptions: {
            series: {
                stacking: 'normal'
            }
        },
            series: [{
            name: 'Total Days',
            data: daysTotal    // m getting an error here
        }, {
            name: 'Total Users',
            data: valuesTotal   // m getting an error here
        }]
    });

Please help me out. Any help will be appreciated.

Thanks.

You can declare an array in javascript like this also:

var daysTotal = new Array();

Also try to insert values into array like:

daysTotal[key] = value;

Then pass this array to highchart.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM