我正在使用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);
}
答案 0 :(得分:1)
将reportData
作为drawChart
...的参数
setTimeout(() => {
GoogleCharts.load(() => {
drawChart(reportData);
});
}, 500);
function drawChart(reportData) {
let data = google.visualization.arrayToDataTable(reportData);