Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would start by setting the lower and upper bounds of your domain to dynamic values, calculated from your data set. Depending on the structure or your data, d3 has <code>max</code> and <code>min</code> methods that will calculate the max / min values in an array of values.</p> <pre><code>var x = d3.scale.linear().domain([d3.min(data), d3.max(data)]).range([0,w]); </code></pre> <p>If you have some method to update your data, you can add functionality to then redefine <code>x</code> (you might want to attach <code>x</code> to some sort of namespace that is accessible throughout the entire scope of your function) and then recall your line generator (via <code>d3.svg.line()</code>). </p> <h3>UPDATE</h3> <p>Seeing your comments, let me clarify. </p> <p>There are several different ways that you can do this, since d3 is such a low-level library (which I personally think is part of the appeal). In my own work, I use multiple series which conveniently allows me to use the common <em>enter, update and exit</em> model that you see used with other chart types (like a bar chart). But in the most basic terms, here's what you need:</p> <ol> <li>You'll need to initially setup a couple objects: <ul> <li>your SVG container</li> <li>your x and y scales</li> <li>a line generator, not bound to any data <br /><br /></li> </ul></li> <li>Next, you'll use that line generator to initialize an <code>SVG:path</code> element with your dataset</li> <li>Then you'll need to create a means up updating your <code>SVG:path</code> element and scales with new data</li> </ol> <p>Here's a <a href="http://jsfiddle.net/mbeasley183/DbXhL/" rel="nofollow">jsfiddle</a> that demonstrates this, adding new random data every seconds for 10 seconds. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload