Convert length of time to percentages nvd3

I am looking for leads on how to convert time based events from seconds to hours into percentages which can be displayed properly on nvd3 graphs.

The problem currently is that when using a time based scale, the Y axis either dynamic or static, does not show all of the data properly.
For example, there are events which are 2 seconds long while there are others which are a few hours long. When putting both on the same scale, one ends up either being so small that it cannot be seen or so large that it just shows a huge bar on the graph.

Therefore, we need to convert the time based events to percentages so that a Y axis could work. Then users could mouse over each event to get finer details.

I am not the programmer, I am only looking for leads or input on how this could be done by others who may have done something similar.
projectsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Can you please show us some test data so we can see what we're working with?  Thanks.
projectsAuthor Commented:
Test data such as?
The data is time based events, so when you look at the database, you'll see

start_time
2014-09-11 18:58:12

and

end_time
2014-09-11 18:58:14

As you can see, the above is 2 seconds. The data is just that, but the time can range between seconds to hours.

Using nvd3, we need to show each of these events in a graph but since the range is go great, the data is not showing up very well as explained in my question. The answer seems to be to convert the time based events into percentages so they can be displayed on a graph properly.
Ray PaseurCommented:
Help me understand how you want to treat the outliers...
What amount of time is the maximum amount of time that would represent 100%?
Do you want a display for amounts of time that are less than 0.5%
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

projectsAuthor Commented:
I don't know any of these things, that's why I posted all of the info I have.
What I can tell you is that the range can be from seconds to hours.
That kind of data doesn't display on a graph so I need to find some alternative way to show this data on a graph.
One lead was using a logarithmic scale which lead to the idea of converting the time based output to percentages instead.

In terms of what to use for percentages, I don't know and is why I posted this question, to get some idea of how others may have dealt with something like this.
Ray PaseurCommented:
Here is how you might deal with it.  Take all of your data and find the largest timespan.  Let that equal 100%, then divide that timespan into all the other data (and multiply by 100) to get a percentage.

Here is another way to deal with it.  Set an arbitrary upper limit, say 1 hour to represent 100%, then divide that timespan into all the other data (and multiply by 100) to get a percentage.  This will allow for percentages greater than 100.

You could also set a lower limit, etc.  The key is to decide what will give you a meaningful visual display.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrzCommented:
there are events which are 2 seconds long while there are others which are a few hours long
I think you need to use a logarithmic scale. You can use JavaScript's Math.log(y) method.  I created the simplest  demonstration code possible with HTML5 canvas. It assumes that you can convert your data into the number of seconds for each event.
<!DOCTYPE html>
<html>
<head>
    <title>Graph Example</title>
    <script type="text/javascript">
        var dataValue = [ 2, 100, 5000, 36000 ];
		var data = [];
        function init() {
		    for(var i =0; i < dataValue.length; i++){
			   data[i] = 10 * Math.log(dataValue[i]);
			}
            var can = document.getElementById("can");
            var ctx = can.getContext("2d");
            ctx.fillStyle = "black";
            for (i = 0; i < 4; i++) {
                ctx.fillRect(i * 100, 10, 20, data[i]);
            }
        }
    </script>
</head>
<body onload="init()">
        <canvas id="can" height="600" width="600"></canvas>
</body>
</html>

Open in new window

Ray PaseurCommented:
Converting the data from ISO-8601 date/time strings to seconds is easy in PHP.  You might use PHP to create the elements of the dataValue array in rrz's example.
<?php
$alpha = '2014-09-11 18:58:12';
$omega = '2014-09-11 18:58:14';
$diff  = strtotime($omega) - strtotime($alpha);
print_r($diff);

Open in new window

projectsAuthor Commented:
time-reports.png
It isn't completed yet but it shows that this was doable. There is a range of 2 seconds to 5 hours on this chart. Amazingly, everything shows just as it should. When the user mouses over any bar, the details show up in an info bubble so this works nicely.

For each duration, we have used the function Math.log
We return a number between 0 and 10
So, our Y axis has a range of 0 to 10

Each bar has more information when you mouse over it for details.
Ray PaseurCommented:
Looks great.  Would you be willing to share the JavaScript and CSS?  Thanks, ~Ray
rrzCommented:
So, our Y axis has a range of 0 to 10
 How does that relate to
There is a range of 2 seconds to 5 hours
?  Why not label it with the actual values?  Look at  
http://en.wikipedia.org/wiki/Semi-log_plot
projectsAuthor Commented:
@rrz; There is no actual relation, it's just a representation of time, as a percentage so that it can be displayed as it is. Otherwise, the 5 hour event for example would be nothing but a huge red bar on the screen. Or I'm not understanding your question.

@ray; I'm sure I can share the code but it's not done yet, including the labels.
I'll revisit this question once it's done.

However, once everything is done, gone over, good as can be, it may very well all end up being open source, free to use. I'm not sure how that will work just yet however. Lots to figure out.
rrzCommented:
There is no actual relation, it's just a representation of time, as a percentage so that it can be displayed as it is.
But, you posted
For each duration, we have used the function Math.log
 So, what is your Y-axis scale?  I was envisioning something similar to  
http://en.wikipedia.org/wiki/Semi-log_plot#Phase_diagram_of_water   
Note the logarithmic scale for pressure.
projectsAuthor Commented:
I don't know yet, we'll work on it later.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.