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] Use real world data for ScatterChart examples #14333

Closed
wants to merge 10 commits into from

Conversation

JCQuintas
Copy link
Member

@JCQuintas JCQuintas commented Aug 25, 2024

Added multiple dataset examples, just to try some things out.

I tried to find more interesting datasets, but it's hard to find data that creates nice visualisations 😅

The two best are Life expectancy vs. GDP per capita and an adaptation of Hertzsprung–Russell diagram, which plot stars.

Issues

A recurring issue is that the Scatter chart doesn't support the dataset, which makes it required for us to construct the data as the Scatter chart expects it, which is annoying and time-consuming.

A possibility would be to allow the dataset to be used on scatter charts. We can then ask users to provide a dataKey for x and y axis, as well as some way of filtering the data for sets, eg:

export const lifeExpectancyVsGdpPerCapita = [
  {
    name: 'Afghanistan',
    code: 'AFG',
    lifeExpectancyAtBirth: 62.6587,
    gdpPerCapita: 1928,
    year: 2015,
    continent: 'Asia',
  },
  {
    name: 'Albania',
    code: 'ALB',
    lifeExpectancyAtBirth: 78.6441,
    gdpPerCapita: 10192.529,
    year: 2015,
    continent: 'Europe',
  },
]

<ScatterChart
  height={300}
  yAxis={[{ 
    label: 'Life expectancy at birth',
    dataKey: 'lifeExpectancyAtBirth'
  }]}
  xAxis={[{ 
    scaleType: 'log',label: 'GDP per capita',
    dataKey: 'gdpPerCapita'
  }]}
  dataset={lifeExpectancyVsGdpPerCapita}
  series={[
    {
      label: "Asia",
      dataFilter: (v) => v.continent === 'Asia'
    },
    {
      label: "Europe"
      dataFilter: (v) => v.continent === 'Asia'
    },
  ]}
/>

Examples

https://deploy-preview-14333--material-ui-x.netlify.app/x/react-charts/scatter/#interaction

screencapture-localhost-3001-x-react-charts-scatter-2024-08-25-20_53_32

@JCQuintas JCQuintas self-assigned this Aug 25, 2024
@JCQuintas JCQuintas added docs Improvements or additions to the documentation component: charts This is the name of the generic UI component, not the React module! labels Aug 25, 2024
@mui-bot
Copy link

mui-bot commented Aug 25, 2024

Deploy preview: https://deploy-preview-14333--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 7b75242

Copy link

codspeed-hq bot commented Aug 25, 2024

CodSpeed Performance Report

Merging #14333 will not alter performance

Comparing JCQuintas:scatter-chart-real-dataset (7b75242) with master (309199a)

Summary

✅ 3 untouched benchmarks

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! docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants