primevue-mirror/pages/chart/Pie.vue

85 lines
2.3 KiB
Vue
Executable File

<template>
<div>
<div class="content-section introduction">
<div class="feature-intro">
<h1>Pie Chart</h1>
<p>A pie chart is a circular statistical graphic, which is divided into slices to illustrate numerical proportion.</p>
</div>
<AppDemoActions />
</div>
<div class="content-section implementation">
<div class="card flex justify-content-center">
<Chart type="pie" :data="chartData" :options="chartOptions" style="width: 40%" />
</div>
</div>
<PieChartDoc />
</div>
</template>
<script>
import EventBus from '@/layouts/AppEventBus';
import PieChartDoc from './PieChartDoc';
export default {
themeChangeListener: null,
data() {
return {
chartData: {
labels: ['A', 'B', 'C'],
datasets: [
{
data: [300, 50, 100],
backgroundColor: ['#42A5F5', '#66BB6A', '#FFA726'],
hoverBackgroundColor: ['#64B5F6', '#81C784', '#FFB74D']
}
]
},
chartOptions: this.isDarkTheme() ? this.getDarkTheme() : this.getLightTheme()
};
},
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);
},
methods: {
isDarkTheme() {
return this.$appState.darkTheme === true;
},
getLightTheme() {
return {
plugins: {
legend: {
labels: {
color: '#495057'
}
}
}
};
},
getDarkTheme() {
return {
plugins: {
legend: {
labels: {
color: '#ebedef'
}
}
}
};
}
},
components: {
PieChartDoc: PieChartDoc
}
};
</script>