Answer the question
In order to leave comments, you need to log in
Which vue plotting plugin is the most flexible and simple?
Good day. What plugin would you recommend besides vue-chartjs?
Answer the question
In order to leave comments, you need to log in
Just a week ago I integrated chart.js without a plugin. There is a great method there: update. When changing props, call chart.update in watch.
Dataset as a computed property and, when props changed, the dataset was updated using chart.update
Here is a piece straight from the component:
<template>
<div class="chart">
<canvas ref="canvas"></canvas>
</div>
</template>
<script>
import Chart from 'chart.js/dist/chart.js';
export default {
name: 'Chart',
props: {
actions: {
type: Array,
// ...
}
},
computed: {
ctx(){
return this.$refs?.canvas?.getContext('2d');
}
},
watch: {
actions(){
const points = calculePoints.call(this);
this.chart.data.labels = points;
this.chart.data.datasets[0] = {
label: '',
data: /* ... */,
backgroundColor: /* ... */,
borderColor: /* ... */,
borderWidth: 3
};
this.chart.update();
}
},
mounted(){
this.chart = new Chart(this.ctx, {
type: 'line',
data: {
labels: //...,
datasets: [{
label: '',
data: /* ... */,
backgroundColor: /* ... */,
borderColor: [/* ... */],
borderWidth: 3
}]
},
options: { /* ... */ }
});
}
}
</script>
I started amcharts.js for a vue project, which required several dozens of the most diverse charts, and I am very pleased with how everything turned out in the end both visually and in terms of speed.
But, of course, IMHO.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question