Created on September 23, 2014 02:46 | Updated about 6 years ago

**Link:** https://gist.github.com/jywarren/3791c67384c88d53f155

Calculate center of area for a graph -- draws a vertical line which bisects the area of the graph equally

// calculate center of area for a graph -- draws a vertical line which bisects the area of the graph equally setup: function() { // code to run on startup flotoptions.grid.markings = [] var color_count = 0 // go through each spectrum $.each($W.data,function(index,spectrum){ // calculate total area: var area = 0 $.each(spectrum.data,function(i,v){ area += v[1] }) // now find the halfway point var count = 0 $W.colors = flotoptions.colors $.each(spectrum.data,function(i,v){ if (count < area/2) { count += v[1] } else { // draw markers: color = flotoptions.colors[color_count] color_count += 1 flotoptions.grid.markings.push({ color: color, lineWidth: 1, xaxis: { from: v[0], to: v[0] } }); return false } }) }) $W.plot = $.plot($("#graph"),$W.data,flotoptions); }, draw: function() { // code to run every frame }