VisActor / VisActor/VChart

[Bug] 动态获取数据渲染词图显示有问题

Open
#4,327 3 comments 0 reactions 1 assignee View on GitHub

@xuefei1313 is already working on this.

Since Dec 2, 2025.

bug Vue-VChart
Dominant language
TypeScript
Stars
1.8k
Forks
221
Avg merge
1d 6h
Merged PRs (30d)
26

Description

Version

2.0.9

Link to Minimal Reproduction

动态获取数据渲染词图显示有问题

Steps to Reproduce
<template>
  <n-card
    :segmented="{ content: true }"
    :header-style="{ padding: 0 }"
    header-class="bg-gradient-to-b from-[#e8f4ff80] to-[#fff0]"
  >
    <template #header>
      <div class="px-20 py-15 text-md font-bold">热门词条</div>
    </template>
    <div ref="chartRef" class="w-full min-h-600"></div>
  </n-card>
</template>
<script lang="ts" setup>
import { VChart, type ISpec } from '@visactor/vchart';
const spec = {
  type: 'wordCloud',
  data: {
    id: 'wordCloud',
    name: 'baseData',
    values: [],
  },
  nameField: 'challenge_name',
  valueField: 'sum_count',
  seriesField: 'challenge_name',
  word: {
    formatMethod: (datum) => {
      return `${datum.challenge_name}...`;
    },
  },
} as ISpec;

const chartRef = ref<HTMLDivElement>();
const chartInstance = ref<VChart>();
const getData = () => {
  return fetch('https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/data-wordcloud.json').then(
    (response) => {
      return response.json();
    },
  );
};

onMounted(async () => {
  const el = chartRef.value;
  if (!el) return;
  chartInstance.value = new VChart(spec, { dom: el });
  chartInstance.value.renderAsync();
  setTimeout(async () => {
    const data: any[] = await getData();
    chartInstance.value?.updateData('wordCloud', data.slice(0, 30));
  }, 1000);
});
onBeforeUnmount(() => {
  chartInstance.value?.release();
});
</script>

渲染效果为:

Image 是我写的有问题吗?

Current Behavior
Image
Expected Behavior

希望能正常显示

Environment
- OS:
- Browser:
- Framework:
Any additional comments?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.