From 737a857ce8f71281276467666b13ff8c3847a7ec Mon Sep 17 00:00:00 2001 From: Duncan Walker Date: Mon, 10 Sep 2018 00:56:26 -0400 Subject: [PATCH] Documentation added for events. Fixes #26. --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index f786e99..011470a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ See the [demo app](http://sir-dunxalot.github.io/ember-google-charts/) here. - [Actions](#actions) - [chartDidRender()](#chartdidrender) - [packagesDidLoad()](#packagesdidload) +- [Events](#events) - [Custom Charts](#custom-charts) - [Content Security Policy](#content-security-policy) - [Testing](#testing) @@ -284,6 +285,42 @@ export default Controller.extend({ }} ``` +### Events + +It's easy to listen to events emitted by a chart: + +```js +/* stats/controller.js */ + +import Controller from '@ember/controller'; + +export default Controller.extend({ + + actions: { + addChartEventListeners(chart) { + const { google: { visualization } } = window; + + visualization.events.addListener(chart, 'onmouseover', function(event) { + /* Do something here... */; + }); + } + }, + +}); +``` + +```hbs +{{!-- stats/template.hbs --}} + +{{line-chart + data=data + options=options + chartDidRender=(action 'addChartEventListeners') +}} +``` + +For more information on events, see the [Google Charts event documentation](https://developers.google.com/chart/interactive/docs/events). + ### Custom Charts All chart components in this addon extend from a single core component: the `GoogleChartComponent`.