Chart.js: [BUG] Scatter chart with large dataset does not properly fill chart width

Created on 5 Jan 2017  路  11Comments  路  Source: chartjs/Chart.js

It seems that when working with semi-large datasets, (I have 204 points) the scatter chart does not use up all of the horizontal space afforded to it. This makes for very compact hard to read charts and visually looks very bad. I am using chart.js latest (v 2.4.0) on macOS and Chrome. Here is a link to the codepen where you can see exactly what is happening, along with a version of my dataset to test with.

http://codepen.io/anon/pen/WRbRWW

Please let me know if you need any other details.

screen shot 2017-01-04 at 11 15 41 pm

EDIT: Based on more reading of closed issues, this could be a problem with a calculation of how far apart to space each datapoint based on the width of the canvas. See https://github.com/chartjs/Chart.js/issues/248

bug

Most helpful comment

Even better, the time and linear scales should share the exact same code :)

All 11 comments

@scmyers11 the issue here is that the x axis range is auto scaled up so that the right edge is at 250. If you set an explicit maximum, this will not occur

I forked it and added an explicit maximum at the last point (x == 203) and it turned out better
http://codepen.io/etimberg/pen/LxEQrw

@etimberg I appreciate the help and that does solve my immediate problem. However, I am curious if this is still a bug? Auto scaling the right edge to more than the number of data points seems counterintuitive. I might be missing some context to be able to understand the reasoning but it seems like at draw time, the chart has a set size as defined by the canvas and the number of ticks. There doesn't seem to be a reason to be larger than that, that I can see.

I think this is a sort of a bug. The scatter chart uses the same numerical axis type for both the x and y axes. On the y axis, this type of scaling is common place. I can see why it causes a problem on the x axis though.

On idea is that we add some kind of configuration to allow changing how this occurs. We could then have the x axis fit to only the data and not increase. The code that increases the size is https://github.com/chartjs/Chart.js/blob/master/src/core/core.ticks.js#L62

@etimberg I am also interested in this. Is there a tracking issue for this?

@etimberg Do you have any news on that?

@mgrandl I haven't had the chance to look at this at all. The solution to this would be to define new option(s) to https://github.com/chartjs/Chart.js/blob/master/src/core/core.ticks.js#L52 and use that to configure the expected behaviour. I'm not sure exactly what the API would look like, but a PR is a good starting point for a conversation

Proposal for solving this in the v2.7 timeframe:

  1. Add a new config option to the linear axis to control the range calculation/
    Option has the a value from an enum with the following possible options:

    • Expand

    • Exact

The default would be Expand. Setting the data range calculation mode to Exact we wouldn't expand the range and just fit the ticks to some old values.

@etimberg Sounds perfect.

Sounds quite similar to the scale.bounds feature that was implemented in https://github.com/chartjs/Chart.js/pull/4556 (docs are being added in https://github.com/chartjs/Chart.js/pull/4592). That was only for the time scale, but if we implemented it for the linear scale a well, we'd probably want to make it consistent with the time scale option

Even better, the time and linear scales should share the exact same code :)

+馃挴 for sharing code between time and linear scales 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gouthamrv picture gouthamrv  路  3Comments

akashrajkn picture akashrajkn  路  3Comments

SylarRuby picture SylarRuby  路  3Comments

gabrieldesouza picture gabrieldesouza  路  3Comments

nanospeck picture nanospeck  路  3Comments