To pass dynamic json array to Highcharts Pie Chart

后端 未结 4 1328
情歌与酒
情歌与酒 2020-12-10 09:50

I passed json encoded string(eg. $TEXT2 consisting [\"chrome\",\"15\",\"firefox\",\"20\"]) from xcode to an array(eg. arr) in javascript.Now I want to pass this array contai

4条回答
  •  清歌不尽
    2020-12-10 10:01

    Simply do :

    Create array with Jquery as bellow :

    $.each(data['values'], function(i, val) {
                        x_values_sub['name'] = i
                        x_values_sub['y'] = val
                        x_values.push(x_values_sub);
                        x_values_sub = {};
    });
    

    // Then call this array with HighCharts as data

    series: [{
                                type: 'pie',
                                name: null,
                                data: x_values
    }]
    

    // Tested and it works with simple javascript object :

    Object Part1Name: 25 Part2Name: 75__proto__: Object
    

提交回复
热议问题