You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+45Lines changed: 45 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,51 @@ Chart.js
2
2
=======
3
3
*Simple HTML5 Charts using the canvas element*[chartjs.org](http://www.chartjs.org)
4
4
5
+
## Changes
6
+
This adds a mouseover and mouseout event to the data points in a line graph (events for all graphs may follow shortly). I implemented because I needed to implement tooltips for the data points, but you can use the event to do whatever you like.
7
+
8
+
To hook into the events, just specify a mouseover and mouseout event handler for your dataset. This works for browser mouse events as well as mobile touch events.
9
+
```javascript
10
+
var data = {
11
+
labels : labels,
12
+
datasets : [
13
+
{
14
+
fillColor :"rgba(151,187,205,0.5)",
15
+
strokeColor :"rgba(151,187,205,1)",
16
+
pointColor :"rgba(151,187,205,1)",
17
+
pointStrokeColor :"#fff",
18
+
data : values,
19
+
mouseover:function(data) {
20
+
// data returns details about the point hovered, such as x and y position and index, as
21
+
// well as details about the hover event in data.event
22
+
// You can do whatever you like here, but here is a sample implementation of a tooltip
23
+
var active_value = values[data.point.dataPointIndex];
24
+
var active_date = labels[data.point.dataPointIndex];
25
+
// For details about where this tooltip came from, read below
var ctx =document.getElementById("myCanvasElement").getContext("2d");
37
+
var chart =newChart(ctx).Line(data);
38
+
```
39
+
40
+
As you can see above, we can easily add an HTML tooltip to the data point by using the x and y position of the point hovered. Above, I offset the tooltip by a few pixels, position it absolutely, and format using plain old CSS/HTML. The absolute position works because I wrap my canvas in a relative div and put the tooltip as a sibling to the canvas:
0 commit comments