Created
June 5, 2013 07:20
-
-
Save mrtimp/5712156 to your computer and use it in GitHub Desktop.
Auto scale the yAxis with Flot and the selectable plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#placeholder").bind("plotselected", function (event, ranges) { | |
var ymin, ymax; | |
var plotdata = plot.getData(); | |
$.each(plotdata, function (e, val) { | |
$.each(val.data, function (e1, val1) { | |
if ((val1[0] >= ranges.xaxis.from) && (val1[0] <= ranges.xaxis.to)) { | |
if (ymax == null || val1[1] > ymax) ymax = val1[1]; | |
if (ymin == null || val1[1] < ymin) ymin = val1[1]; | |
} | |
}) | |
}); | |
$.plot("#placeholder", plotdata, $.extend(true, {}, options, { | |
xaxis: { | |
min: ranges.xaxis.from, | |
max: ranges.xaxis.to | |
}, | |
yaxis: { | |
min: ymin - 10, | |
max: ymax + 10 | |
} | |
})); | |
overview.setSelection(ranges, true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few minor sugestion:
I would sugest rescaling the y axis as a percentage, instead of a constant. And setting the ymin to 0 if it's positive.