Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions packages/web/src/components/Echarts-plus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const props = defineProps({
const echartsRef = ref(null);
const myChart = ref(null);

const refresh = debounce(() => {
const initChart = () => {
if (!echartsRef.value) return;

if (myChart.value) {
myChart.value.dispose();
}
Expand All @@ -30,38 +32,23 @@ const refresh = debounce(() => {
myChart.value.setOption(props.options);
}
if (props.onClick) {
myChart.value.off('click');
myChart.value.on('click', (params) => {
props.onClick(params, myChart.value);
});
}
}, 10);
};

const resizeObserver = new ResizeObserver(() => {
requestAnimationFrame(() => {
refresh();
});
});
const refresh = debounce(initChart, 10);

const resizeObserver = new ResizeObserver(refresh);

const currentName = ref();

watchEffect(() => {
const options = props.options;
nextTick(() => {
if (myChart.value) {
myChart.value.dispose();
}
myChart.value = echarts.init(echartsRef.value);
if (props.options) {
myChart.value.setOption(props.options);
}

if (props.onClick) {
myChart.value.off('click');
myChart.value.on('click', (params) => {
props.onClick(params, myChart.value);
});
}
});
props.options;
props.onClick;
nextTick(initChart);
});

onMounted(() => {
Expand Down
Loading