Skip to content

MouseOver event for entire stacked bar, not each small rectangle in the StackedBarChart #759

@corinnebrady

Description

@corinnebrady

I need to be able to trigger a mouse event from the entire vertical bar of a Stacked Bar Chart.

Currently, if you add onMouseEnter on on <Bar ... it triggers when you mouse over the corresponding colour on each bar (which makes sense), but isn't what I need.

When you add a <Tooltip ... it is able to trigger when on a single bar, which is what I need, but i don't need the Recharts tooltip. I need to be able to call a function that triggers state within my React component. I've played around with trying to manipulate the Tooltip to do what I want, but I can't send down the active state (and the label which i was planning on using to differentiate between which bar was being hovered over) unless I sent it through the Tooltips's content prop as a new component. This doesn't work because you end up leaving the original component and therefor don't have access to its state.

My code:

        <BarChart
          width={205}
          height={275}
          barCategoryGap="25%"
          data={graphData}
          margin={{ top: 20, right: 15, left: 0, bottom: 5 }}
        >
          <XAxis
            dataKey="name"
            tickLine={false}
            tick={<XAxisTick />}
            stroke={color.grey400}
          />
          <Bar
            dataKey="project"
            stackId="a"
            fill={color.blueMedium}
            isAnimationActive={false}
            label={<BarLabel currency={currencySymbol} />}
            onMouseEnter={this.handleShowDivA}
            onMouseLeave={this.handleHideDivA}
          />
          <Bar
            dataKey="reccuring"
            stackId="a"
            fill={color.blueDark}
            isAnimationActive={false}
            onMouseEnter={this.handleShowDivB}
            onMouseLeave={this.handleHideDivB}
          />
        </BarChart>

What currently happens when using onMouseEnter etc:

current mouse events

What I need to happen:

desired mouse events

Does anyone know how to do this? Is it even possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs neededIssues that require documentationfeature requestIssues that are feature requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions