-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] Helpers for Transforming Dataset Series #15832
Comments
@JCQuintas could you step in here? Thanks! 🙇🏼 |
Hi @aress31, indeed, this is something we have discussed before internally but isn't currently planned. Do you have suggestions on how an implementation would look like? |
@JCQuintas no idea sorry, but would be nice to see such helpers to make the charts plug and play. |
We could introduce a We could automatically parse with |
@alexfauquette, I will provide you with an example using the dataset below: [
{
"count": 1,
"created_at": "2024-12-09T03:18:26.859344+00:00"
},
{
"count": 1,
"created_at": "2024-12-11T10:37:59.602215+00:00"
},
{
"count": 1,
"created_at": "2024-12-09T03:20:05.259137+00:00"
},
{
"count": 1,
"created_at": "2024-12-09T06:34:33.092119+00:00"
},
{
"count": 1,
"created_at": "2024-12-09T03:17:32.97368+00:00"
},
{
"count": 1,
"created_at": "2024-12-09T03:20:14.916028+00:00"
},
{
"count": 10,
"created_at": "2024-12-07T03:39:50.844102+00:00"
},
{
"count": 1,
"created_at": "2024-12-09T06:33:54.326826+00:00"
},
{
"count": 1,
"created_at": "2024-12-09T06:34:26.344888+00:00"
},
{
"count": 1,
"created_at": "2024-12-09T04:16:14.825664+00:00"
}
] In a <LineChart {...commonProps} />
const commonProps = {
xAxis: [
{
min: dayjs(filterDate).toDate(),
dataKey: xAxis,
scaleType: chartType === "bar" ? "band" : "utc",
},
],
series: [{ dataKey: "count" }],
dataset: dataset.map(({ created_at, ...item }) => ({
...item,
created_at: dayjs(created_at).toDate(),
}))
}; The above configuration results in multiple lines (i.e., series), see: The goal here is to generate a single line showing the count change over time ( |
@aress31 In your example use case, the issue is that the time data is unordered. After sorting it, it seems to display the expected curve. https://codesandbox.io/embed/r6yh4h?module=/src/Demo.tsx&fontsize=12 |
@JCQuintas that is correct! It now works, thanks, but should not this sort be done at the Chart level when type is set to either |
Summary
Using charts often requires significant data transformation, which can be cumbersome and not very developer-friendly. Let me illustrate this with my current use case: I fetch data from a database, where the records (referred to as the dataset in MUI terminology) look like this:
From this dataset, I want to generate charts dynamically using any field as the xAxis or series key. Ideally, I’d like to do something like this:
However, because the chart components expect aggregated data (e.g., counts or other transformations), additional preprocessing of the dataset is required. This introduces unnecessary complexity and boilerplate code.
To simplify this, it would be helpful to expose utility functions for common transformations or, even better, to bake this functionality directly into the chart components for plug-and-play usability. This would significantly enhance developer experience and reduce repetitive tasks.
Examples
See above.
Motivation
See above.
Search keywords: series, chart, helper, aggregate
The text was updated successfully, but these errors were encountered: