Custom events allow you to easily interact with and extend RGraph for your own purposes. The list of available events is below, as is an example of how to make use of them with the RGraph.AddCustomEventListener() function. Event handler functions (ie your functions) are passed a single parameter - the chart object. With this you can get references to the canvas and context. There's an example of this below.
<script> window.onload = function () { var line = new RGraph.Line('myLine', [45,12,16,18,44,54,23,21,56]); line.Set('chart.tooltips', ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev']); line.Set('chart.labels', ['Fred', 'Barney', 'Jay', 'Pete', 'Frank', 'Bob', 'Ted', 'Lou', 'Kev']); line.Set('chart.hmargin', 5); line.Set('chart.tickmarks', 'dot'); line.Draw(); /** * This is the call to the RGraph function that registers the event listener * * line: The chart object * ontooltip: The name of the event * myFunc: The function that handles the event */ RGraph.AddCustomEventListener(line, 'ontooltip', myFunc); } /** * The function that is called when the ontooltip event fires. It is passed a single parameter - the chart object. * With this you can get the ID and references to the canvas and context: * o obj.id * o obj.canvas * o obj.context */ function myFunc(obj) { var id = obj.id; var canvas = obj.canvas; var context = obj.context; alert('This alert was triggered by the custom ontooltip event'); } </script>
ModalDialog.AddCustomEventListener('onmodaldialog', function () {alert('Hello world!');});
In the case that you need to remove RGraph event listeners, there are a few ways that you can do it. The API function RGraph.RemoveCustomEventListener(obj, id) can be used to remove a single event listener. This function takes the chart object and the numerical ID (returned by RGraph.AddCustomEventListener()) as its arguments.
There's also the RGraph.RemoveAllCustomEventListeners(), for easily removing all of the pertinent event listeners. This function can either take no arguments at all, in which case ALL event listeners for ALL objects are removed. Or it can also take a canvas ID (the same id that you pass to the constructor), in which case the removal will be limited to that canvas.