在HighChart Bar系列数据中传递数组

时间:2022-09-15 09:00:17

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

我正在使用HighCharts将数据可视化作为其中一个问题的条形图。但是,我将系列数据/类别作为数组传递时遇到问题。请在这件事上给予我帮助

$.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];

在它结束时,我得到的数值是值总数= [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

我想在HighGraphs中的堆积条形图的类别和系列数据中传递此数组,如下所示

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

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.

1 个解决方案

#1


0  

You can declare an array in javascript like this also:

您也可以在javascript中声明一个数组,如下所示:

var daysTotal = new Array();

Also try to insert values into array like:

还尝试将值插入到数组中,如:

daysTotal[key] = value;

Then pass this array to highchart.

然后将此数组传递给highchart。

#1


0  

You can declare an array in javascript like this also:

您也可以在javascript中声明一个数组,如下所示:

var daysTotal = new Array();

Also try to insert values into array like:

还尝试将值插入到数组中,如:

daysTotal[key] = value;

Then pass this array to highchart.

然后将此数组传递给highchart。