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

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