I'm using VueCharts which is a Google Charts plugin for vue.
I'm trying to give the newer Material Design looks to the charts. I've tried passing "google.charts.Bar" to chart-type prop and it did work. However, many of the options are ignored because, as stated in the Google Charts docs, the options object needs to be converted by using google.charts.Bar.convertOptions(options)
, something the plugin doesn't do.
Looking at the source, the plugin installs a 'vue-chart' component. This component uses ChartWrapper
to handle loading the chart libraries, like so:
methods: {
buildWrapper (chartType, dataTable, options, containerId) {
let wrapper = new google.visualization.ChartWrapper({
chartType: chartType,
dataTable: dataTable,
options: options,
containerId: containerId
})
return wrapper
},
So all I need is to override this method to convert the options before passing them to the ChartWrapper.
But how? I haven't found a way to simply override a component method in vue docs. I could create a new component and pass the converted options down, but I need access to the google object, which is only loaded internally by the plugin.
I have also read I could use mixins, but it's not clear how. This doesn't work:
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 warn]: Failed to mount component: template or render function not defined. (found in MyCustomChart)
vue-charts
is a plugin.vue-chart
is a globally added component. – Cortney