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] Add data label for line charts & area charts #14605

Open
alexbalonperin opened this issue Sep 13, 2024 · 7 comments
Open

[charts] Add data label for line charts & area charts #14605

alexbalonperin opened this issue Sep 13, 2024 · 7 comments
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 new feature New feature or request

Comments

@alexbalonperin
Copy link

alexbalonperin commented Sep 13, 2024

Summary

First of all, thank you so much for the great library. Looking at many alternatives, I was quite impressed with the design of the components' interface and how easy it is to create charts with multiple series and multiple axis with their own formatters.

This request is the Line/Area Chart version of #12331

I have searched through Github issues, the API references and the code but couldn't find a way to show data labels on line & area charts. I apologize in advance if have missed just missed the feature. The closest thing that I found was the LineSeriesType which has a showMark attribute that can be a function accepting ShowMarkParams. This looked promising as ShowMarkParams has the item value but the function returns a boolean.

Please advise if this is possible and if so, some pointer would be very helpful.

Examples

Equivalent in Recharts:
Screenshot from 2024-09-12 23-09-39

Motivation

I believe that this is a fairly standard feature of charts and that one that we offer at the moment with ChartJS. However, as we are building more and more complex charts and we already use Material UI for all our components, it makes sense to use MUI/x-charts instead. We need to have at least the same level of feature support as the current version of our application and as far as my research goes, this is the only missing piece in MUI/x-charts.

Search keywords: line chart data label

@alexbalonperin alexbalonperin added new feature New feature or request status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 13, 2024
@alexfauquette
Copy link
Member

alexfauquette commented Sep 13, 2024

It looks feasible with the slots.mark sinc e it provides the x, y, coordinate of the circle and the `datatIndex. From those information you will have to retrieve the value you want to display, and then plot the circle and the text.

https://codesandbox.io/p/sandbox/adoring-water-lrzsn3?file=%2Fsrc%2FDemo.tsx%3A55%2C23

image

It works, but might need some refinement

@alexbalonperin
Copy link
Author

Nice. Thank you for the quick reply and the sandbox! I'll give it a try. 💯

@alexbalonperin
Copy link
Author

Do you think this could become a more standard feature in mui-x similar to barLabel?

@alexfauquette
Copy link
Member

Do you think this could become a more standard feature in mui-x similar to barLabel?

I would be more in favor of a useLineMark that would return the needed data and let the user do his own label component

@michelengelen michelengelen added status: waiting for author Issue with insufficient information enhancement This is not a bug, nor a new feature component: charts This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer status: waiting for author Issue with insufficient information labels Sep 13, 2024
@michelengelen
Copy link
Member

@alexfauquette added to the board to track this issue.

@alexbalonperin
Copy link
Author

Thank you for your reply.
Should I close the issue as resolved since there is a work around and potential enhancement in the future?

@alexfauquette
Copy link
Member

Should I close the issue as resolved

No, we keep issues open up until we have a proper fix. This issue will allow us to track we need to improve this aspect of the charts

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 new feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants