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.

Scatter Chart linear X-Axis

See original GitHub issue

What is the current behavior?

I am trying to generate a scatter chart with some data which has an x and y values. X ranges from 1-5 and y ranges from 0-25. I just want to plot all data points into a single chart which respects the ranges as axis.

Example

My Current Component looks like this:

  render() {
    const { data } = this.props;
    const mapped = data.map(d => {
      return {
        x: parseInt(d.orig_x),
        y: Math.round(d.orig_y)
      }
    })

    console.log(mapped.slice(1, 10))
    const limitedData = _.sortBy(mapped.slice(1, 10), 'x')

    return (
      <ScatterChart width={500} height={400} margin={{ top: 20, right: 20, bottom: 20, left: 20 }}>
        <XAxis dataKey="x" name='x' domain={[0, 5]} />
        <YAxis dataKey="y" name='y' domain={[0, 25]} />
        <CartesianGrid horizontal={false} vertical={false} />
        <Scatter name='data' data={limitedData} fill='#8884d8' />
        <Tooltip cursor={{ strokeDasharray: '3 3' }} />
      </ScatterChart>
    )
  }

The current code results in a chart which looks like this: image

What is the expected behavior?

The expected behaviour would be that all data points with an X value of e.g. 3 would be on the same point on the x-axis. But in the current version, there are multiple 3 on the x-axis. Is there a way to prevent this?

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

Recharts: 1.0.0-alpha.6 Browser: Chrome

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
Kobzolcommented, Apr 7, 2018

Try setting allowDuplicatedCategory={false} on the XAxis component.

2reactions
xile611commented, Nov 6, 2017

@KeKs0r Update the type of <XAxis> which has default value ‘category’.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Present your data in a scatter chart or a line chart
In a scatter chart, the daily rainfall values from column A are displayed as x values on the horizontal (x) axis, and the...
Read more >
Scatter Chart - Chart.js
Scatter charts are based on basic line charts with the x axis changed to a linear axis. ... The index scale is of...
Read more >
Scatterplot with 2 x-axis variables in Excel - YouTube
Need to make a graph, but have two x-axis variables? In this video I show you how to plot a second x-axis variable...
Read more >
4.3 The Scatter Chart - GitHub Pages
In a scatter chart, the X axis operates just like the Y axis. In other words, the distance between the values on the...
Read more >
How to Make a Scatter Plot in Excel (XY Chart)
A scatter plot has dots where each dot represents two values (X-axis value and ... The above steps would add a linear trendline...
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