2017-11-24 4 views
0

"pie"という名前の円グラフループ配列のデータを取得しようとしています。しかし、選択された行e.locationでエラーが発生しました。私はその行をコメントしています。ここに絵がある。それはそれなしで動作しますが、私はあなたがすべてでそのマッピングを行う必要はありませんように思えソリューションimage where i get the errorループを使用して円グラフで値を送信

<div class="col-md-6"> 
    <style> 
     #chartdiv { 
     width: 100%; 
     height: 500px; 
     } 
    </style> 

    <script src="https://www.amcharts.com/lib/3/amcharts.js"></script> 
    <script src="https://www.amcharts.com/lib/3/pie.js"></script> 
    <script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script> 
    <link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" /> 
    <script src="https://www.amcharts.com/lib/3/themes/light.js"></script> 

    <script> 
     var pie = [ 
      {"id":"1","location":"address1","value":"20"}, 
      {"id":"2","location":"address2","value":"30"}, 
      {"id":"3","location":"address3","value":"40"}, 
      {"id":"4","location":"address4","value":"50"}, 
      {"id":"5","location":"address5","value":"60"}, 
      {"id":"6","location":"address6","value":"70"}, 
      {"id":"7","location":"address7","value":"80"}, 
     ]; 

     console.log(pie); 

     pie.map((e) => { 
      console.log(e.location); 
      return e; 
     }); 

     var chart = AmCharts.makeChart("chartdiv", { 
      "type": "pie", 
      "theme": "light", 
      "dataProvider": [pie.map((e)=>{ 
       "location": e.location, //here is the error 
       "value": e.value //here is the error 
      })], 
      "valueField": "value", 
      "titleField": "location", 
      "balloon":{ 
      "fixedPosition":true 
      }, 
      "export": { 
       "enabled": true 
      } 
     }); 
    </script> 

    <div id="chartdiv"></div> 
</div> 

答えて

0

を見つける助けてください。

だから"dataProvider": pie,

Here's a working version on JSFiddle.

+0

それは働いた。ありがとうございますDavid:P –

+0

私は投票に十分な評判がありません。そのために残念。 –

0
[pie.map((e)=>{return { 
       "location": e.location, //here is the error 
       "value": e.value //here is the error} 
      }})] 

まず{関数及び第二のオブジェクトのためであるを使用。

関連する問題