Charts
Chart components are wrappers over Vue Chart.js (opens new window) library and enhanced visually to look inline with the dashboard style.
Initialization:
// Charts
import * as chartConfigs from '@/components/Charts/config';
import LineChart from '@/components/Charts/LineChart';
import BarChart from '@/components/Charts/BarChart';
export default {
components: {
LineChart,
BarChart
}
}
Line Chart example
Overview
Sales value
Updating charts
A common use case is the one where you need to update the chart data in real time. Although this is pretty easy to do, there are some nuances to it, due to certain limitations around change detections in Vue.js (opens new window) and Vue Chart.js (opens new window).
In order to update charts, you'll have to re-assign the whole chartData
, otherwise the changes
::: tip DO
<line-chart :chart-data="myChartData"></line-chart>
<script>
export default {
data() {
return {
myChartData: {
datasets: [
{
label: 'Performance',
data: [0, 20, 10, 30, 15, 40, 20, 60, 60],
}
],
labels: ['May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
}
}
},
methods: {
updateChart() {
this.myChartData = {
datasets: [
{
label: 'Performance',
data: [10, 20, 10, 30, 15, 40, 20, 60, 60],
}
],
labels: ['May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
}
}
}
}
</script>
:::
::: danger DON'T
<line-chart :chart-data="myChartData"></line-chart>
<script>
export default {
data() {
return {
myChartData: null
}
},
methods: {
updateChart() {
this.myChartData.datasets[0] = 10
}
}
}
</script>
:::
Although second option is more convinient it won't work and the chart won't update.
Another easy option is to clone the original values, update them, then re-assign your chartData
Bar Chart
Performance
Total orders
LineChart Props
BarChart Props
PieChart Props
DoughnutChart Props
← Tooltips Datepicker →