Highchart pie - 动态饼图的动态数组

时间:2013-02-25 00:15:18

标签: javascript arrays highcharts pie-chart

在我的代码下面:

$(document).ready(function() {
    for(var j = 0; j < productsSize; j++) {
        //tmStringToDisplay.push(name[j], parseInt(percent[j]));
        var tmStringToDisplay = [name[j], parseInt(percent[j])];
        tmStringToDisplay.push(temp);
    }
    console.log(tmStringToDisplay);

    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'The best selling products :'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage}%</b>',
            percentageDecimals: 1
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                    }
                }
            }
        },



        series: [{
            type: 'pie',
            name: 'Product share',
            data: tmStringToDisplay
        }]
    });

我必须创建“tmStringToDisplay”选项卡,将其放入系列数组的数据var中。 在静态中,就像那样:

series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox',   45.0],
                ['IE',       26.8],
                {
                    name: 'Chrome',
                    y: 12.8,
                    sliced: true,
                    selected: true
                },
                ['Safari',    8.5],
                ['Opera',     6.2],
                ['Others',   0.7]
            ]
        }]

这就是循环FOR,一切正常:

for(var j = 0; j < productsSize; j++) {
        //tmStringToDisplay.push(name[j], parseInt(percent[j]));
        var tmStringToDisplay = [name[j], parseInt(percent[j])];
        tmStringToDisplay.push(temp);
    }

我必须创建并准备“tmStringToDisplay”,它需要像静态示例一样....

谢谢!

1 个答案:

答案 0 :(得分:1)

将tmStringToDisplay解析为json

例如 jQuery.parseJSON(tmStringToDisplay);