How to add x axis from the line in bar line chart?

2👍

https://jsfiddle.net/qrwvvtxs/

var barChartData = {
  labels: ["January", "February", "March", "April", "May", "June", "July"],
  datasets: [{
    label: 'Dataset 1',
    yAxisID: "y-axis-1",
    data: [3,2,7,4,5,7,6]
  }, {
  	type: "line",
    fill: false,
    label: 'Dataset 2',
    borderColor: '#faa',
    backgroundColor: "#faa",
    yAxisID: "y-axis-2",
    data: [11,13,21,13,16,21,18]
  }]
};

var ctx = document.getElementById("canvas").getContext("2d");
window.myBar = new Chart(ctx, {
  type: 'bar',
  data: barChartData,
  options: {
    responsive: true,
    title:{
      display:true,
      text:"Chart.js Bar Chart - Multi Axis"
    },
    tooltips: {
      mode: 'index',
      intersect: true
    },
    scales: {
      yAxes: [{
        display: true,
        position: "left",
        id: "y-axis-1",
        ticks: {
          callback: function(value, index, values) {
            return value + " Kg";
          }
        }
      }, {
        display: true,
        position: "right",
        id: "y-axis-2",
        gridLines: {
          drawOnChartArea: false
        },
        ticks: {
          callback: function(value, index, values) {
            return "€ " + value;
          }
        }
      }],
    }
  }
});
.wrapper {
  width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>

<div class="wrapper">
    <canvas id="canvas"></canvas>
</div>

Leave a comment