如何在javascript中使数据动态化

时间:2017-09-19 08:10:45

标签: javascript

我正在尝试使用变量“temp”的数据制作饼图。数据显示在控制台上的图片中。我应该如何开始这个请帮助我。

enter image description here

$(function () {
    var temp = <?php echo $branch_emp; ?>;
    console.log(temp);
    $('#pie_chart').highcharts({
        chart: {
            type: 'pie',
            options3d: {
                enabled: true,
                alpha: 45,
                beta: 0
            }
        },
        title: {
            text: 'Incident Report'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                depth: 35,
                dataLabels: {
                    enabled: true,
                    format: '{point.name}'
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [ 
                //this is where i want the data
                // temp.foreach(function(){
                    ['a', 50.0],
                    ['b', 25.0],
                    ['c', 25.0],
                // })
            ]
        }]
    });
});

1 个答案:

答案 0 :(得分:0)

您只想使用map将属性branch_nametotalemp的对象数组转换为多维数组

series: [{
        type: 'pie',
        name: 'Browser share',
        data: temp.map(function(e){
            return [e.branch_name,e.totalemp];
        })
    }]