Home Forums Chart Support Dynamically build a linear chart from JSON with date? Reply To: Dynamically build a linear chart from JSON with date?

#17310

@dimas19801,

Please refer Tutorial on Creating Charts from JSON Data & AJAX.

The JSON data needs to parsed before passing it to chart-options. Check out the below code snippet for the same.

$.getJSON("https://api.npoint.io/6be170cb804361d314e3", function(chartData) {  
	for(var i = 0; i < chartData.length; i++){
  	dps.push({ x: new Date(chartData[i].x), y: chartData[i].y});
  }
	chart = new CanvasJS.Chart("wtChart", {    
  	title: {
    	text: "Chart from External JSON Data"
    },
    data: [
      {
        type: "column",
        dataPoints: dps
      }
    ]
  });
  chart.render();
});

Please check this JSFiddle for complete code.

Chart from external JSON with datetime values on X Axis


Vishwas R
Team CanvasJS