Custom Tooltip opacity always 1
See original GitHub issueI need to have custom Tooltip and I design a react-component using hooks, check out the code:
import {Line} from "react-chartjs-2";
import {Button} from "reactstrap";
import React, {useState, useRef} from "react";
// noinspection ES6UnusedImports
// eslint-disable-next-line no-unused-vars
// import Drag from "../DraggableChart";
export default function ProgramChart({data}) {
const [tooltipData, setTooltipData] = useState(null);
const chartRef = useRef(null);
return (
<div>
<Line
ref={chartRef}
options={{
legend: {
display: false
},
tooltips: {
"enabled": false,
"mode": "point",
"intersect": false,
custom: (tooltipModel) => {
// hide tooltip if needed
if (tooltipModel.opacity === 0) {
setTooltipData(null);
console.log("Hide tooltip");
return;
}
const chart = chartRef.current.chartInstance;
const canvas = chart.ctx.canvas;
if (canvas) {
const position = canvas.getBoundingClientRect();
// set position of tooltip
const left = position.left + tooltipModel.caretX;
const top = position.top + tooltipModel.caretY;
setTooltipData({top, left});
}
}
},
}}
data={chartData}
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
textAlign: "center",
flex: 1,
height: "100%",
}}/>
{tooltipData ? <GraphTooltip data={tooltipData}/> : <div/>}
</div>
);
};
const GraphTooltip = ({data}) => <div
style={{
padding: 20,
position: "fixed",
border: "1px solid",
borderColor: "#fff8f9",
backgroundColor: "rgba(53,53,53,0.81)",
borderRadius: 4,
top: data.top,
left: data.left,
}}
>
<Button>Whatever</Button>
</div>;
Tooltip is rendered but it never disappear!
If I remove setTooltipData({top, left});
line than there are no problem…
Have anyone any idea?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:9
Top Results From Across the Web
custom tooltip opacity always 1 - Stack Overflow
opacity === 0) { // never called because opacity is always 1 this.hide(); return; } // const position = this.chartRef.current.chartInstance.
Read more >Custom Tooltip opacity always 1 · Issue #450 - GitHub
I need to have custom Tooltip and I design a react-component using hooks, check out the code: ... opacity === 0) { setTooltipData(null);...
Read more >Developers - Custom Tooltip opacity always 1 - - Bountysource
I need to have custom Tooltip and I design a react-component using hooks, check out the code: import {Line} from "react-chartjs-2"; import {Button}...
Read more >Tooltip - Chart.js
The bubble, doughnut, pie, polar area, and scatter charts override the tooltip defaults. To change the overrides for those chart types, ...
Read more >Tooltips · Bootstrap v5.0
Documentation and examples for adding custom Bootstrap tooltips with CSS and ... One way to initialize all tooltips on a page would be...
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
I decided to take it out due to having issues creating my own that looked nice but I found what I used that worked.
And then I called it in the options:
From what I remember, not defining the
customTooltip
with auseCallback
gave the error where opacity did not change. Hope it helps!The only workaround which works for me is using test-react-chartjs2