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

百般思念 提交于 2020-01-14 02:48:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!