Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate the y-axis of a brushed area chart
    primarykey
    data
    text
    <p>I am using d3.js, and I'm working on a brushed area chart by modifying <a href="http://bl.ocks.org/1667367">this example</a>. In addition to the x-axis changing based on the brush, I'd like chart's y-axis to be redrawn, based on the y-values of the data that fall within the brush (similar to the behavior of <a href="http://www.google.com/finance?q=INDEXDJX%3a.DJI,INDEXSP%3a.INX,INDEXNASDAQ%3a.IXIC&amp;ei=qCnTULiiJqut0AGYiQE">a Google Finance chart</a>).</p> <p>I have gotten the functionality working, but only in a way that enables the brush to be drawn in both x- and y-space. I did this by first adding a y scale to the <code>brush</code> variable:</p> <pre><code>var brush = d3.svg.brush() .x(x2) .y(y2) .on("brush", brush); </code></pre> <p>This makes <code>brush.extent()</code> return the following multi-dimensional array: <code>[ [x0, y0], [x1, y1] ]</code>. I then use this data in the <code>brush()</code> function to redefine the x- and y- domain for the focus chart:</p> <pre><code>function brush() { var extent = brush.extent(); x.domain(brush.empty() ? x2.domain() : [ extent[0][0], extent[1][0] ]); y.domain(brush.empty() ? y2.domain() : [ extent[0][1], extent[1][1] ]); focus.select("path").attr("d", area); focus.select(".x.axis").call(xAxis); focus.select(".y.axis").call(yAxis); } </code></pre> <p>This works, but by defining the y scale in the brush variable, the user can now drag 'boxes' in the focus chart, rather than only being able to drag west to east, as in the original chart.</p> <p>Essentially, my question is: <strong>how do I get the range of values that fall within a brush's area, rather than the range of the brush's area itself?</strong> Is this even possible?</p> <p>d3's brush documentation is <a href="https://github.com/mbostock/d3/wiki/SVG-Controls#wiki-brush">here</a>.</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. 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