I'm using Recharts in a setting where users will want to see the same data plotted at different scales. In particular, I need to be able to set the axis domain maximum to be lower than the maximum data value (dataMax
); e.g., I want to set domain={[0,10]}
when dataMax
is 20. I have yet to find a way to do this in Recharts; whenever I set a domain maximum that is lower than dataMax
, my plot is drawn so that the domain goes up to dataMax
anyway. Is there a way to do this?
I've found a way to do this. You need to use the functional syntax, which I had already tried, but without any reference to dataMax in the function. So this is what worked for me:
domain={[ 0, dataMax => (10) ]}
You can of course use more elaborate code inside the parentheses; the trick is that you cannot use the dataMax variable in any way that reduces its value. That is, you can't use, say dataMax => (dataMax/2)
or dataMax => (dataMax - 10)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With