Skip to content

How to set the reference line position based on value? #370

Closed Answered by Abhinandan-Kushwaha
IkaWaAyuMu asked this question in Q&A
Discussion options

You must be logged in to vote

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 and referenceLine1Position={meanValue}

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}
  />
)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@IkaWaAyuMu
Comment options

Answer selected by Abhinandan-Kushwaha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants