Skip to content

Adding functions to JQPlot Graph Y Axis for plotting values

November 2, 2012

Today I had focused on building JQPlot graphs, but I wanted to build a custom value for setting hours, minuts, and seconds in the format HH:mm:SS onb the Y Axis.

After several attempts, there is no functionaility to convert seconds to hours, minutes and seconds, even with the DateAxisRenderer.

However here was a really useful function I manage to write below which can convert in javascript for those interested: –

   function secondsToTime(val) {
        var totalSec = new Date().getTime() / 1000;
        hours = parseInt(val / 3600) % 24;
        minutes = parseInt(val / 60) % 60;
        seconds = totalSec % 60;
        result = (hours < 10 ? “0” + hours : hours) + “:” + (minutes < 10 ? “0” + minutes : minutes) + “:” + (seconds < 10 ? “0” + seconds : seconds);
        return result;
    }
    
    (function($) {
        $.jqplot.secondsToTime = function (val) {
            var totalSec = new Date().getTime() / 1000;
            hours = parseInt(val / 3600) % 24;
            minutes = parseInt(val / 60) % 60;
            seconds = totalSec % 60;
            result = (hours < 10 ? “0” + hours : hours) + “:” + (minutes < 10 ? “0” + minutes : minutes) + “:” + (seconds < 10 ? “0” + seconds : seconds);
            return result;
        }

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: