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 multiple Y axes to the left or right of the chart #16387

Open
prakhargupta1 opened this issue Jan 29, 2025 · 2 comments
Open

[charts] Add multiple Y axes to the left or right of the chart #16387

prakhargupta1 opened this issue Jan 29, 2025 · 2 comments
Labels
component: charts This is the name of the generic UI component, not the React module! new feature New feature or request support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@prakhargupta1
Copy link
Member

prakhargupta1 commented Jan 29, 2025

Summary

I would like to display multiple Y axes on the left or right side of the chart. Currently, LineChart has
leftAxis and rightAxis properties. There is not the ability to display more than one Y axis on the left or right and you can only display up to two Y axes (one on the left, one on the right).

Examples

https://www.highcharts.com/demo/highcharts/combo-multi-axes

https://apexcharts.com/react-chart-demos/mixed-charts/multiple-yaxis/#

Search keywords: multiple Y Axes

Order ID: 104043

@prakhargupta1 prakhargupta1 added component: charts This is the name of the generic UI component, not the React module! new feature New feature or request status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 29, 2025
@github-actions github-actions bot added the support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ label Jan 29, 2025
@michelengelen
Copy link
Member

Thanks for opening this feature request.
It makes sense to add this IMO, so I'll add it to the board.

maybe there is a way to add multiple axes with the current product as a workaround, @alexfauquette?

@michelengelen michelengelen changed the title [charts] Allow for multiple Y Axes that can be configurable to display on the left or right of the chart [charts] Add multiple Y axes to the left or right of the chart Jan 29, 2025
@michelengelen michelengelen removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 29, 2025
@alexfauquette
Copy link
Member

alexfauquette commented Jan 29, 2025

Yes, a workaround with composition is feasible.

The idea is to add extra margin on the side you want to put an additional axis. Then you can add an extra <ChartsYAxis /> with the axisId you want to display and place it where it looks best for you :)

The codesandbox is a bit buggy, so I also add the code here

import * as React from 'react';
import Box from '@mui/material/Box';
import { LineChart } from '@mui/x-charts/LineChart';
import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis'


const sample = [1, 10, 30, 50, 70, 90, 100];

export default function ScaleExample() {
  return (
    <Box sx={{ width: '100%', maxWidth: 500 }}>
      <LineChart
        xAxis={[{ data: sample }]}
        yAxis={[
          { label: 'linear (0 to 100)', id: 'linearAxis', scaleType: 'linear' },
          { label: 'linear (0 to 10)', id: 'linear2Axis', scaleType: 'linear', min: 0, max: 10 },
          { label: 'log', id: 'logAxis', scaleType: 'log' },
        ]}
        series={[
          { yAxisId: 'linear2Axis', data: sample.map(y => Math.sqrt(y)), label: 'sqrt' },
          { yAxisId: 'linearAxis', data: sample, label: 'linear' },
          { yAxisId: 'logAxis', data: sample, label: 'log' },
        ]}
        leftAxis="linearAxis"
        rightAxis="logAxis"
        margin={{ left: 150 }}
        height={400}
      >
        <ChartsYAxis axisId='linear2Axis' sx={{ transform: 'translateX(75px)' }} />
      </LineChart>
    </Box>
  );
}

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! new feature New feature or request support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

No branches or pull requests

3 participants