Home forums Using CanvasJS Bar Chart with Multiple Data Columns Reply To: Bar Chart with Multiple Data Columns

#17495

corylee766
Member

@Suyash Singh

I looked at the jFiddle and tried to replicate it and must be missing something. I am still a novice when it comes to Json.

What am I doing wrong?


  <!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' >
<head>
    <title></title>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
var dps1 = [], dps2 = [];

var chart = new CanvasJS.Chart("chartContainer", {
  title: {
    text: "Multiseries Chart from JSON Data"
  },
  data: [
    {
      type: "column",
      dataPoints: dps1
    },
    {
      type: "column",
      dataPoints: dps2
    }
  ]
});
$.getJSON("https://api.myjson.com/bins/b1gun", function(chartData) {
	for(var i = 0; i < chartData.length; i++){
  	dps1.push({ x: new Date(chartData[i].x), y: chartData[i].y});
  }
  chart.render();
});

$.getJSON("https://api.myjson.com/bins/18fvvz", function(chartData) {
	for(var i = 0; i < chartData.length; i++){
  	dps2.push({ x: new Date(chartData[i].x), y: chartData[i].y});
  }
  chart.render();
});

});
  </script>

</head>
<body>
<br><!-- Just so that JSFiddle's Result label doesn't overlapthe Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
</body>
</html>