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

🧐[问题] Multiline chart doesn't render the legend #2728

Open
dominon12 opened this issue Oct 8, 2024 · 0 comments
Open

🧐[问题] Multiline chart doesn't render the legend #2728

dominon12 opened this issue Oct 8, 2024 · 0 comments

Comments

@dominon12
Copy link

🧐 问题描述 [详细地描述问题,让大家都能理解]

Legend doesn't appear in a Line chart with multiple Line children. Also tooltip doesn't render correct text.

💻 示例代码 [如果有必要,展示代码,线上示例,或仓库]

Abstracted component:

import dynamic from 'next/dynamic';
import { chartColors } from 'config/colors';

const Line = dynamic(
  () => import('@ant-design/plots').then(({ Line }) => Line),
  { ssr: false }
);


function MultiLineChart(props) {
  const { xField, yFields, data, height, axis } = props;

  const config = {
      data,
      xField,
      legend: true,
      children: yFields.map((yField, index) => ({
        type: 'line',
        yField,
        style: {
          stroke: chartColors[index] ?? chartColors[0],
          lineWidth: 2,
        },
      }))
    };

  return <Line {...config} />;
}

Usage:

function App() {
  const data = [
    { date: 'April', x: 55, y: 17 },
    { date: 'May', x: 43, y: 26 },
    { date: 'June', x: 70, y: 53 },
    { date: 'July', x: 96, y: 68 },
  ];

  return <MultiLineChart data={data} xField="date" yFields={["x", "y"]} />;
}

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

Result:

image

I expect this kind of legend to appear:

image

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

1 participant