score:0

Accepted answer

I found simple solutions. We need add 12 hours for every date and then are bars on correct positions.

JSFiddle is here https://jsfiddle.net/gpfz62z4/4/.

(Code is slightly improved. I add some interactivity (try mouse), and change dates to string because bar size is renderend more precise way.)

    function makeBasicChart() {

      var data    = [{"x":"2016-09-06 00:00","y":0},{"x":"2016-09-07 00:00","y":73},{"x":"2016-09-08 00:00","y":3},{"x":"2016-09-09 00:00","y":0},{"x":"2016-09-10 00:00","y":0},{"x":"2016-09-11 00:00","y":0},{"x":"2016-09-12 00:00","y":0},{"x":"2016-09-13 00:00","y":0}];
    var dataset = new Plottable.Dataset(data);

    var xScale  = new Plottable.Scales.Time().domain([new Date("2016-09-05"), new Date("2016-09-16")]);;
    var yScale  = new Plottable.Scales.Linear();

    var xAxis   = new Plottable.Axes.Time(xScale, "bottom");
    var yAxis   = new Plottable.Axes.Numeric(yScale, "left");

    var plot    = new Plottable.Plots.Bar();

    plot.addDataset(dataset);
    plot.x(function (d) { return (moment(new Date(d.x)).add(12, 'h')); }, xScale);
    plot.y(function (d) { return d.y; }                                 , yScale);
    plot.attr("width", function() { return xScale.scale(24*3600*1000) - xScale.scale(0); });

    var grid    = new Plottable.Components.Gridlines(xScale);
    var group   = new Plottable.Components.Group([plot, grid]);

    var chart = new Plottable.Components.Table([
      [yAxis, group],
      [null, xAxis]
    ]);

    chart.renderTo("svg#tutorial-result");
    pzi = new Plottable.Interactions.PanZoom(xScale, null).attachTo(chart);
  }

  $(document).ready(function () {
    makeBasicChart();
  });

Related Query

More Query from same tag