Exponential interval workaround - CanvasJS HTML JavaScript chart
Exponential interval workaround - CanvasJS HTML JavaScript chart
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: 600px; width: 100%;"></div>
JavaScript
var factor = 10;
var newIntervel = 1; //newly updated intervel will be stored here.
var axisYMaxValue = -Infinity; //One extra variable for keep traking the current cycle of labelFormater
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Exponential interval workaround"
},
axisY:{
interval: 10,
gridThickness: 0,
labelFontSize: 12,
labelFormatter: function(e){
if(e.value > axisYMaxValue){//Will be used later to reinitialize newIntervel if labelFormater is running morethen one cycle
axisYMaxValue = e.value;
if(e.value % newIntervel === 0){
if(e.value / newIntervel >= factor)
newIntervel *= factor;
return e.value;
}
else
return "";
}
else{
//Reinitializing newIntervel if labelFormater is running morethen one cycle
newIntervel = 1;
axisYMaxValue = -Infinity;
return "";
}
}
},
data: [
{
type: "column",
dataPoints: [
{ x: 10, y: 310 },
{ x: 20, y: 150 },
{ x: 30, y: 300 },
{ x: 40, y: 450 },
{ x: 50, y: 250 },
{ x: 60, y: 180 },
{ x: 70, y: 280 },
{ x: 80, y: 340 },
{ x: 90, y: 140 }
]
}
]
});
chart.render();