[Chartjs]-Starting a Chart.js Time Scale at 0

1👍

Seems this is by design, why dont you do a simple workaround to this. Use moment.js for doing the time manipulations and load the data into x axis as type linear instead of date, This basically gives the same output.

JSFiddle: here

Code:

var timeOperations = ["2013-03-09", "2013-03-16", "2013-03-23", "2013-03-30", "2013-04-06"].map(function(value){
    return moment(value, "YYYY-MM-DD").format('MMM-DD').toString();
});
var barChartData = {
  labels: timeOperations,
  datasets: [{
    borderColor: "#3e95cd",
    data: [10943, 29649, 6444, 2330, 36694],
    fill: false,
    borderWidth: 2
  },
  {
    borderColor: "#ff3300",
    data: [9283, 1251, 6416, 2374, 9182],
    fill: false,
    borderWidth: 2
  }]
};

Leave a comment