Time axis in common increments
I will even provide sample code. If I have a chart with automatic y-axis labels: 3 minutes 8 minutes, 14 minutes, it looks stupid. It should be 5, 10, 15 minutes and similar adjustments should be made for other increments as well. Adjust for irregular points by raising the max slightly and / or dropping a label.
Sample Code (works well enough):
var FitTimeAxis =
{
getAxisData: function (max,intervals)
{
var data = {};
data.max = this.getMaxValue(max,true);
data.interval = this.getMaxValue(data.max/intervals, true);
return data;
},
getIncrementsArray: function(levels)
{
levels = isTrue(levels);
var arr = [];
arr.push(15);
arr.push(30);
for (var i=1;i<=15;i++)
arr.push(60i);
arr.push(3060);
arr.push(4560);
for (var i=1;i<=48;i++)
{
arr.push(i3600);
if (levels)
arr.push(i3600 + 3060);
}
},
getMaxValue: function (number,levels)
{
var arr = this.getIncrementsArray(levels);
for (var i in arr)
{
if (arr[i] > number)
{
return arr[i];
}
}
return number; // if too large
}
}
FitTimeAxis.getXAxisLabels(29*60,3);
-
You are aware that you can make your yAxis a datetime axis? http://jsfiddle.net/highcharts/3ECm3/
-
Elijah commented
code is un-tested because it was ported to PHP and tested there. Add a missing return in getIncrements.