ng2-google-charts
Google Charts module for Angular 2
Please see this page for a live demo.
Install
npm i --save ng2-google-charts
Usage
Import the Ng2GoogleChartsModule
in your app.module.ts
:
;
In your templates, use the google-chart
component like this:
and in the corresponding .ts
file:
pieChartData =;
Formatters
You can specify an array of multiple formatter types and configurations like this:
public tableChartData =;
Please refer to the Google Chart documentation for formatter types and options.
Please see this page for a demo with more examples.
Events
chartReady
The chartReady
event is fired when a chart is completely loaded.
Bind the chartReady
event in the google-chart
component like this:
Your ready()
function is passed an event whose interface looks like this:
You can import the ChartReadyEvent
interface in your .ts
file:
;
and then use it like:
public readyevent: ChartReadyEvent
chartError
The chartError
event is fired if there are some errors with a chart.
Bind the chartError
event in the google-chart
component, like this:
Your error()
function is passed an event whose interface looks like this:
You can import the ChartErrorEvent
interface in your .ts
file:
;
and then use it like:
public errorevent: ChartErrorEvent
See more details about returned values for error event.
chartSelect
The chartSelect
event is fired when a chart is selected/clicked.
Bind the chartSelect
event in the google-chart
component, like this:
Your select()
function is passed an event whose interface looks like this:
You can import the ChartSelectEvent
interface in your .ts
file:
;
and then use it like:
public selectevent: ChartSelectEvent
mouseOver
The mouseOver
event is fired when the user moves the mouse over some chart
item.
Bind the MouseOver
event in the google-chart
component like this:
Your mouseOver()
function is passed an event whose class looks like this:
You can import the ChartMouseOverEvent
class in your .ts
file:
;
and then use it like:
public mouseOverevent: ChartMouseOverEvent
mouseOut
The mouseOut
event is fired when the user moves the mouse out of some chart
item.
Bind the MouseOut
event in the google-chart
component like this:
Your mouseOut()
function is passed an event whose class looks like this:
You can import the ChartMouseOutEvent
class in your .ts
file:
;
and then use it like:
public mouseOutevent: ChartMouseOutEvent
Advanced usage
You can access Google Chart's underlying ChartWrapper through the
wrapper
property of the component object:
;