Histogram Chart using Column Chart - CanvasJS JavaScript Charts

Histogram Chart using Column Chart - CanvasJS JavaScript Charts

by Vitaliy

HTML

<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>

JavaScript

window.chart = new CanvasJS.Chart("chartContainer",
{
	title: {
  	text: "Histogram using Column Chart"
  },
  type: "column",
  axisY2:{
  		title : "Secondary Y Axis"
 	},
	data: [
	{
		
		dataPoints: [
			{ x: 10, y: 71, color: 'black' },
			{ x: 20, y: 55, color: 'black'},
			{ x: 30, y: 50, color: 'black' },
			{ x: 40, y: 65, color: 'black' },
			{ x: 50, y: 95, color: 'black' },
			{ x: 60, y: 68, color: 'black' },
			{ x: 70, y: 28, color: 'black' },
			{ x: 80, y: 34, color: 'black' },
			{ x: 90, y: 14, color: 'black'}
		]
	}
	]
});

chart.render();

//get("propertyName");
//set("propertyName", value, updateChart);

//updateChart = false
chart.set("dataPointWidth",Math.ceil(chart.axisX[0].bounds.width/chart.data[0].dataPoints.length),true);

//On Resize chart width changes so as the plotArea, so dataPointWidth will vary according to width
$( window ).resize(function() {
	chart.set("dataPointWidth",Math.ceil(chart.axisX[0].bounds.width/chart.data[0].dataPoints.length),true);
});