Histogram with dateTime axis - CanvasJS JavaScript Charts
Histogram with dateTime axis - CanvasJS JavaScript Charts
by canvasjs
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
var chart = new CanvasJS.Chart("chartContainer",
{
data: [
{
type: "column",
dataPoints: [
{ x: new Date(2017, 5, 5), y: 71 },
{ x: new Date(2017, 5, 10), y: 55 },
{ x: new Date(2017, 5, 15), y: 50 },
{ x: new Date(2017, 5, 20), y: 40 },
{ x: new Date(2017, 5, 25), y: 53 },
{ x: new Date(2017, 5, 30), y: 51 }
]
}
]
});
chart.render();
removeGapBetweenColumn();
function removeGapBetweenColumn() {
var length, diff;
diff = chart.axisX[0].convertValueToPixel(chart.axisX[0].minimum) - chart.axisX[0].convertValueToPixel(chart.axisX[0].maximum);
length = chart.data[0].dataPoints.length;
chart.set("dataPointWidth", Math.abs(diff / length) + 1);
}
window.onresize = removeGapBetweenColumn;