Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scatter chart hides data points that have the same x value #287

Open
hkumar1993 opened this issue Oct 18, 2018 · 2 comments
Open

Scatter chart hides data points that have the same x value #287

hkumar1993 opened this issue Oct 18, 2018 · 2 comments

Comments

@hkumar1993
Copy link
Contributor

In a recent project a scatter plot only showed 3 out of 5 data points,

{ x: 0.1, y: 30 },
{ x: 0.1, y: 20 },
{ x: 0.2, y: 0 },
{ x: 0.1, y: 0 },
{ x: 0.15, y: 20 },

The points that were not displayed had the x value in common ( 0.1 ). The y values were all different but the only one displayed was y: 30

@lukwallace
Copy link
Contributor

There's a fix for this. Use the field dataKey. It's not specified anywhere in the docs tho.

@lukwallace
Copy link
Contributor

lukwallace commented Jan 7, 2020

Additional clarification regarding the dataKey flag --

For whatever reason, Contour defaults to using the x values of the dataset as the unique identifier when it comes to the scatter chart, we can change this by adding in a dataKey option to the Contour chart instance, e.g.,

this.chart = new Contour({
    el: 'my-scatter-chart',
    scatter: { dataKey: 'id' },
})
    .cartesian()
    .scatter(data)
    .render();

Essentially, this will let Contour know to consider the data unique by a key: id; applying this to the dataset raised in the issue should then fix the problem:

const data = [
    { id: 1, x: 0.1, y: 30 },
    { id: 2, x: 0.1, y: 20 },
    { id: 3, x: 0.2, y: 0 },
    { id: 4, x: 0.1, y: 0 },
    { id: 5, x: 0.15, y: 20 },
];

Alternatively, there is another method to get Contour's scatter chart to recognize your dataset as separate series without using dataKey. If you provide it in the format that makes it clear that this is the case:

const data = [
    { name: 'series-1', data: [{ x: 0.1, y: 30 }] },
    { name: 'series-2', data: [{ x: 0.1, y: 20 }] },
    { name: 'series-3', data: [{ x: 0.2, y: 0 }] },
    { name: 'series-4', data: [{ x: 0.1, y: 0 }] },
    { name: 'series-5', data: [{ x: 0.15, y: 20 }] },
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants