<template>
  <div>
    <h2>饼状图示例</h2>
    <PieChart :chartData="chartData" />
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue';
import { Pie } from 'vue-chartjs';
import {
  Chart as ChartJS,
  Title,
  Tooltip,
  Legend,
  ArcElement,
} from 'chart.js';


ChartJS.register(Title, Tooltip, Legend, ArcElement);

export default defineComponent({
  components: {
    PieChart: Pie,
  },
  setup() {
    const chartData = ref({
      labels: ['红色', '蓝色', '黄色', '绿色', '紫色', '橙色'],
      datasets: [
        {
          label: '我的饼状图',
          backgroundColor: [
            '#FF6384',
            '#36A2EB',
            '#FFCE56',
            '#4BC0C0',
            '#9966FF',
            '#FF9F40',
          ],
          data: [12, 19, 3, 5, 2, 3],
        },
      ],
    });

    return {
      chartData,
    };
  },
});
</script>

<style scoped>
h2 {
  text-align: center;
}
</style>
