ankane / react-chartkick

Create beautiful JavaScript charts with one line of React
https://chartkick.com/react
MIT License
1.2k stars 58 forks source link

Multiple series line charts not plotting correctly for dynamic data points #40

Closed maxnathaniel closed 5 years ago

maxnathaniel commented 5 years ago

Hi,

I am rendering multiple series line charts.

The data structure is as such -

const data = [ { name:'Workout', data: { MAR19: 3, APR19: 4, MAY19:4.7, JUN19: 5.1 } }, { name:'Call parents', data: { JAN19: 3.4, FEB19: 5, MAR19: 3, APR19: 3.5, MAY19: 4.3 } }, ];

To give some context, the data that I'm receiving is dynamic, and I don't know beforehand what the data points would be.

The expected behaviour is that the second line will display the JAN19 and FEB19 points at the beginning of the x-asis, but it isn't. It ends up rendering the 2 points at the end of the x-asis.

How can I resolve this?

image

ankane commented 5 years ago

Hey @maxnathaniel, Chartkick is treating the data as categorical since it doesn't recognize that format as date/time. You'll need to use a recognized format (like YYYY-MM-DD) for ordering to work. Otherwise, it orders based on the first time the value appears in the dataset. Since the first value in the first series is MAR19, that value appears first.

maxnathaniel commented 5 years ago

Hi @ankane, thanks for your reply. I see, that explains it. Unfortunately, I have no control over the date format as I'm working with a long standing convention. What I've done, as a workaround, is to add labels with null value to standardize across the multi series, and that fixed it.