antvis/G2

复用面积图多次渲染填充色出现异常 #6507

Laurettaaa posted onGitHub

问题描述

封装了一个面积图组件,在单页面上多次渲染,会出现多个面积图同一个地方填色异常

重现链接

No response

重现步骤

<script setup>
import { Chart } from '@antv/g2';
import { stringify } from 'postcss';
import {onMounted, watch, ref} from "vue";

const props = defineProps({
  data: {
    type: Array,
    required: true
  },
})

let chart;
const container = ref(null);

onMounted(() => {
  chart = renderChart(container.value);
})

watch(() => props.data, () => {
  updateBarChart(chart, props.data);
});

const updateBarChart = (chart, data) => {
  const interval = chart.getNodesByType('interval')[0];

  interval.data(data);
  chart.render();
}

const renderChart = (container) => {
  const chart = new Chart({ container, autoFit: true });

  chart
    .data(props.data)
    // .area()
    .encode('x', 'date')
    .encode('y', 'value')
    .encode('color', 'type')
    .encode('shape', 'smooth')
    .axis('x', { title: false })
    .axis('y', { title: false })
    .scale('color', {
      relations: [
        ['instagram', '#df8cf8'], 
        ['twitter', '#fade98'], 
        ['tiktok', '#8b83f7'], 
        ['youtube', '#ef8d8a'], 
        ['facebook', '#a6fcf6'], 
        [(d) => d === undefined, 'grey'], 
      ],
    })
    .legend({
      color: {
        itemMarker: 'itemMarker',

      },
    })

    chart.area().style('fillOpacity', 0.4);
    chart.line().style('strokeWidth', 2).tooltip(false);  

  chart.render();

  return chart;
};

</script>
<template>
  <div ref="container" class="w-full h-[340px] my-sm"></div>
</template>

预期行为

No response

平台

  • 操作系统: [macOS]
  • 网页浏览器: [Google Chrome]

屏幕截图或视频(可选)

<img width="1483" alt="企业微信截图_399bbfe1-a496-40b1-916b-fdadf629d351" src="https://github.com/user-attachments/assets/9497ebe9-5f44-45ea-961d-6b63f9848c90">

补充说明(可选)

No response


哈喽,可以来一个在线可预览的地址方便调试吗?谢谢~ 是使用的这个 demo 案例吗?https://g2.antv.antgroup.com/examples/general/area/#orderly-area

posted by hustcc 6 months ago

⚠️ This issue has been automatically closed due to inactivity.

  • If the issue is still relevant and important to you, feel free to:
    1. Reopen with additional information
    2. Create a new issue with updated context
    3. Reference any related issues or discussions

We close inactive issues to keep our backlog manageable and focused on active issues.

Your contribution makes our project better! 🌟


⚠️ 由于长期无活动,此 issue 已被自动关闭。

  • 如果这个问题对您来说仍然重要,您可以:
    1. 重新打开并提供补充信息
    2. 创建一个新的 issue 并更新相关背景
    3. 关联相关的 issue 或讨论

为了更好地维护项目,我们需要定期清理不活跃的问题。

感谢您为开源添砖加瓦!🌟

posted by github-actions[bot] 23 days ago

Fund this Issue

$0.00
Funded

Pull requests