2017-09-19 12 views
0

変数 "temp"のデータで円グラフを作成しようとしています。データはコンソールの画像に表示されます。どうすればこれを始めるべきですか?JavaScriptを使用してデータを動的にする方法

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], 
       // }) 
      ] 
     }] 
    }); 
}); 
+0

にプロパティbranch_nametotalempを持つオブジェクトのあなたの配列をオンにするmapを使用したいあなたはjQueryとjsの他の参照を追加している – Ajay2707

答えて

0

あなたは、単にマルチdiensional配列

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

それは働いてくれてありがと –

関連する問題