【发布时间】:2020-10-15 08:24:03
【问题描述】:
我正在尝试使用 Vue.js 库使用 Google Charts 制作图表,但我不知道如何添加到 div。
这是我尝试做的,这是如何使用香草 javascript (Here the code example of the documentation) 添加图表,我尝试适应 vue,但没有发生任何事情:
google.charts.load('current', {'packages': ['corechart']});
Vue.component('line-char', {
data: function(){
// Create the data table.
var data = google.visualization.arrayToDataTable([
['Tiempo', 'Temperatura'],
[1, 1000],
[2, 1170],
[3, 660],
[4, 1030]
]);
// Set chart options
var options = {
'title': 'Data Line',
'width': '100%',
'height': 250,
legend: { position: 'bottom' }
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
},
template: '<div v-model="chart_div"></div>'
});
html:
<div id="component">
<line-chart></line-chart>
</div>
【问题讨论】:
标签: javascript html vue.js