问题
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?
回答1:
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)
.
来源:https://stackoverflow.com/questions/53751564/can-i-set-the-recharts-axis-domain-max-lower-than-datamax