Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created February 24, 2011 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsiii/842175 to your computer and use it in GitHub Desktop.
Save jfsiii/842175 to your computer and use it in GitHub Desktop.
require("jsdom").env({
html: "<html><body></body></html>",
scripts: [
'http://code.jquery.com/jquery-1.5.min.js',
'http://jsno.de/javascripts/jquery.flot.svn.js', // please don't hotlink
'http://jsno.de/javascripts/jquery.flot.text.js' // please don't hotlink
],
done: function (errors, window)
{
var i, d1 = [], d2 = [], d3 = [];
for (i = 10; --i;) d1.push([i, parseInt(Math.random() * 30)]);
for (i = 10; --i;) d2.push([i, parseInt(Math.random() * 30)]);
for (i = 10; --i;) d3.push([i, parseInt(Math.random() * 30)]);
var line_opts = { show: false, fill: true, steps: false };
var bars_opts = { show: true, barWidth: 0.6 };
var data = [
{ label: "sweet", data: d1, lines: line_opts, bars: bars_opts },
{ label: "bars", data: d2, lines: line_opts, bars: bars_opts },
{ label: "bro", data: d3, lines: line_opts, bars: bars_opts }
],
options = {
width: 600, height: 300,
xaxis: { labelWidth: 50, labelHeight: 20 },
yaxis: { labelWidth: 50, labelHeight: 20 },
grid: {
backgroundColor: "#eee",
canvasText: { show: true, font: "sans 9px" }, // for text plugin
clickable: false, hoverable: false // non-interactive
}
},
$ = window.$,
jQuery = window.jQuery,
$div = $('div'),
$plot = $.plot($div, data, options),
canvas = $plot.getCanvas(),
dir = '/home/jfsiii/webapps/node_flot/public/',
name = 'jsdom.png',
loc = dir + name,
fs = require('fs'),
out = fs.createWriteStream(loc);
canvas
.createPNGStream()
.on('data', function (chunk) { out.write(chunk); })
}
});
@GoldenStake
Copy link

I hope this project isn't too depreciated, but I'm having trouble finding the to the flot files.
I found a diff of yours but it seems to be old. I was wondering if you had any advice to modifying the flot files, and other modules to work with node.js
or still follow the diff from https://gist.github.com/708172

Thanks, It seems like you are the only person to have created a working server-side Flot.

@rlt
Copy link

rlt commented Jul 18, 2011

When running this I receive the error TypeError: Cannot call method 'replace' of undefined

Using node-inspector I found that $.plot is undefined. I'm using jsdom 0.2.0 & node 0.4.9.

Any ideas what might be causing this?

@jfsiii
Copy link
Author

jfsiii commented Nov 14, 2011

@GoldenStake, @rlt can you take a look at this Flot on node-canvas gist and let me know if you're still having issues?

BTW, @GoldenStake, created a patch for Flot 0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment