【发布时间】:2020-01-02 09:01:25
【问题描述】:
使用 vue-google-charts 插件的说明如下:https://www.npmjs.com/package/vue-google-charts
想创建组织结构图:https://developers.google.com/chart/interactive/docs/gallery/orgchart
认为我必须使用 onChartReady() 但不知道如何使用组织结构图。
<template >
<div class="container">
<GChart
type="OrgChart"
:data="chartData"
@ready="onChartReady"
/>
</div>
</template>
<script>
import { GChart } from 'vue-google-charts'
export default {
components: {
GChart
},
data () {
return {
// Array will be automatically processed with visualization.arrayToDataTable function
chartData: [
[{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'},
'', 'The President'],
[{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President</div>'},
'Mike', 'VP'],
['Alice', 'Mike', ''],
['Bob', 'Jim', 'Bob Sponge'],
['Carol', 'Bob', '']
],
options: {allowHtml : true}
}
},
methods: {
onChartReady (chart, google) {
var chart = new google.visualization.OrgChart();
chart.draw(this.chartData, this.options)
}
}
}
</script>
当我运行以下代码时,我只是得到一个空白网页,上面显示“未处理的承诺拒绝 TypeError:“google.visualization[type] 不是构造函数”。
认为我需要在 google.visualization.OrgChart() 中输入一些内容;但不确定我的代码是什么。
【问题讨论】:
-
你在哪里加载google charts packages?一定要加载
'orgchart'包... -
谢谢@WhiteHat。在
上面 type="OrgChart" 我添加了 :settings="{ packages: ['orgchart'] }"。刷新后,我现在看到一个图表,但呈现的图表看起来不正确。我需要从我的 chartData 数组中删除 标签吗?
标签: javascript vue.js google-visualization