Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Laurettaaa opened this issue Oct 24, 2024 · 1 comment
Open

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

Laurettaaa opened this issue Oct 24, 2024 · 1 comment

Comments

@Laurettaaa
Copy link

问题描述

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

重现链接

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]

屏幕截图或视频(可选)

企业微信截图_399bbfe1-a496-40b1-916b-fdadf629d351

补充说明(可选)

No response

@hustcc
Copy link
Member

hustcc commented Nov 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@hustcc @Laurettaaa and others