Skip to content

Instantly share code, notes, and snippets.

@skamithi
Last active August 29, 2015 13:57
Show Gist options
  • Save skamithi/9868051 to your computer and use it in GitHub Desktop.
Save skamithi/9868051 to your computer and use it in GitHub Desktop.
express app.js example in CoffeeScript showing how to render D3 output.
# very new to node.js and express.
# very excited to play with server side rendering of SVG.
# If this simple example can be improved pls put your comments.
express = require('express')
d3 = require('d3')
draw_divs = ->
dataset = [ 5, 10, 15, 20, 25 ]
d3.select("body").selectAll("div")
.data(dataset)
.enter()
.append("div")
.attr("class", "bar")
.style
'background-color': 'red'
'height': (d) ->
d + "px"
'width': '25px'
'display': 'inline-block'
'margin-right': '5px'
# produces <html>..simple bar chart..</html>
d3.select('html').node().outerHTML
app = express()
app.get '/', (req, res) ->
res.send(draw_divs())
app.listen 3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment