【发布时间】:2017-03-30 11:31:33
【问题描述】:
我正在使用VueCharts,这是一个用于 vue 的 Google Charts 插件。
我正在尝试为图表提供更新的 Material Design 外观。我尝试将“google.charts.Bar”传递给图表类型道具,它确实有效。但是,许多选项都被忽略了,因为正如Google Charts docs 中所述,选项对象需要使用google.charts.Bar.convertOptions(options) 进行转换,而插件不会这样做。
查看源代码,该插件安装了一个“vue-chart”组件。该组件使用ChartWrapper 处理加载图表库,如下所示:
methods: {
buildWrapper (chartType, dataTable, options, containerId) {
let wrapper = new google.visualization.ChartWrapper({
chartType: chartType,
dataTable: dataTable,
options: options,
containerId: containerId
})
return wrapper
},
所以我只需要重写此方法以在将选项传递给 ChartWrapper 之前对其进行转换。
但是怎么做呢?我还没有找到一种方法来简单地覆盖 vue 文档中的组件方法。我可以创建一个新组件并将转换后的选项向下传递,但我需要访问 google 对象,该对象仅由插件在内部加载。
我也读过我可以使用 mixins,但不清楚如何使用。这不起作用:
Vue.component('MyCustomChart', {
mixins: ['vue-chart'],
methods: {
buildWrapper (chartType, dataTable, options, containerId) {
let wrapper = new google.visualization.ChartWrapper({
chartType: chartType,
dataTable: dataTable,
options: google.charts.Bar.convertOptions(options), // that's all I need
containerId: containerId
})
return wrapper
},
}
})
[Vue 警告]:无法挂载组件:未定义模板或渲染函数。 (在 MyCustomChart 中找到)
【问题讨论】:
标签: vuejs2 google-visualization