Using DateTime value on Y Axis - CanvasJS JavaScript Charts

Using DateTime value on Y Axis - CanvasJS JavaScript Charts

by canvasjs

HTML

<script src="http://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", {
	title:{
		text: "Popular Fast Food Chains"
	},
  toolTip: {
  	contentFormatter: function(e){
    	return ("End : " +  CanvasJS.formatDate(e.entries[0].dataPoint.y[1], "HH:mm:ss") +"</br> Start: " +  CanvasJS.formatDate(e.entries[0].dataPoint.y[0], "HH:mm:ss"));
    }
  },
	axisY: {
        minimum: (new Date(1970, 0, 0, 0, 0, 0)).getTime(),       
            labelFormatter: function(e){
                return CanvasJS.formatDate(e.value, "HH:mm:ss");
            },
          	//suffix : " hour"
		},
	axisY2: {
		title: "Percent",
		suffix: "%",
		lineColor: "#C0504E",
		tickColor: "#C0504E",
		labelFontColor: "#C0504E"
	},
	data: [{
			type: "rangeColumn",      
			dataPoints: [
                { label: "Test",
                 	y: [(new Date(1970, 0, 0, 0, 0)).getTime(), (new Date(1970, 0, 0, 10, 0,0)).getTime()] },
				{ label: "Test1",
                 	y: [(new Date(1970, 0, 0, 0, 0)).getTime(), (new Date(1970, 0, 0, 3, 0)).getTime()] },
				{ label: "Test2",
                 	y: [(new Date(1970, 0, 0, 0, 0)).getTime(), (new Date(1970, 0, 0, 2, 0)).getTime()] },
				{ label :"Test3",
                 	y: [(new Date(1970, 0, 0, 0, 0)).getTime(), (new Date(1970, 0, 0, 2, 45)).getTime()] }
			]
		}]  
});
chart.render();
createPareto();	

function createPareto(){
	var dps = [];
	var yValue, yTotal = 0, yPercent = 0;

	for(var i = 0; i < chart.data[0].dataPoints.length; i++)
		yTotal += chart.data[0].dataPoints[i].y[1];
	
  
	for(var i = 0; i < chart.data[0].dataPoints.length; i++){
		yValue = chart.data[0].dataPoints[i].y[1];
		yPercent += (yValue / yTotal * 100);
		dps.push({label: chart.data[0].dataPoints[i].label, y: yPercent});
	}
	
	chart.addTo("data",{type:"line", yValueFormatString: "0.##\"%\"", dataPoints: dps, toolTipContent: "{y}"});
	chart.data[1].set("axisYType", "secondary");  
	chart.axisY2[0].set("maximum", 100);
}