Last active
August 29, 2015 13:57
-
-
Save skamithi/9868051 to your computer and use it in GitHub Desktop.
express app.js example in CoffeeScript showing how to render D3 output.
This file contains hidden or 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
# 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