Giter Club home page Giter Club logo

Comments (8)

codesuki avatar codesuki commented on May 21, 2024

Wow that's very weird! Thanks for the report.
Actually had some similar bug here before and it was because of the data format / sorting.
Could you post a small part of your data and if you do the scales that you pass to the graph?

from react-d3-components.

AlexPoint avatar AlexPoint commented on May 21, 2024

I don't pass any scale to the graph.
Below is the code for reproducing:

var data = [
{label:"1",values:[{x:"0",y:1},{x:"1",y:1},{x:"4",y:1}},
{label:"2",values:[{x:"0",y:1},{x:"1",y:2},{x:"4",y:0}]},
{label:"null",values:[{x:"0",y:6},{x:"1",y:0},{x:"4",y:0}]}
];
return (<LineChart data={data} width={840} height={500} margin={{top: 10, bottom: 50, left: 50, right: 10}} />)

It seems that the issue happens when the "x" values are string.
Below is the graph for the same data points when "x" values are ints (works well in this case)
issue

from react-d3-components.

codesuki avatar codesuki commented on May 21, 2024

Thanks for the details! Any reason you pass is in as string? Just for clarification.

from react-d3-components.

codesuki avatar codesuki commented on May 21, 2024

Thinking of it. If you pass a string the default scales will be ordinal and what you want is linear, which will be generated automatically if you pass numbers. So if you want to pass strings and have a linear scale you might make a scale yourself with the correct settings and pass it to the graph.

from react-d3-components.

AlexPoint avatar AlexPoint commented on May 21, 2024

I'm passing the values as string because they're not necessarily numbers (could be dates, numbers, strings...)
I think I should cast the values from strings to numbers when they're actually numbers since I assume that the default ordering for strings is lexicographic?
That example being apart, I will have other cases where the values will be strings. I will try passing a scale as you suggested in those cases.
Getting back to you asap to tell you if that worked.

from react-d3-components.

codesuki avatar codesuki commented on May 21, 2024

At the moment it's automatically decided by looking at a single data point in https://github.com/codesuki/react-d3-components/blob/master/src/DefaultScalesMixin.jsx

Supported are ordinal, numerical and date scales by default. But what you pass in yourself is not limited of course.

from react-d3-components.

brooksp avatar brooksp commented on May 21, 2024

The x-axis offset for ordinal scales is being caused by bar padding in _makeOrdinalXScale of DefaultScalesMixin.jsx. Bar padding defaults to 0.5, which is why it shows up correctly for bar charts but not for any other chart type. If you pass barPadding={1} as a property to charts (other than bar charts), it should fix the issue.

from react-d3-components.

codesuki avatar codesuki commented on May 21, 2024

Good catch!

from react-d3-components.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.