In my MainChart.vue file, I defined my chart like this:
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
// const brandPrimary = '#20a8d8'
export default {
extends: Line,
mixins: [reactiveProp],
props: ['options', 'chartData', 'height'],
mounted () {
this.renderChart(this.chartData, this.options)
var elements = 1
}
}
I ran a test on this code and it worked perfectly.
<line-chart :chartData="myChartData"></line-chart>
However, when I attempted to render the chart dynamically, it didn't work.
import lineChart from './MainChart';
// ...
let chartClass = Vue.extend(lineChart)
let chartInstance = new chartClass({
propsData: {
chartData: myChartData
}
})
chartInstance.$mount()
console.log(chartInstance.$el)
console.log(chartInstance.$el.querySelector("canvas").toDataURL('image/png'))
console.log(chartInstance.$refs.canvas)
console.log(chartInstance.$refs.canvas.toDataURL('image/png'))
When checking the console messages, I noticed that nothing was being drawn in the canvas area.
How can I go about rendering my chart dynamically?
For more information, please refer to these related questions:
- Is it possible to print a chart with vue-chartjs?