Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set the Recharts axis domain max lower than dataMax?

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?

like image 299
bioJim Avatar asked Jan 02 '23 12:01

bioJim


1 Answers

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).

like image 171
bioJim Avatar answered Jan 09 '23 20:01

bioJim