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.

Line components render offset from rest of chart when the XAxis component's 'scale' property is assigned to 'linear'

See original GitHub issue

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

When using a scale of linear with time series data (encoded in unix timestamps), Line components within a LineChart render offset to the rest of the chart. (Mine were wrapped in ResponsiveContainer, but I have validated that removing this does not solve my occurrence of this issue.) screenshot 2017-12-11 16 49 04

Appears in the fiddle posted below. Notice how the orange and green lines run off the chart

screenshot 2017-12-11 16 38 57

This behavior does not effect the Tooltip’s cursor.

jsfiddle Demo of problem (on right-hand side)

What is the expected behavior?

Line’s output should render in the appropriate position. Note: this happens with multiple different scale.

Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?

macOS High Sierrra, Chrome 62, using the latest npm release at time of writing (1.0.0-beta.6)

Issue Analytics

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

github_iconTop GitHub Comments

9reactions
tkeffercommented, Feb 10, 2018

Setting type='number' in <XAxis> solved my problem:

 <XAxis
     dataKey='timestamp'
     domain={['auto', 'auto']}
     scale='time'
     type='number'
/>

Otherwise, the default type='category' applies, resulting in categories that center on the tick marks, and thus stray beyond the end of the x-axis.

Applying the fix to @B3rry JSFiddle fixes his problem as well: http://jsfiddle.net/zqu3rb8s/4/

I leave it to him to close the issue.

1reaction
orhan-swecommented, May 22, 2018

I have also seen this; initial XAxis:

<XAxis
                    dataKey="name"
                    scale="time"
                    interval="preserveStartEnd"
                    tickFormatter={getTickFormat}
                    ticks={ticks}
                />

I had to add both type and domain to get rid of the offset:

<XAxis
                    dataKey="name"
                    scale="time"
                    interval="preserveStartEnd"
                    tickFormatter={getTickFormat}
                    ticks={ticks}
                    domain={['auto', 'auto']}
                    type="number"
                />

It should not be necessary to add both domain and type, I would suggest that this is a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Line Charts | Tutorial by Chartio
Line charts are a fundamental chart type generally used to show change in values across time. Learn how to best use this chart...
Read more >
Victory | VictoryAxis
VictoryAxis renders a single axis which can be used on its own or composed ... a component instance which will be responsible for...
Read more >
Linear Axis - Chart.js
The linear scale is used to chart numerical data. It can be placed on either the x or y-axis. The scatter chart type...
Read more >
xAxis.categories | highcharts API Reference
A positive offset moves the axis with it's line, labels and ticks away from the plot area. This is typically used when two...
Read more >
How to add annotations and decorations to charts - think-cell
In addition, the X-axis of a line chart may be a value axis, ... then to select appropriate parts in the requested charts...
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