primevue-mirror/apps/showcase/doc/chart/pt/PTViewer.vue

92 lines
2.9 KiB
Vue
Raw Normal View History

2024-09-17 12:21:10 +00:00
<template>
2024-09-20 12:22:44 +00:00
<DocPTViewer :docs="docs">
2024-09-17 12:21:10 +00:00
<Chart type="bar" :data="chartData" :options="chartOptions" />
</DocPTViewer>
</template>
<script>
import { getPTOptions } from '@/components/doc/helpers';
import EventBus from '@/layouts/AppEventBus';
export default {
data() {
return {
chartData: null,
chartOptions: null,
2024-09-20 12:22:44 +00:00
docs: [
2024-09-17 12:21:10 +00:00
{
data: getPTOptions('Chart'),
key: 'Chart'
}
]
};
},
beforeUnmount() {
EventBus.off('dark-mode-toggle-complete', this.redrawListener);
EventBus.off('theme-palette-change', this.redrawListener);
},
mounted() {
this.chartData = this.setChartData();
this.chartOptions = this.setChartOptions();
this.redrawListener = () => {
this.chartOptions = this.setChartOptions();
};
EventBus.on('theme-palette-change', this.redrawListener);
EventBus.on('dark-mode-toggle-complete', this.redrawListener);
},
methods: {
setChartData() {
return {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [
{
label: 'Sales',
data: [540, 325, 702, 620],
backgroundColor: ['rgba(249, 115, 22, 0.2)', 'rgba(6, 182, 212, 0.2)', 'rgb(107, 114, 128, 0.2)', 'rgba(139, 92, 246, 0.2)'],
borderColor: ['rgb(249, 115, 22)', 'rgb(6, 182, 212)', 'rgb(107, 114, 128)', 'rgb(139, 92, 246)'],
borderWidth: 1
}
]
};
},
setChartOptions() {
const documentStyle = getComputedStyle(document.documentElement);
const textColor = documentStyle.getPropertyValue('--p-text-color');
const textColorSecondary = documentStyle.getPropertyValue('--p-text-muted-color');
const surfaceBorder = documentStyle.getPropertyValue('--p-content-border-color');
return {
plugins: {
legend: {
labels: {
color: textColor
}
}
},
scales: {
x: {
ticks: {
color: textColorSecondary
},
grid: {
color: surfaceBorder
}
},
y: {
beginAtZero: true,
ticks: {
color: textColorSecondary
},
grid: {
color: surfaceBorder
}
}
}
};
}
}
};
</script>