Skip to content

[charts][docs] Charts Legend does not have ability to customize by individual legend item #15560

@MMShep97

Description

@MMShep97

Related page

https://mui.com/x/react-charts/legend/

Kind of issue

Missing information

Issue description

Hi there! Not sure if this is just a docs update for someone who couldn't figure out the advanced case, or actually a feature request. Thanks in advance!

Here is a link to a reproduction of my current code (has many commented lines of attempts :P)

Legend does not have the ability to customize individual legend items -- specific aim is to make the legend a dotted line just like the line on the graph. I know you can customize every item the same, like in these docs, but not individual pieces. See the image below for the expected/wanted functionality:

image

Attempts at a solution:

  • using slotProps, slots, both on the individual LineGraph, and also composing with ChartContainer and ChartsLegend -- there might be a solution there, but I couldn't quite figure it out. I kept thinking I could get to the solution with slotsProps.legend.seriesToDisplay and customizing the individual items that way, but the props on that aren't customizable enough. CSS also doesn't have css class customizability down to the series like line graphs do (example ['.MuiLineElement-series-{specific series id}']: { strokeDasharray: '10 5', ...plus some other svg modifiers},
  • using <ChartsLegendItem /> (even though it's an 'internal component', this might work, but it's obviously not the correct solution)

Context

image

what I have

vs.

image
what I want

As the line for five year average is dotted, I would like the legend for it to also be dotted. The more general want I suppose is to have the ability to customize each individual legend item.

Search keywords: legend itemMark mark series dotted strokeDasharray charts chart

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions