Skip to content

Commit b4ec95e

Browse files
committedDec 10, 2023
fix: echarts can't get dom size
1 parent d79ab04 commit b4ec95e

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed
 

‎frontend/src/views/admin/components/charts/AskChart.vue

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="pr-4">
3-
<v-chart class="h-100" :option="option" :loading="props.loading" />
3+
<v-chart ref="chartRef" class="h-100" :option="option" :loading="props.loading" />
44
</div>
55
</template>
66

@@ -19,7 +19,7 @@ import {
1919
} from 'echarts/components';
2020
import { use } from 'echarts/core';
2121
import { CanvasRenderer } from 'echarts/renderers';
22-
import { computed, ref } from 'vue';
22+
import { computed, onMounted, ref } from 'vue';
2323
import VChart from 'vue-echarts';
2424
import { useI18n } from 'vue-i18n';
2525
@@ -43,6 +43,8 @@ use([
4343
BrushComponent,
4444
]);
4545
46+
const chartRef = ref<InstanceType<typeof VChart>>();
47+
4648
const props = defineProps<{
4749
loading: boolean;
4850
askStats: AskLogAggregation[];
@@ -343,12 +345,7 @@ const option = computed<EChartsOption>(() => {
343345
} as EChartsOption;
344346
});
345347
346-
// watchEffect(() => {
347-
console.log('props', props.askStats);
348-
// console.log('xAxis', xAxis.value);
349-
// console.log('totalRequestsCountData', totalRequestsCountData.value);
350-
// console.log('datasetSource', datasetSource.value);
351-
// console.log('users', props.users)
352-
// console.log('option', option.value);
353-
// });
348+
onMounted(() => {
349+
chartRef.value?.resize();
350+
});
354351
</script>

‎frontend/src/views/admin/components/charts/RequestsChart.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="pr-4">
3-
<v-chart class="h-35" :option="option" :loading="props.loading" />
3+
<v-chart ref="chartRef" class="h-35" :option="option" :loading="props.loading" />
44
</div>
55
</template>
66

@@ -20,7 +20,7 @@ import {
2020
} from 'echarts/components';
2121
import { use } from 'echarts/core';
2222
import { CanvasRenderer } from 'echarts/renderers';
23-
import { computed, ref, watchEffect } from 'vue';
23+
import { computed, onMounted, ref, watchEffect } from 'vue';
2424
import VChart from 'vue-echarts';
2525
import { useI18n } from 'vue-i18n';
2626
@@ -55,6 +55,8 @@ const props = defineProps<{
5555
users?: UserRead[];
5656
}>();
5757
58+
const chartRef = ref<InstanceType<typeof VChart>>();
59+
5860
const findUsername = (user_id: number) => {
5961
const user = props.users?.find((u) => u.id === user_id);
6062
return user?.username || user_id;
@@ -278,4 +280,8 @@ watchEffect(() => {
278280
// console.log('users', props.users)
279281
console.log('option', option.value);
280282
});
283+
284+
onMounted(() => {
285+
chartRef.value?.resize();
286+
});
281287
</script>

0 commit comments

Comments
 (0)
Failed to load comments.