Pablo Estrada
Pablo Estrada

Reputation: 3462

Wrong order in Chart.js graph with time on the X-Axis

Hello Im trying to plot some data on angularjs using chart.js , but Im getting a weird ordering of my data, which results in a weird chart like this:

enter image description here

This are my options:

 vm.options = {
        type:'line',
        fill: false,
        backgroundColor: 'transparent',
        scales: {
          xAxes: [{
            type: 'time',
            position: 'bottom'
          }]
        }
      };

I tried ordering the date of my data like this:

    vm.data.sort(function(a,b){
      // Turn your strings into dates, and then subtract them
      // to get a value that is either negative, positive, or zero.
      return new Date(b.time) - new Date(a.time);
    });

But the result is the image above. Can anyone help me spot the problem?

Upvotes: 0

Views: 1964

Answers (1)

mnhmilu
mnhmilu

Reputation: 2468

Though it is an old post but I am answering so that somebody may get benefit from it!

I have faced similar problem with my ionic3 app. I had a problematic graph with wrong order,though my dataset was in right order (I have used a slider to adjust the value) .The problem was solved by applying a loading controller of ionic framework. You need to give time to complete the response and render before the final display.

Hope it will help you.

line graph with wrong order

Upvotes: 0

Related Questions