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

[charts] Allow to have specific labels in legends/tooltip #12482

Closed
youngmoon715 opened this issue Mar 18, 2024 · 3 comments · Fixed by #12830
Closed

[charts] Allow to have specific labels in legends/tooltip #12482

youngmoon715 opened this issue Mar 18, 2024 · 3 comments · Fixed by #12830
Assignees
Labels
component: charts This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature

Comments

@youngmoon715
Copy link

youngmoon715 commented Mar 18, 2024

Summary

Just like xAxis or yAxis, legend should also accept valueFormatter. Currently, I'm having to use a hack to use the slots for the legends to render a different legend label

Examples

import {ChartsLegend} from '@mui/x-charts';
import type {ChartsLegendProps} from '@mui/x-charts/ChartsLegend';

interface CustomLegendProps extends ChartsLegendProps {
  series: any;
  seriesToDisplay: any[];
}

const CustomLegend = ({
  seriesToDisplay,
  series,
  ...restProps
}: CustomLegendProps) => {
  const newSeriesToDisplay = seriesToDisplay?.map((item) => ({
    ...item,
    label: item.label === 'Duration' ? 'Duration (HH:MM:SS)' : item.label,
  }));
  const newSeries = Object.keys(series?.bar?.series).reduce(
    (acc, key) => {
      if (series?.bar?.series[key].label === 'Duration') {
        acc.bar.series[key].label = 'Duration (HH:MM:SS)';
      }
      return acc;
    },
    {...series} as any,
  );
  return (
    <ChartsLegend
      {...restProps}
      seriesToDisplay={newSeriesToDisplay}
      series={newSeries}
    />
  );
};

export default CustomLegend;

Motivation

make MUI more customizable.

Search keywords: custom, valueFormatter, legends, chart, charts, x-chart
Order ID: 81516

@youngmoon715 youngmoon715 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 18, 2024
@zannager zannager added the component: charts This is the name of the generic UI component, not the React module! label Mar 19, 2024
@alexfauquette
Copy link
Member

Is it about valueFormatter or is it about having multiple label options? Because the legend does not show any value for now.

I was considering having following series properties:

  • label
  • labelTooltip
  • labelLegend

@alexfauquette alexfauquette added enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 19, 2024
@youngmoon715
Copy link
Author

youngmoon715 commented Mar 19, 2024

Its being able to change the label that's displayed on the legend and the axis.
For example, on my Y Axis, i want it to say Duration
but for the legends, I want it to say Duration (HH:MM:SS)

I was considering having following series properties:

  • label
  • labelTooltip
  • labelLegend

Those suggestions sound great. Would love the flexibility on the Tooltips as well.

@alexfauquette alexfauquette changed the title [charts] Add valueFormatter to legends [charts] Allow to have specific labels in legends/tooltip Mar 28, 2024
Copy link

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@youngmoon715: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
None yet
4 participants