Chart Screenshot
i’m trying to draw several reference line at this AreaChart for threshold values, which is the Y value for the chart.
And the domain of the Y value is the cumulative amount of data traffic (100kb, 112gb, 12pb …)
If there is a threshold for the traffic, i want to draw a ReferenceLine for that value, so the user would be able to notice the traffic is about to exceed or exceeded the limitation.
<ResponsiveContainer width='100%' height='100%'>
<AreaChart data={cumulativeData} margin={{ top: 20, right: 5, left: 10 }}>
<CartesianGrid strokeDasharray='3 3' />
<XAxis dataKey='startedAt' />
<YAxis
width={70}
padding={{ top: 30 }}
tickFormatter={byteFormatter}
/>
<Tooltip
formatter={(value) => [
`${byteFormatter(value as number)} (${commaizeNumber(value as number)} bytes)`,
t('metrics::dataType.edgeTransfer')
]}
/>
{thresholdList?.items.map((threshold) => (
<React.Fragment key={threshold.toId().id}>
<defs>
<linearGradient id='splitColor' x1='0' y1='0' x2='0' y2='1'>
<stop offset={offset} stopColor={theme.palette.error.main} stopOpacity={0.32} />
<stop offset={offset} stopColor='white' stopOpacity={0} />
</linearGradient>
</defs>
<ReferenceLine
y={threshold.transfer.threshold}
ifOverflow={'visible'}
orientation={'right'}
stroke={theme.palette.error.main}
label={<ReferenceLabel value={byteFormatter(threshold.transfer.threshold)} />}
strokeDasharray='5 3'
/>
</React.Fragment>
))}
<Area
dataKey='edgeTransfer'
fill={`url(#splitColor)`}
connectNulls
this is my code for that.
in the screenshot, the chart’ y range is 0 ~ 111.76 GB. and i want to draw ReferenceLine at the top of the chart, if the y prop for ReferenceLine (threshold) exceed far more than the range of the chart (like, 10 TB.
Recharts provide ifOverflow prop for that, but i don’t want to ‘extendDomain’ cause if the chart is extended to 10 TB, it gets so hard to see the graph for the cumulative data.
<YAxis
width={70}
padding={{ top: 30 }}
tickFormatter={byteFormatter}
// domain={['auto, 'auto']} <- default props value
/>
so, THE Y VALUE OF THE TOP POSITION is calculated by the library, by the domain prop of the domain, and padding.
is there anyway that i can get THAT VALUE??
hongsoohyuk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.