Skip to content

Getting transformed data values from a Plot #2290

Answered by Fil
mkfreeman asked this question in Q&A
Discussion options

You must be logged in to vote

Here's what I'd try:

Plot.plot({
  y: { tickFormat: "s" },
  marks: [
    Plot.barY(tidy, {
      x: "state",
      y: "population",
      fill: "age",
      sort: { x: "y", reverse: true },
      render(index, scales, values, dimensions, context, next) {
        const g = next(index, scales, values, dimensions, context);
        g.addEventListener("pointerdown", (event) => {
          const i = event.target.__data__;
          d3.select(context.ownerSVGElement)
            .append("circle")
            .attr("r", 5)
            .attr("fill", "red")
            .attr("cx", values.x[i] + scales.scales.x.bandwidth / 2)
            .attr("cy", values.y2[i]);
        });
        return g;
      

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@mkfreeman
Comment options

Answer selected by mkfreeman
Comment options

You must be logged in to vote
7 replies
@mkfreeman
Comment options

@Fil
Comment options

Fil Feb 27, 2025
Collaborator

@mkfreeman
Comment options

@Fil
Comment options

Fil Feb 28, 2025
Collaborator

@mkfreeman
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants