angular2-google-chart
angular2-google-chart copied to clipboard
This is how I successfully integrate this module to my angular2 project with Angular-CLI
Thank you for creating this wonderful NPM module. I am sharing my experience to benefit others.
Use angular2-google-chart
- npm i angular2-google-chart
- Index.html has
- App.component.ts import {GoogleChart} from 'angular2-google-chart/directives/angular2-google-chart.directive';
- App.module.ts import {GoogleChart} from 'angular2-google-chart/directives/angular2-google-chart.directive';
@NgModule({ declarations: [ AppComponent, GoogleChart ],
Includes Timeline chart in app.component.html, I have
Timeline Charts
in app.component.ts , I have
public timeline_ChartData ={
cols: [
{type: 'string', id: 'Executor'},
{type: 'string', id: 'Name'},
{type: 'string', id: 'Tooltip', role: 'tooltip', p: {html: true}},
{type: 'date', id: 'start_date'},
{type: 'date', id: 'finish_date'},
],
rows: [
{c:[{v: 'A'}, {v: 'John'}, {v: 'John Doe'}, {v: new Date(2016, 7, 31)}, {v: new Date(2016, 8, 1)}]},
{c:[{v: 'A'}, {v: 'Jane'}, {v: 'Jane Doe'}, {v: new Date(2016, 7, 27)}, {v: new Date(2016, 7, 31)}]},
{c:[{v: 'B'}, {v: 'John'}, {v: 'John Doe'}, {v: new Date(2016, 7, 30)}, {v: new Date(2016, 8, 1)}]},
{c:[{v: 'B'}, {v: 'Jane'}, {v: 'Jane Doe'}, {v: new Date(2016, 7, 29)}, {v: new Date(2016, 8, 5)}]},
{c:[{v: 'C'}, {v: 'John'}, {v: 'John Doe'}, {v: new Date(2016, 7, 25)}, {v: new Date(2016, 7, 29)}]},
{c:[{v: 'C'}, {v: 'Jane'}, {v: 'Jane Doe'}, {v: new Date(2016, 7, 27)}, {v: new Date(2016, 8, 1)}]},
{c:[{v: 'C'}, {v: 'Fred'}, {v: 'Fred Doe'}, {v: new Date(2016, 7, 21)}, {v: new Date(2016, 7, 26)}]}
]
};
public timeline_ChartOption={ timeline: { colorByRowLabel: true }, backgroundColor: '#ffd', tooltip: {isHtml: true}, width: '100%', height: '600px', chartArea: { width: '80%', height: '80%' }, colors: ['red', 'blue', 'green'], avoidOverlappingGridLines: true };
This helped me a lot. Just going to clean up some of what you wrote for others to see...
-
npm install angular2-google-chart
- In index.html add the following between the header tags:
<script src="https://www.gstatic.com/charts/loader.js"></script> <script> var googleLoaded = false; </script>
- In app.module.ts and app.component.ts add:
import {GoogleChart} from 'angular2-google-chart/directives/angular2-google-chart.directive';
- Add GoogleChart to your declarations in app.module.ts
@NgModule({ declarations: [ AppComponent, GoogleChart ],
- In app.component.html I have:
<div id="pie_chart" [chartData]="pie_ChartData" [chartOptions]="pie_ChartOptions" chartType="PieChart" GoogleChart></div>
- In app.component.ts I have:
public pie_ChartData = [ ['Task', 'Hours per Day'], ['Work', 11], ['Eat', 2], ['Commute', 2], ['Watch TV', 2], ['Sleep', 7] ];
public pie_ChartOptions = { title: 'My Daily Activities', width: 400, height: 400 };
Thank you. Could someone post this to the overview page?
I have followed the same steps in my application, but getting error like
I'm using barChart, I need to wrap the text from the x-axis, which options should I use to overcome this? here is the screenshot of it : https://prnt.sc/gq6wuq