# Plot: Data Items from Stacked Bar

**URL:** <https://talk.observablehq.com/t/plot-data-items-from-stacked-bar/5733>\
**Category:** Help\
**Created:** [October 21, 2021, 12:24pm UTC](https://talk.observablehq.com/t/plot-data-items-from-stacked-bar/5733 "2021-10-21T12:24:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChrisWoodsSays](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/chriswoodssays/32/3754_2.png) [@ChrisWoodsSays](https://talk.observablehq.com/u/ChrisWoodsSays)\
**Post date:** [October 21, 2021, 12:24pm UTC](https://talk.observablehq.com/t/plot-data-items-from-stacked-bar/5733/1 "2021-10-21T12:24:52Z")

</div>

In the attached notebook, I have a bar chart built with plot and @mkfreeman’s [@mkfreeman/plot-tooltip](https://observablehq.com/@mkfreeman/plot-tooltip).

I want to provide a tooltip showing the `consumption_grade` which should apply to any given stacked element. I say stacked, as the fill is taken from `consumption_grade`, however it doesn’t appear stacked (which is fine) as each consumption\_grade happens to fall into different bins.

However, the tooltip is showing as undefined, I expect due to `(d) =>Consumption Grade: ${d.consumption_grade}` not being grouped correctly.

> **[Carbon Calculator Map - CO2 Consumption Ratings vs Population](https://observablehq.com/@chriswoodssays/carbon_ratings_vs_population)**
>
> Initial Analysis There appears to be a correlation between an Lower Layer Super Output Area's population and the CO2 consumption per capita F- rated LSOAs (worst 1%) appear to have populations less than while A+ LSOAs (best 1%) have populations...

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [October 21, 2021, 12:51pm UTC](https://talk.observablehq.com/t/plot-data-items-from-stacked-bar/5733/2 "2021-10-21T12:51:16Z")

</div>

You need to reduce the title, too. You can pull out the first value for each bin like so:

```auto
Plot.binX({y: "count", title: "first"}, …)

```

Alternatively you can definite your title as a reducer where it is passed the data for each bin, so if you want to pull out the first data point for each bin e.g.:

```auto
Plot.binX({y: "count", title: ([d]) => d.consumption_grade}, …)

```

---

<div class="post-metadata">

**Author:** ![ChrisWoodsSays](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/chriswoodssays/32/3754_2.png) [@ChrisWoodsSays](https://talk.observablehq.com/u/ChrisWoodsSays)\
**Post date:** [October 21, 2021, 3:36pm UTC](https://talk.observablehq.com/t/plot-data-items-from-stacked-bar/5733/3 "2021-10-21T15:36:36Z")

</div>

Thanks @mbostock
