question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceLine not appearing when returned from inside component

See original GitHub issue

I think I’ve found a bug. I am trying to create a ScatterChart with a ReferenceLine. I want to put the ReferenceLine inside a Redux connected component, which means I have to put it in a separate custom component.

The problem is that unless I explicitly place the ReferenceLine inside the chart it doesn’t appear in the chart at all. Even if I put it in a simple wrapper component the ReferenceLine disappears.

Here is a JSFiddle: http://jsfiddle.net/9xjjuwkk/27/

Chart

class Chart extends Component {
    render() {
        const { now } = this.props;
        return (
            <ResponsiveContainer width="100%" height={400}>
                <ScatterChart >
                    <CartesianGrid strokeDasharray="3 3" />
                    <Scatter name="vector" data={data} fill='#8884d8'
                        line
                        shape={shape} />
                    <XAxis dataKey="time" name="time" unit="seconds" label="seconds" domain={[0, 1]} />
                    <YAxis dataKey="vector" unit="g" name="acceleration" />
                    <ReferenceLine x={0.5} stroke="red" strokeDasharray="3 3" label="Crash" />
                    <NowLine now={now} /> {/* should also return ReferenceLine */}
                </ScatterChart>
            </ResponsiveContainer>
        )
    }
}

Component that returns a ReferenceLine

class NowLine extends Component {
    render() {
        const { now } = this.props;
        return (
            <ReferenceLine x={now} stroke="blue" strokeDasharray="3 3" label="Current" />
        )
    }
}

There should be two reference lines inside the chart, a red one which is placed inside the chart explicitly, and a blue one which should be returned through the NowLine component. However the blue one doesn’t appear. Why is this the case?

I am using recharts v0.20.8 on Chrome 55/Windows 7.

This could be related to #41 but I’m not 100% sure.

Any help would be appreciated!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
xile611commented, Mar 3, 2017

@Arrow7000

You must use component ReferenceLine not a customized component. Check the code for detail.

When we render ScatterChart, we’ll check the type of children to find out the ReferenceLine instances and append some props to the instances. So If you add a customized component to the ScatterChart, we can’t identify it as a ReferenceLine element.

              <ResponsiveContainer width="100%" height={400}>
                <ScatterChart >
                    <CartesianGrid strokeDasharray="3 3" />
                    <Scatter name="vector" data={data} fill='#8884d8'
                        line
                        shape={shape} />
                    <XAxis dataKey="time" name="time" unit="seconds" label="seconds" domain={[0, 1]} />
                    <YAxis dataKey="vector" unit="g" name="acceleration" />
                    <ReferenceLine x={0.5} stroke="red" strokeDasharray="3 3" label="Crash" />
                    <ReferenceLine x={now} stroke="blue" strokeDasharray="3 3" label="Current" />
                </ScatterChart>
            </ResponsiveContainer>
3reactions
LR-brendancommented, Apr 3, 2019

Is there any solution to this problem yet? I am trying to do the same thing as @Arrow7000, i.e create a Redux connected ReferenceLine which is required to only re-render this the reference line and not entire graph.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - No component displayed when adding a custom label ...
I'm trying to add a custom label with a circular border to the right of a ReferenceLine as shown here ...
Read more >
No component displayed when adding a custom label to a ...
Coding example for the question No component displayed when adding a custom label to a ReferenceLine in Recharts-Reactjs.
Read more >
All about Reference Plane Vs Reference Line and How to use ...
All about Reference plane and Reference line in Revit. This tutorial explains how to control angle constraint using Reference Line.
Read more >
The Reference Lines Tab - OriginLab
You can display reference lines behind or in front of your data points. See Data Drawing Options. Line. Specify whether to show the...
Read more >
Creating a Reference Line which Appears and Disappears ...
Question. Usually, a reference line will display whether or not there are corresponding values visible in the underlying data.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found