Charts
Chart components are wrappers over Vue Chart.js library and enhanced visually to look inline with the dashboard style.
Initialization:
// Charts
import * as chartConfigs from '@/components/argon-core/Charts/config';
import LineChart from '@/components/argon-core/Charts/LineChart';
import BarChart from '@/components/argon-core/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 and Vue Chart.js.
In order to update charts, you'll have to re-assign the whole
chartData
, otherwise the changes
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>
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