问题描述
我在一种设置中使用图表",在该设置中,用户将希望看到以不同比例绘制的相同数据.特别是,我需要能够将轴域最大值设置为小于最大数据值(dataMax
). 例如,我想在dataMax
为20时设置domain={[0,10]}
.每当我将域最大值设置为小于dataMax
时,都会绘制我的图,以便该域无论如何都升至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?
推荐答案
我找到了一种方法.您需要使用我已经尝试过的函数语法,但是在函数中没有对dataMax的任何引用.所以这对我有用:
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) ]}
您当然可以在括号内使用更详细的代码;诀窍是您不能以任何降低其值的方式使用dataMax变量.也就是说,您不能使用dataMax => (dataMax/2)
或dataMax => (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)
.
这篇关于我可以将“图表"轴域最大值设置为低于dataMax吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!