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.

Show tooltip on hover

See original GitHub issue

How make it?

https://s.mail.ru/37sz/fwFzs6Lrx

I try

{data.map((e, i) =>
  <Bar
    dataKey={e}
    fill={lib.getRandomColor()}
    onMouseOver={((e) => {console.log(e)})}
    { ...columnChartToBarChart == false ? {stackId: 'a'} : {}}
    key={i}
    label={(obj) => this.renderCustomLabel(obj, e, i)} />
)}

renderCustomLabel(obj, label, index) {
  let { showTopLabel, columnChartHoveredBar } = this.state;
  let { x, y, height, width } = obj;

  if (+obj.payload[label] <= 0) return null;
  if (height < 30) return null;
  if (width < 50) return null;

  return <text
    key={index * index}
    x={x}
    y={y}
    dy={-4}
    fill={"#333"}
    // transform="rotate(-35)"
    // { ...showTopLabel == false ? {transform: "rotate(-35)"} : {} }
    fontSize={14}
    textAnchor="middle">
      {obj.payload[label]}
    </text>
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rajatkanthaliya12commented, May 9, 2019

Using below logic you can achieve individual tool-tip for each dot.

Demo Link: Line chart with custom Tooltip

  1. Hide default Tooltip

    <Tooltip cursor={false} wrapperStyle={{ display: “none” }} />

  2. Add mouse event function on Line (when dot is active)

     <Line
           activeDot={{
             onMouseOver: this.showToolTip,
             onMouseLeave: this.hideToolTip
           }}
          ....
         />
    
  3. custom tooltip div

       <div className="ui-chart-tooltip" ref={ref => (this.tooltip = ref)} >
           <div className="ui-chart-tooltip-content" />
       </div>
    
  4. showToolTip and hideTooltip Function

          showToolTip = (e) => {
           let x = Math.round(e.cx);
           let y = Math.round(e.cy);
           this.tooltip.style.opacity = "1";
           this.tooltip.childNode[0].innerHTML = e.payload["value"];
    
           };
    
           hideTooltip = e => {
           this.tooltip.style.opacity = "0";
           };
    
0reactions
taner-yilmazcommented, Apr 12, 2022

Line chart with custom Tooltip

I solved it another way 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Tooltip - W3Schools
The :hover selector is used to show the tooltip text when the user moves the mouse over the <div> with class="tooltip" . Positioning...
Read more >
What is the easiest way to create an HTML mouseover tool tip?
Show activity on this post. The easiest way is to use the native HTML title attribute: <img src="https://stackoverflow.com/favicon.ico" ...
Read more >
How to Create an HTML Tooltip [+ Code Templates]
A tooltip is a user interface component containing text that appears when a user hovers their cursor over an element. A tooltip usually...
Read more >
HTML Tooltip | How to Add Tooltip in HTML with examples?
Tooltip is a concept used in HTML for showing some extra information about the specifically selected element. This can be done on the...
Read more >
Simple Tooltips On Hover | HTML & CSS Tutorial - YouTube
Create simple tooltips on links that appear on hover using HTML and CSS.
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