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.

uneven distribution of xaxis time scale with 'autoSkip:true' and maxTicksLimit

See original GitHub issue

image

Here initially gap is 5 days but at end it gets increased and data is cluttered at the end of the scale. Data:

"x_axis": [
            1465084800000,
            1466553600000,
            1467417600000,
            1470096000000,
            1471651200000,
            1472083200000,
            1472688000000,
            1472774400000,
            1473033600000,
            1473120000000,
            1473206400000
        ],
        "y_axis": [
            1,
            2,
            4,
            2,
            3,
            2,
            3,
            2,
            4,
            1.8,
            1.3
        ]

and options set are

ticks: {
                    autoSkip:true,
                    maxTicksLimit:20,
                    maxRotation:30
                }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
heyrexcommented, Oct 9, 2017

@etimberg This problem also affects category scale, not just time scale.

This bug is an “emergent behavior” of how the tick skipping is performed. If the number of plot points on the x axis is evenly divisible by the number of labels Chart.js decides to render, then the gap will not appear.

A contributing factor is the insistence on always plotting the last tick mark. Perhaps this should be an option that can be disabled. What I would like is interpolation and nearest neighbor matching for tick placement.

So, maybe there needs to be a config option like:

options.scales.xAxes[].ticks.autoSkipStyle = 'nearest'; //One of: 'fixed', 'nearest', 'skipLast'

I was able to work around it and get a more aesthetically pleasing plot (in my opinion) by making the following change to Chart.js. Locate the _autoSkip() function and replace:

// Since we always show the last tick,we need may need to hide the last shown one before
shouldSkip = (skipRatio > 1 && i % skipRatio > 0) || (i % skipRatio === 0 && i + skipRatio >= tickCount);
if (shouldSkip && i !== tickCount - 1 || helpers.isNullOrUndef(tick.label)) {
	// leave tick in place but make sure it's not displayed (#4635)
	delete tick.label;
}
result.push(tick);

with

// Last tick is only displayed if number of categories on axis is evenly divisible by skipRatio
shouldSkip = (skipRatio > 1 && i % skipRatio > 0);
if (shouldSkip || helpers.isNullOrUndef(tick.label)) {
	// leave tick in place but make sure it's not displayed (#4635)
	delete tick.label;
}
result.push(tick);
4reactions
Techn1xcommented, Sep 12, 2017

Still an issue in ChartJS 2.7.0, with the new time series options. Here’s a sample of my options for my time series graph.

xAxes: [{
  distribution: 'linear'
  ticks: {
    autoSkip:true,
    maxTicksLimit:10,
    source: 'auto'
  }
}]

Here’s a screenshot of what my graph looks like; capture4

Penultimate tick still missing here. I would look into submitting a PR with a fix but I don’t have the time 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I evenly distribute ticks when using maxTicksLimit?
This solution works most of the time, but still occasionally has a wider gap for the last column. I have a graph that...
Read more >
Linear Axis - Chart.js
The linear scale is used to chart numerical data. It can be placed on either the x or y-axis. The scatter chart type...
Read more >
How to make an XY graph with a time-scale on the X axis ...
When creating an XY data table (and graph), Prism allows the entry of date/time information either in the form of total elapsed time...
Read more >
Customize X-axis and Y-axis properties - Power BI
Screenshot of the Visualizations pane and an empty stacked column chart. To set the X-axis values, from the Fields pane, select Time > ......
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