question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bar #onClick handler should also work for the Label of that Bar

See original GitHub issue

hey 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. image

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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

7reactions
DigidragonZXcommented, Jun 8, 2018

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'}}/>

7reactions
PatrickProcommented, Mar 9, 2018

I ran into the same issue and would appreciate a solution 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found