/**
* Initiates Graph Functions
* See: http://jsfiddle.net/jenniferperrin/ntAbz/
**/
function egraph($graph_id, $lines, $bar_margins, $bar_speed, $animate) {
var self = this; // create graph object
var graphid = $graph_id; // id of graph container, example "graph1" or "myGraph"
var values = new Array(); // array of values
var heights = new Array(); // array of bar heights
var colors = new Array(); // colors for bars
var lines = $lines; // number of lines - keep this 10 unless you want to write a bunch more code
var bm = $bar_margins; // margins between the bars
var mx = 0; // highest number, or rounded up number
var gw = $('#' + graphid + ' .graph').width(); // graph width
var gh = $('#' + graphid + ' .graph').height(); // graph height
var speed = $bar_speed; // speed for bar animation in milliseconds
var animate = ($animate != undefined && $animate == true) ? true : false; // determines if animation on bars are run, set to FALSE if multiple charts
/**
* Gets the values & colors from the HTML <labels> and saves them into $v ohject
**/
var getValues = function() {
var lbls = $('#' + graphid + ' .values span');
// loop through
for (i = 0; i <= lbls.length - 1; i++) {
var vals = parseFloat(lbls.eq(i).text());
colors.push(lbls.eq(i).css('background-color'));
mx = (vals > mx) ? vals : mx;
values.push(vals);
}
}
/**
* A Simple Round Up Function
**/
var roundUp = function(num, rr) {
return ((num % rr) > 0) ? num - (num % rr) + rr : num;
}
/**
* Makes the HTML for the lines on the chart, and places them into the page.
**/
var graphLines = function() {
var r = (mx < 100) ? 10 : 100; // determine to round up to 10 or 100
mx = roundUp(mx, r); // round up to get the max number for lines on chart
var d = mx / lines; // determines the increment for the...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.