1
<!DOCTYPE html>
<html>
<head>
 <script type="text/javascript" src="d3/d3.min.js"></script>
</head>
<body>

<script type="text/javascript">
    var dataA=[10,20];
    d3.select("body").style("background-color", "green");

    var canvas = d3.select("body")
                   .append("svg")
                   .attr("width",500)
                   .attr("height",500);

    var bars = canvas.selectAll("rect")
                     .data(dataA)
                     .enter()
                     .append("rect")
                     .attr("width",function (d){ return d*5;})
                     .attr("height",10)
                     .attr("y",function(d,i){ return i*20;});

</script>

</body>

This is the code I used for drawing a bar char in d3. how can I use node.js to do the same chart?

3
  • You want to render this chart server-side? Use PhantomJS for that. Commented Aug 9, 2015 at 5:34
  • is it possible that way? or can i draw this chart only using node js? Commented Aug 9, 2015 at 5:37
  • You only need to render the data variable in a template with Node.js, then D3 library will do the rest. What's your Node.js code? Commented Aug 9, 2015 at 6:52

1 Answer 1

1

The question is not clear enough, whether you want to just use node or node as a server and a client code. But still, you can go ahead with the two use cases given below.

  1. Server side scripting to generate a chart and take a snapshot: I think yes, you can use node and phantomjs and node_phantomjs
  2. If you have both client and server side code: You can render you web page using node and expressjs

You can keep your D3 code as it is. But, if you want to play with dynamic data being sent from the server, just have a look at full fledged MEAN framework.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you I render d3 code using ejs.it works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.