Refactored JS graphing code.
Added NaN check to prevent division-by-zero bug.