# vega-lite api selectInterval() not working

**URL:** <https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846>\
**Category:** Help\
**Created:** [April 13, 2023, 5:41pm UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846 "2023-04-13T17:41:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![drlynb](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/drlynb/32/2283_2.png) [@drlynb](https://talk.observablehq.com/u/drlynb)\
**Post date:** [April 13, 2023, 5:41pm UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846/1 "2023-04-13T17:41:37Z")

</div>

`I have a small scatterplot that i want to brush in *x* and y*,* but it currently only selects along the *y* axis.` I cannot see what the problem is. Using vl API v5.  
Code:

```auto
{
  const selectBrush = vl.selectInterval();

  return vl
    .markCircle({ stroke: "black", strokeWidth: 1 })
    .width(400)
    .params(selectBrush)
    .title({
      text: "NonViolent Crime Totals by Neighbourhoods Summer 2016",
      subtitle: headerString
    })
    // .title(headerString)
    .data(crimeDensityTotal)

    .encode(
      vl
        .size()
        .fieldQ("population")
        .legend({ orient: "right" })
        .scale({ domain: [0, 50000] }),
      vl
        .y()
        .fieldQ("sqm")
        .title("Square M per person")
        .scale({ domain: [0, 500] }),
      vl
        .x()
        .fieldQ("Offense")
        .aggregate("count")
        .scale({ type: "log" })
        .title("Total Crimes"),
      vl
        .color()
        .scale({ range: OffenseCatColors })
        .legend({ orient: "right" })
        .if( selectBrush, vl.fieldN("Offense Category")).value("lightgrey")
    ).render();
}

```

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [April 13, 2023, 7:52pm UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846/2 "2023-04-13T19:52:45Z")

</div>

Can you share your example as a notebook?

---

<div class="post-metadata">

**Author:** ![drlynb](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/drlynb/32/2283_2.png) [@drlynb](https://talk.observablehq.com/u/drlynb)\
**Post date:** [April 14, 2023, 6:46pm UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846/3 "2023-04-14T18:46:03Z")

</div>

There is a lot in this notebook but the simpler example is at the end as the single (nonfaceted) scatter plot.  
[https://observablehq.com/d/d99dc850cb235a15](https://observablehq.com/d/d99dc850cb235a15)  
Note that neither brush works, not even the solution copied from Jeff Heer’s example.

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [April 14, 2023, 8:38pm UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846/4 "2023-04-14T20:38:43Z")

</div>

Your notebook seems to be private?

---

<div class="post-metadata">

**Author:** ![drlynb](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/drlynb/32/2283_2.png) [@drlynb](https://talk.observablehq.com/u/drlynb)\
**Post date:** [April 14, 2023, 8:49pm UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846/5 "2023-04-14T20:49:41Z")

</div>

Public now

![image001.png](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/1/1bed659d6b80cd860945cdea8868040561cd2082.png)

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [April 15, 2023, 8:25am UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846/6 "2023-04-15T08:25:33Z")

</div>

It seems that you can’t use a selection on an aggregated channel, at least not in multiple views ([see docs](https://vega.github.io/vega-lite/docs/selection.html#current-limitations)):

```js
vl.selectInterval().encodings(["x", "y"])

```

> WARN Cannot project a selection on encoding channel “y” as it uses an aggregate function (“count”).

---

<div class="post-metadata">

**Author:** ![drlynb](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/drlynb/32/2283_2.png) [@drlynb](https://talk.observablehq.com/u/drlynb)\
**Post date:** [April 16, 2023, 7:50pm UTC](https://talk.observablehq.com/t/vega-lite-api-selectinterval-not-working/7846/7 "2023-04-16T19:50:19Z")

</div>

Thank you! That seems very limiting.
