简体   繁体   English

ReCharts.Js阴影区域,用于图表的完整高度(并与Brush,dataMax一致)

[英]ReCharts.Js Shaded Areas For full height of Chart (and consistent with Brush, dataMax)

I am trying to create an area that is to be shaded based on the presents of a key. 我正在尝试创建一个区域,该区域将根据钥匙的提示进行着色。 I want the shading to be from min-to-max in the Y-axis and I want the max to be dependent on the current-local max of the dataset (with respect to Brush). 我希望阴影在Y轴上从最小值到最大值,并且希望最大值取决于数据集的当前局部最大值(相对于Brush)。

I tried to play around with the internals of ReChart.js such methods as getTicksOfAxis and getValueByDataKey because I know that the Y-axis already knows the local max, so I wouldn't have to reinvent the wheel. 我尝试使用ReChart.js的内部方法,例如getTicksOfAxis和getValueByDataKey之类的方法,因为我知道Y轴已经知道局部最大值,所以我不必重新发明轮子。 Anyone have any solutions 任何人有任何解决方案

Fiddle With Me 小提琴与我

 const {ComposedChart, Area ,LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend,Brush} = Recharts; const data = [ {name: 'Page A', pv: 2400, max: 10800}, {name: 'Page q', pv: 4800, max: 10800}, {name: 'Page w', pv: 1398}, {name: 'Page e', pv: 0}, //I don't want this part max to squish the pv values since Max should be of the local max. {name: 'Page r', pv: 300, max: 10800}, {name: 'Page t', pv: 200, max: 10800}, {name: 'Page y', pv: 0}, {name: 'Page u', pv: 500}, {name: 'Page i', pv: 1398, max: 10800}, {name: 'Page o', pv: 4300, max: 10800}, {name: 'Page p', pv: 10800 }, {name: 'Page [', pv: 3908 }, {name: 'Page ]',pv: 4800, max: 10800}, {name: 'Page F', pv: 3800, max: 10800}, {name: 'Page G', pv: 4300, max: 10800}, ]; const SimpleLineChart = React.createClass({ render () { return ( <ComposedChart width={600} height={300} data={data} margin={{top: 5, right: 30, left: 20, bottom: 5}}> <XAxis dataKey="name"/> <YAxis type="number"/> <CartesianGrid strokeDasharray="3 3"/> <Tooltip/> <Legend /> <Line type="monotone" dataKey="pv" stroke="#8884d8" activeDot={{r: 8}}/> <Area type="monotone" dataKey="max" stroke="#8884d8" activeDot={{r: 8}}/> <Brush/> </ComposedChart> ); } }) ReactDOM.render( <SimpleLineChart />, document.getElementById('container') ); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> 

Suitable Example The graph provided is what I was aiming for where the shaded area is representative of some datapoint. 合适的示例提供的图形是我要针对的目标,其中阴影区域代表某些数据点。 I was able to create a sawtooth appearance (working with the brush) by providing a method for the "local-max" ei: 通过提供“ local-max” ei的方法,我能够创建锯齿外观(使用画笔):


let data=[{ line-graph:<arbitrary_value>, shaded-areas:local_max()},...]; let local_max=()=>{return this.state.localMax}


I then had to discover the local maxes, which involves getting the brushes start/endIndex and saving those to state. 然后,我不得不发现局部最大值,这涉及获取画笔的start / endIndex并将其保存为状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM