Bar #onClick handler should also work for the Label of that Bar
See original GitHub issuehey there,
I use the Vertical Barchart Component. The Bar#onClick handler works like expected. But when I have a Label on top of the Bar, clicking on the label won’t call the onClick handler with the bar data. Check the attached screen, you can imagine, that clicking on the bar works, but clicking on the label does not, confuses quite a lot of Users.
Thus I would propose: the Bar onClick handler gets also triggered when the respective label is clicked.
Code that produces above Chart.
<BarChart data={data} layout='vertical' gapSize={10}>
<XAxis type="number" orientation='bottom' hide={false} domain={[0, this.state.max]} allowDecimals={false}>
<Label value="Anzahl der Meldungen" offset={-2} position="insideBottomRight" />
</XAxis>
<CartesianGrid strokeDasharray="3 3" horizontal={false}/>
<Bar dataKey="value" fill="#155a89" barSize={25} onClick={data=>this.handleClick(data)}>
<LabelList valueAccessor={i => i.label+' ('+i.value+')'} position='insideLeft' width={800} style={ {textShadow:'1px 1px 1px #000',fill:"#f5f5f6"} }/>
</Bar>
<YAxis type="category" hide={true}/>
</BarChart>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:8
Top Results From Across the Web
Chart.js: Bar Chart Click Events - Stack Overflow
barLabel is the label of the clicked bar. You need to pass the onClick to the bar chart config: const barConfig = {...
Read more >ChartJs onClick event - is it possible? #2614 - KoolReport
Hi, I need to make the labels on a few ChartJs charts clickable (and later bars on a stacked bar charts), but all...
Read more >click - Sets Click Event Handler for Data Series - CanvasJS.com
Sets the click event handler for dataSeries which is triggered when user clicks on a dataSeries. Upon event, a parameter that contains event...
Read more >Bar Charts | Google Developers
In this section, we'll see how to put labels inside (or near) the bars in a bar chart. Let's say we wanted to...
Read more >Forms in HTML documents - W3C
When the type attribute has the value "radio" or "checkbox", this boolean attribute specifies that the button is on. User agents must ignore...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A dirty fix for this issue is to add the “pointer-events: none” css-style to allow for clicking trough the label:
<LabelList dataKey="tooltip" style={{pointerEvents: 'none'}}/>
I ran into the same issue and would appreciate a solution 👍