primevue-mirror/pages/chart/Doughnut.vue

85 lines
2.4 KiB
Vue
Raw Normal View History

2022-09-09 20:41:18 +00:00
<template>
<div>
<div class="content-section introduction">
<div class="feature-intro">
<h1>DoughnutChart</h1>
<p>A doughnut chart is a variant of the pie chart, with a blank center allowing for additional information about the data as a whole to be included.</p>
</div>
<AppDemoActions />
</div>
<div class="content-section implementation">
<div class="card flex justify-content-center">
<Chart type="doughnut" :data="chartData" :options="chartOptions" style="width: 40%" />
</div>
</div>
<DoughnutChartDoc />
</div>
</template>
<script>
import EventBus from '@/layouts/AppEventBus';
2022-12-08 12:26:57 +00:00
import DoughnutChartDoc from './DoughnutChartDoc';
2022-09-09 20:41:18 +00:00
export default {
themeChangeListener: null,
data() {
return {
chartData: {
labels: ['A', 'B', 'C'],
datasets: [
{
data: [300, 50, 100],
backgroundColor: ['#FF6384', '#36A2EB', '#FFCE56'],
hoverBackgroundColor: ['#FF6384', '#36A2EB', '#FFCE56']
}
]
},
chartOptions: this.isDarkTheme() ? this.getDarkTheme() : this.getLightTheme()
};
},
2022-12-08 12:26:57 +00:00
mounted() {
this.themeChangeListener = (event) => {
if (event.dark) this.chartOptions = this.getDarkTheme();
else this.chartOptions = this.getLightTheme();
};
EventBus.on('theme-change', this.themeChangeListener);
},
beforeUnmount() {
EventBus.off('change-theme', this.themeChangeListener);
},
2022-09-09 20:41:18 +00:00
methods: {
isDarkTheme() {
return this.$appState.darkTheme === true;
},
getLightTheme() {
return {
plugins: {
legend: {
labels: {
color: '#495057'
}
}
}
};
},
getDarkTheme() {
return {
plugins: {
legend: {
labels: {
color: '#ebedef'
}
}
}
};
}
},
components: {
DoughnutChartDoc: DoughnutChartDoc
}
};
</script>