<template>
    <div>
        <canvas ref="chart" style="margin: auto"></canvas>
    </div>
</template>
<script>
import VueCharts from 'vue-chartjs'
import { Line, Bar } from 'vue-chartjs'
export default {
    name: 'lineBarChart',
    props: ['chartData', 'options', 'width', 'height', 'type'],
    watch: {
        chartData() {
            if (this.myChart) {
                this.myChart.update()
            }
            else {
                this.myChart = new Chart(this.$refs.chart.getContext('2d'), { type: this.type, data: this.chartData, options: this.options })
            }
        }
    },
    data() {
        return {
            myChart: null
        }
    },
    mounted() {
        console.log(this.type)
        if (this.chartData) {
            this.myChart = new Chart(this.$refs.chart.getContext('2d'), { type: this.type, data: this.chartData, options: this.options })
        }

    },
    methods: {
        updateChart() {
            this.myChart.update()
        }
    }
}
</script>
<style lang="less" scoped>
</style>
