I am looking to create a chart using MUI X barchart.
import { BarChart } from ‘@mui/x-charts/BarChart;
I specifically am looking only to add horizontal grid lines extending from the auto established tick marks on y axis, but thought it would be also helpful to know if vertical grid lines could also be added in case of future users searching for a similar solution for the other available charts (ex. I would think vertical grid lines would be helpful in the case of a line graph).
I haven’t been able to really try anything as I am unsure how to even go about it (I’m new to react and using MUI components so still learning how to style elements)
There is an issue opened on Github for this feature: https://github.com/mui/mui-x/issues/10158
In the meantime you can create a custom styled Path and use
d3-scale
to determine line position and draw it usingpath
Example :
Still you can use Your Chart Component (e.g:
<BarChart/>
) and put the inside it, as a children:Here is the demo : https://codesandbox.io/s/tender-napier-3htnp6?file=/src/Demo.tsx:1333-1343