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] LineChart have only MuiChartsAxis-right and not left #14817

Closed
DonikaV opened this issue Oct 3, 2024 · 9 comments
Closed

[charts] LineChart have only MuiChartsAxis-right and not left #14817

DonikaV opened this issue Oct 3, 2024 · 9 comments
Labels
component: charts This is the name of the generic UI component, not the React module! customization: extend Logic customizability status: waiting for author Issue with insufficient information

Comments

@DonikaV
Copy link

DonikaV commented Oct 3, 2024

Hello, i am new to x-charts and maybe because lack of knowledge I don't know how to do it and can not find it in the docs. So I want to have only MuiChartsAxis-right and not render the left one, because if I do what I have now - the chart have less width than it should have.
I am trying to build an expenses chart with buttons in the bottom which will be clickable, this is what I disabled bottom information and will add my custom ones. Also, I don'know how to add "$" to the values at the right. I triedvalueFormatter = (value) =>$${value}, but it brokes the UI
So this is my code:

<LineChart
  height={450}
  margin={{ top: 100 }}
  colors={['#2F4CDD', '#B519EC']}
  grid={{ horizontal: true }}
  series={[
    {
      yAxisId: 'logAxis',
      id: 'main',
      data: pData,
      area: true,
      showMark: false,
    },
  ]}
  yAxis={[
    {
      id: 'linearAxis',
      scaleType: 'linear',
    },
    {
      id: 'logAxis',
      scaleType: 'log',
    },
  ]}
  xAxis={[
    {
      scaleType: 'point',
      data: xLabels,
    },
  ]}
  rightAxis="logAxis"
  leftAxis={null}
  sx={{
    '& .MuiAreaElement-series-main': {
      fill: "url('#myGradient')",
    },
  }}
>
  <Colorswitch />
</LineChart>

This is what I have
Image
and this is what I want to have
Image

Search keywords:

Search keywords:

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 3, 2024
@zannager zannager transferred this issue from mui/material-ui Oct 3, 2024
@zannager zannager added the component: charts This is the name of the generic UI component, not the React module! label Oct 3, 2024
@JCQuintas
Copy link
Member

JCQuintas commented Oct 4, 2024

Hi @DonikaV you can try something like on this codesandbox: https://codesandbox.io/p/sandbox/gracious-lovelace-5k4z83

Axis formatting goes into the axis configuration, though it shouldn't break the tick positioning, I'll take a look at that.

@JCQuintas JCQuintas added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 4, 2024
@DonikaV
Copy link
Author

DonikaV commented Oct 4, 2024

Hi @zannager you can try something like on this codesandbox: https://codesandbox.io/p/sandbox/gracious-lovelace-5k4z83

Axis formatting goes into the axis configuration, though it shouldn't break the tick positioning, I'll take a look at that.

Amazing! Thank you so much!
One more question, if I want to have

const xLabels = ['1M', '2M', '3M', '6M', 'YTD', 'All']; // Months | YEAR | ALL 
 xAxis={[
                    {
                      scaleType: 'point',
                      data: xLabels,
                    },
                  ]}

And in the bottom I will add also buttons with same labels and on click will change series data
Its ok? Or I need to change scaleType or smh like this?

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Oct 4, 2024
@JCQuintas
Copy link
Member

I don't think you should use the xAxis to have labels/buttons. You can do that outside of the chart and then change all the necessary data to display your current state

@DonikaV
Copy link
Author

DonikaV commented Oct 4, 2024

BTW with these settings, grid={{ horizontal: true }}, grid is not presented... On your demo as well.
But thank you!

@JCQuintas
Copy link
Member

Grid seems to be applied only to the first axis, so you would need to remove the linear axis

        {
          id: "linearAxis",
          scaleType: "linear",
        },

@DonikaV
Copy link
Author

DonikaV commented Oct 4, 2024

Grid seems to be applied only to the first axis, so you would need to remove the linear axis

    {
      id: "linearAxis",
      scaleType: "linear",
    },

Tried this,

app-index.js:33 Warning: Encountered two children with the same key, `horizontal-`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
    at ChartsGridHorizontal (webpack-internal:///(app-pages-browser)/./node_modules/@mui/x-charts/ChartsGrid/ChartsHorizontalGrid.js:19:5)

and then it renders this
Image

@JCQuintas
Copy link
Member

yes, the current grid renders based on the shown axis. To have a "square" grid on a "log" axis you would have to go into more in-depth customization

Creating custom components: https://mui.com/x/react-charts/components/
Composition: https://mui.com/x/react-charts/composition/

@michelengelen michelengelen changed the title LineChart have only MuiChartsAxis-right and not left [charts] LineChart have only MuiChartsAxis-right and not left Oct 6, 2024
@michelengelen michelengelen added status: waiting for author Issue with insufficient information customization: extend Logic customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 6, 2024
@michelengelen
Copy link
Member

Hey @DonikaV is this issue resolved for you with the provided solutions? If yes, feel free to close it! Thanks!

Copy link

The issue has been inactive for 7 days and has been automatically closed.

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! customization: extend Logic customizability status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

4 participants