Geetha R.
asked 09/18/18implementing a graph which overlays a image whenever we hover over the coordinates
2 Answers By Expert Tutors
Dayaan M. answered 9d
Bachelors in Computer Science and certified in responsive web design
There are two main ways to implement a graph which overlays an image whenever we hover over the coordinates:
1) Using a chart library
This would be the easiest and most efficient approach. Libraries like Chart.js, ApexCharts, Highcharts, Plotly let you detect hovered points and show custom content.
For each graph point you can store:
- x value
- y value
- image URL
- option title / description
Then on hover, display the corresponding image
2) Using HTML canvas or SVG manually
You can draw the graph yourself and listen for mouse events like:
- mousemove
- click
Then check whether the mouse is close to a coordinate and show the image. This gives more control, but it is harder than using a chart library.
Matt G. answered 02/15/23
Full-Stack Software Engineer Specializing in Javascript & GraphQL
Hi Geetha,
There are many options for rendering a graph using Javascript and PHP. Some popular libraries include:
- C3.js
- Chart.js
- Highcharts
Once you've chosen which library works best for you then you can check it's documentation for `tooltip`. In C3 for example, it's not as beginner friendly but its very customizable.
For Chart.js for example, you can pass `customTooltips` and replace the `innerHtml` with an `img` tag with the `src` being the image you want to overlay. You can programmatically change the image based upon the data that is passed into the argument of the `customTooltips` function.
Hope this helps.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Shaquon K.
Are you making a webpage that is showing the graph? Also, how are you using PHP in this case? I'm asking because I'll need to know more info to really give a good answer.11/02/22