Files
vueecharts/demo/examples/PieChart.vue
Yue JIN 522dd7cc5c chore: ESLint Flat Config (#834)
* chore: eslint flat config

* chore: format

* update according to review

* chore: remove prettier config and format

* fix: move handler to script to bypass eslint

* chore: config eslint for lang=js block

* docs: add surrounding empty lines for code block

* chore: also minify css in csp build

* chore: publint
2025-08-10 23:22:04 +08:00

83 lines
1.5 KiB
Vue

<script setup>
import { use } from "echarts/core";
import { PieChart } from "echarts/charts";
import {
PolarComponent,
TitleComponent,
LegendComponent,
TooltipComponent,
} from "echarts/components";
import { shallowRef, onMounted, onUnmounted } from "vue";
import VChart from "../../src/ECharts";
import VExample from "./Example.vue";
import getData from "../data/pie";
use([
PieChart,
PolarComponent,
TitleComponent,
LegendComponent,
TooltipComponent,
]);
const option = shallowRef(getData());
const pie = shallowRef(null);
let timer = null;
onMounted(() => {
startActions();
});
onUnmounted(() => {
stopActions();
});
function startActions() {
let dataIndex = -1;
const dataLen = option.value?.series?.[0]?.data?.length || 0;
if (!pie.value || dataLen === 0) {
return;
}
clearInterval(timer);
timer = setInterval(() => {
if (!pie.value) {
clearInterval(timer);
return;
}
pie.value.dispatchAction({
type: "downplay",
seriesIndex: 0,
dataIndex,
});
dataIndex = (dataIndex + 1) % dataLen;
pie.value.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex,
});
pie.value.dispatchAction({
type: "showTip",
seriesIndex: 0,
dataIndex,
});
}, 1000);
}
function stopActions() {
clearInterval(timer);
}
</script>
<template>
<v-example id="pie" title="Pie chart" desc="(with action dispatch)">
<v-chart ref="pie" :option="option" autoresize />
</v-example>
</template>