How to set the reference line position based on value? #370
-
Right now the For example, const data = [{value: 10, value: 20, value: 30, value: 40}]
const meanValue = data.reduce((prev, curr) => prev + curr.value, 0) / data.length;
return (<LineChart
// @ts-ignore
data={data}
// I want to use meanValue as the reference line here
/>
) Is there currently any way to do that? |
Beta Was this translation helpful? Give feedback.
Answered by
Abhinandan-Kushwaha
Aug 26, 2023
Replies: 1 comment 1 reply
-
Hi @IkaWaAyuMu 👋 So, for your example, you just need to pass the props Your code should look like- const data = [{value: 10, value: 20, value: 30, value: 40}]
const meanValue = data.reduce((prev, curr) => prev + curr.value, 0) / data.length;
return (<LineChart
// @ts-ignore
data={data}
showReferenceLine1
referenceLine1Position={meanValue}
/>
) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Abhinandan-Kushwaha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @IkaWaAyuMu 👋
I think you misunderstood
referenceLinePosition
. It is NOT based on pixel amount from the bottom. It is already based on the data values.So, for your example, you just need to pass the props
showReferenceLine1
andreferenceLine1Position={meanValue}
Your code should look like-