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

x-axis missing first label #9470

Closed
FlukeFan opened this issue Jul 25, 2021 · 2 comments
Closed

x-axis missing first label #9470

FlukeFan opened this issue Jul 25, 2021 · 2 comments

Comments

@FlukeFan
Copy link

FlukeFan commented Jul 25, 2021

Reopened as a separate issue to original problem here: #9468

Expected Behavior

Attempting to stack values on a bar chart, where the data x value has sparse time values.

The chart draws correctly I think, but the tooltip is not correct when hovering the mouse over the chart.
The data for 1st May should total 30 (10 + 20);
The data for 2nd May should total 50 (20 + 30);
The data for 5th May should total 40 (10 + 30).

image

Current Behavior

The x-axis label is missing for the first day:
image

Steps to Reproduce

Navigate to here: https://jsfiddle.net/Leelenaleee/8oLgvu41/1/

Environment

var ctx = document.getElementById('myChart').getContext('2d');

new Chart(ctx, {
  type: 'bar',
  data: {
    datasets: [{
      label: 'Amount1',
      backgroundColor: '#004c6d',
      data: [{
          x: '2010-05-01T00:00:00Z',
          y: 10
        },
        {
          x: '2010-05-02T00:00:00Z',
          y: 20
        }
      ]
    }, {
      label: 'Amount2',
      backgroundColor: '#b3cce2',
      data: [{
          x: '2010-05-02T00:00:00Z',
          y: 30
        },
        {
          x: '2010-05-05T00:00:00Z',
          y: 10
        }
      ]
    }, {
      label: 'Amount3',
      backgroundColor: '#547c9a',
      data: [{
          x: '2010-05-01T00:00:00Z',
          y: 20
        },
        {
          x: '2010-05-05T00:00:00Z',
          y: 30
        },
      ]
    }]
  },
  options: {
    plugins: {
    	tooltip: {
      	mode: 'x'
      },
      legend: {
        display: false
      }
    },
    scales: {
      x: {
        stacked: true,
        type: 'time',
        time: {
          unit: 'day',
          displayFormats: {
            day: 'YYYY-MMM-DD'
          }
        }
      },
      y: {
        stacked: true,
      }
    }
  }
});

@kurkle
Copy link
Member

kurkle commented Jul 29, 2021

This depends on the clients timezone. Because the timestamps are in UTC/GMT, and the bounds option is in its default value (for time scale) 'data', generated ticks outside data bounds are filtered out.
Now for me, at GMT+3, the first tick is 2010-04-30 21:00:00 UTC/GMT, which is filtered out. The fix here is either remove the timezone from the timestamps, or set bounds: 'ticks'

edit: or use round: 'day'

@FlukeFan
Copy link
Author

FlukeFan commented Aug 6, 2021

OK, thanks.

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