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

🐛[BUG]带辅助框标注的基础柱状图 动态添加数据时,第二次添加时报错 #2531

Open
2239351258 opened this issue May 6, 2024 · 1 comment

Comments

@2239351258
Copy link

🐛 bug 描述 [详细地描述 bug,让大家都能理解]

在官方案例‘带辅助框标注的基础柱状图’中,动态添加数据时,第二次添加时报错

📷 复现步骤 [清晰描述复现步骤,让别人也能看到问题]

将下面的代码粘贴至官方案例的“带辅助框标注的基础柱状图"中

🏞 期望结果 [描述你原本期望看到的结果]

第二次点击时,正确渲染出柱状图

💻 复现代码 [提供可复现的代码,仓库,或线上示例]

import { Column } from '@ant-design/plots';
import React,{useState} from 'react';
import ReactDOM from 'react-dom';

const data = [
  { month: '1', value: 178 },
  { month: '2', value: 126 },
  { month: '3', value: 78 },
  { month: '4', value: 623 },
  { month: '5', value: 319 },
  { month: '6', value: 422 },
  { month: '7', value: -4 },
  { month: '8', value: -217 },
  { month: '9', value: -358 },
  { month: '10', value: 1513 },
  { month: '11', value: 1388 },
  { month: '12', value: 597 },
];
 
let i=12
const DemoColumn = () => {
  const config1 = {
    data,
    xField: 'month',
    yField: 'value',
    scale: {
      y: {
        domainMax: 2000,
        domainMin: -1000,
      },
    },
    axis: {
      x: {
        labelFormatter: (val) => `${val} 月`,
      },
    },
    annotations: [
      {
        type: 'rangeX',
        data: [{ month: ['7', '9'] }],
        xField: 'month',
      },
    ],
  };
  const [config,setconfig]=useState(config1)
  const click = ()=>{
    i=i+1
    console.log(`i=${i}`)
    setconfig({...config,data:[...config.data,{month:`${i}`,value:12}]})
  }
 
  return <>
  <button onClick={click}>添加一条数据</button>
  <Column {...config} />
  </>;
};

ReactDOM.render(<DemoColumn />, document.getElementById('container'));

© 版本信息

  • ant-design-charts 版本: 2.0.0
  • 浏览器环境 Chrome
  • 开发环境 [e.g. mac OS]

🚑 其他信息 [如截图等其他信息可以贴在这里]

报错信息
错误信息

@lxfu1
Copy link
Member

lxfu1 commented May 7, 2024

先改为 setState(data) 跳过一下,后续修复

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

2 participants