2023-02-28 08:29:30 +00:00
|
|
|
<template>
|
|
|
|
<DocSectionText v-bind="$attrs">
|
|
|
|
<p>
|
|
|
|
A chart is configured with 3 properties; <i>type</i>, <i>data</i> and <i>options</i>. Chart type is defined using the <i>type</i> property that accepts <i>pie</i>, <i>doughtnut</i>, <i>line</i>, <i>bar</i>, <i>radar</i> and
|
|
|
|
<i>polarArea</i> as a value. The <i>data</i> defines datasets represented with the chart and the <i>options</i> provide numerous customization options to customize the presentation.
|
|
|
|
</p>
|
|
|
|
</DocSectionText>
|
|
|
|
<div class="card">
|
|
|
|
<Chart type="bar" :data="chartData" :options="chartOptions" />
|
|
|
|
</div>
|
|
|
|
<DocSectionCode :code="code" :dependencies="{ 'chart.js': '3.3.2' }" component="Chart" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-10-13 20:06:19 +00:00
|
|
|
import EventBus from '@/layouts/AppEventBus';
|
|
|
|
|
2023-02-28 08:29:30 +00:00
|
|
|
export default {
|
2023-10-13 20:06:19 +00:00
|
|
|
themeChangeListener: null,
|
2023-02-28 08:29:30 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2023-10-13 19:52:02 +00:00
|
|
|
chartData: null,
|
|
|
|
chartOptions: null,
|
2023-02-28 08:29:30 +00:00
|
|
|
code: {
|
2023-09-22 12:54:14 +00:00
|
|
|
basic: `
|
2023-10-15 09:38:39 +00:00
|
|
|
<Chart type="bar" :data="chartData" :options="chartOptions" />
|
|
|
|
`,
|
2023-09-22 12:54:14 +00:00
|
|
|
options: `
|
|
|
|
<template>
|
2023-02-28 08:29:30 +00:00
|
|
|
<div class="card">
|
|
|
|
<Chart type="bar" :data="chartData" :options="chartOptions" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2023-10-13 19:52:02 +00:00
|
|
|
chartData: null,
|
|
|
|
chartOptions: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.chartData = this.setChartData();
|
|
|
|
this.chartOptions = this.setChartOptions();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setChartData() {
|
|
|
|
return {
|
2023-02-28 08:29:30 +00:00
|
|
|
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: 'Sales',
|
|
|
|
data: [540, 325, 702, 620],
|
|
|
|
backgroundColor: ['rgba(255, 159, 64, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(153, 102, 255, 0.2)'],
|
|
|
|
borderColor: ['rgb(255, 159, 64)', 'rgb(75, 192, 192)', 'rgb(54, 162, 235)', 'rgb(153, 102, 255)'],
|
|
|
|
borderWidth: 1
|
|
|
|
}
|
|
|
|
]
|
2023-10-13 19:52:02 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
setChartOptions() {
|
|
|
|
const documentStyle = getComputedStyle(document.documentElement);
|
|
|
|
const textColor = documentStyle.getPropertyValue('--text-color');
|
|
|
|
const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary');
|
|
|
|
const surfaceBorder = documentStyle.getPropertyValue('--surface-border');
|
|
|
|
|
|
|
|
return {
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
labels: {
|
|
|
|
color: textColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-02-28 08:29:30 +00:00
|
|
|
scales: {
|
2023-10-13 19:52:02 +00:00
|
|
|
x: {
|
|
|
|
ticks: {
|
|
|
|
color: textColorSecondary
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
color: surfaceBorder
|
|
|
|
}
|
|
|
|
},
|
2023-02-28 08:29:30 +00:00
|
|
|
y: {
|
2023-10-13 19:52:02 +00:00
|
|
|
beginAtZero: true,
|
|
|
|
ticks: {
|
|
|
|
color: textColorSecondary
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
color: surfaceBorder
|
|
|
|
}
|
2023-02-28 08:29:30 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-13 19:52:02 +00:00
|
|
|
};
|
|
|
|
}
|
2023-02-28 08:29:30 +00:00
|
|
|
}
|
|
|
|
};
|
2023-10-15 09:38:39 +00:00
|
|
|
<\/script>
|
|
|
|
`,
|
2023-09-22 12:54:14 +00:00
|
|
|
composition: `
|
|
|
|
<template>
|
2023-02-28 08:29:30 +00:00
|
|
|
<div class="card">
|
|
|
|
<Chart type="bar" :data="chartData" :options="chartOptions" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2023-10-13 19:52:02 +00:00
|
|
|
import { ref, onMounted } from "vue";
|
2023-02-28 08:29:30 +00:00
|
|
|
|
2023-10-13 19:52:02 +00:00
|
|
|
onMounted(() => {
|
|
|
|
chartData.value = setChartData();
|
|
|
|
chartOptions.value = setChartOptions();
|
2023-02-28 08:29:30 +00:00
|
|
|
});
|
2023-10-13 19:52:02 +00:00
|
|
|
|
|
|
|
const chartData = ref();
|
|
|
|
const chartOptions = ref();
|
|
|
|
|
|
|
|
const setChartData = () => {
|
|
|
|
return {
|
|
|
|
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: 'Sales',
|
|
|
|
data: [540, 325, 702, 620],
|
|
|
|
backgroundColor: ['rgba(255, 159, 64, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(153, 102, 255, 0.2)'],
|
|
|
|
borderColor: ['rgb(255, 159, 64)', 'rgb(75, 192, 192)', 'rgb(54, 162, 235)', 'rgb(153, 102, 255)'],
|
|
|
|
borderWidth: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const setChartOptions = () => {
|
|
|
|
const documentStyle = getComputedStyle(document.documentElement);
|
|
|
|
const textColor = documentStyle.getPropertyValue('--text-color');
|
|
|
|
const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary');
|
|
|
|
const surfaceBorder = documentStyle.getPropertyValue('--surface-border');
|
|
|
|
|
|
|
|
return {
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
labels: {
|
|
|
|
color: textColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
ticks: {
|
|
|
|
color: textColorSecondary
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
color: surfaceBorder
|
|
|
|
}
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
beginAtZero: true,
|
|
|
|
ticks: {
|
|
|
|
color: textColorSecondary
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
color: surfaceBorder
|
|
|
|
}
|
|
|
|
}
|
2023-02-28 08:29:30 +00:00
|
|
|
}
|
2023-10-13 19:52:02 +00:00
|
|
|
};
|
|
|
|
}
|
2023-10-15 09:38:39 +00:00
|
|
|
<\/script>
|
|
|
|
`
|
2023-02-28 08:29:30 +00:00
|
|
|
}
|
|
|
|
};
|
2023-10-13 19:52:02 +00:00
|
|
|
},
|
2023-10-13 20:06:19 +00:00
|
|
|
beforeUnmount() {
|
|
|
|
EventBus.off('theme-change-complete', this.themeChangeListener);
|
|
|
|
},
|
2023-10-13 19:52:02 +00:00
|
|
|
mounted() {
|
|
|
|
this.chartData = this.setChartData();
|
|
|
|
this.chartOptions = this.setChartOptions();
|
2023-10-13 20:06:19 +00:00
|
|
|
|
|
|
|
this.themeChangeListener = () => {
|
|
|
|
this.chartOptions = this.setChartOptions();
|
|
|
|
};
|
|
|
|
|
|
|
|
EventBus.on('theme-change-complete', this.themeChangeListener);
|
2023-10-13 19:52:02 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setChartData() {
|
|
|
|
return {
|
|
|
|
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
|
|
|
|
datasets: [
|
|
|
|
{
|
|
|
|
label: 'Sales',
|
|
|
|
data: [540, 325, 702, 620],
|
|
|
|
backgroundColor: ['rgba(255, 159, 64, 0.2)', 'rgba(75, 192, 192, 0.2)', 'rgba(54, 162, 235, 0.2)', 'rgba(153, 102, 255, 0.2)'],
|
|
|
|
borderColor: ['rgb(255, 159, 64)', 'rgb(75, 192, 192)', 'rgb(54, 162, 235)', 'rgb(153, 102, 255)'],
|
|
|
|
borderWidth: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
|
|
|
setChartOptions() {
|
|
|
|
const documentStyle = getComputedStyle(document.documentElement);
|
|
|
|
const textColor = documentStyle.getPropertyValue('--text-color');
|
|
|
|
const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary');
|
|
|
|
const surfaceBorder = documentStyle.getPropertyValue('--surface-border');
|
|
|
|
|
|
|
|
return {
|
|
|
|
plugins: {
|
|
|
|
legend: {
|
|
|
|
labels: {
|
|
|
|
color: textColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
x: {
|
|
|
|
ticks: {
|
|
|
|
color: textColorSecondary
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
color: surfaceBorder
|
|
|
|
}
|
|
|
|
},
|
|
|
|
y: {
|
|
|
|
beginAtZero: true,
|
|
|
|
ticks: {
|
|
|
|
color: textColorSecondary
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
color: surfaceBorder
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-02-28 08:29:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|