将数据传递到Angular Google图表

时间:2019-06-03 18:31:50

标签: angular google-visualization

我正在使用Google Charts for Angular7。我想将reportData传递给drawChart函数。

   var reportData = {"High":100, "Medium" : 200, "Low" : 300}

    generateChart() {
        setTimeout(() => {
          GoogleCharts.load(drawChart);
        }, 500);
    }

    function drawChart(reportData) {

          let data = google.visualization.arrayToDataTable([
            ['Category', 'Value'],
            ['High', reportData.High],
            ['Medium', reportData.Medium],
            ['Low', reportData.Low]
          ]);

          let options = {
            chartArea: { left: 30, top: 30, width: '70%', height: '70%' },
            enableInteractivity: true,
            legend: { position: 'bottom' },
            colors: ['#ccc', '#ddd', '#eee']
          };

          let chart = new google.visualization.PieChart(document.getElementById('chart'));

          chart.draw(data, options);
        }

1 个答案:

答案 0 :(得分:1)

reportData作为drawChart ...的参数

    setTimeout(() => {
      GoogleCharts.load(() => {
        drawChart(reportData);
      });
    }, 500);

function drawChart(reportData) {

      let data = google.visualization.arrayToDataTable(reportData);