Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Axis displaying incorrect tick values for some data point combination

Open dragos-triteanu opened this issue 7 years ago • 2 comments

I've noticed that when using chart.js to plot date related data points, there are times when the graph displays incorrect axis ticks. This happens only for specific data points.

Expected Behavior

The expected behaviour is that the chart correctly generates axis ticks when using a date as an axis based on the provided data set. If the difference between the data points is in the magnitude of days, the chart's axis should reflect that.

Current Behavior

For a multi-day plot, instead of displaying dates such as "20 Feb" the chart displays hours such as "1PM" although the difference of points is in the magnitude of days. Weird thing is that this happens only for specific data.

Possible Solution

I think that there is logic in the chart.js implementation for calculating gaps between data points that are of type "date". I would start investigating how these points are calculated when using the data from Steps To Reproduce (for bugs)

Steps to Reproduce (for bugs)

  1. Open https://codepen.io/anon/pen/KYazaR
  2. In JS tab, switch data between dataThatWorks and dataThatDoesNotWork
  3. In CSS tab, switch width between 900px and 1200px

Context

As our project is intended to present various networking metrics to our customers, the date ranges for these points are important.

Environment

Chart.js version 2.8.0 being used as part of an Angular 6 application Browser used for testing is Chrome Version 70.0.3538.77 (Official Build) (64-bit) running on top of Lubuntu.

Demonstrative formats: https://codepen.io/anon/pen/KYazaR https://stackblitz.com/edit/ng2-chart-example-kvghc3?file=app%2Fapp.component.html

dragos-triteanu avatar Apr 10 '19 08:04 dragos-triteanu

Use time.unit option to specify the unit of ticks.

time: {
   unit: 'day'
}

nagix avatar Apr 11 '19 04:04 nagix

Use time.unit option to specify the unit of ticks.

time: {
   unit: 'day'
}

That did the trick 🗡

dragos-triteanu avatar Apr 11 '19 11:04 dragos-triteanu