TransFlow/node_modules/vue-schart/src/vue-schart.vue

52 lines
1.1 KiB
Vue

<template>
<div>
<canvas :id="canvasId"></canvas>
</div>
</template>
<script>
import Schart from "schart.js";
export default {
props: {
canvasId: {
type: String,
default: "",
required: true
},
options: {
type: Object,
required: true
}
},
mounted() {
this.renderChart();
},
methods: {
renderChart() {
if (!this.checkOptions()) {
return;
}
const opt = { ...this.options };
new Schart(this.canvasId, opt);
},
checkOptions() {
const opt = this.options;
if (!opt.datasets || !opt.datasets.length) {
return false;
}
if (!opt.labels || !opt.labels.length) {
return false;
}
return true;
}
},
watch: {
options: {
handler(newValue, oldValue) {
this.renderChart();
},
deep: true
}
}
};
</script>