Hi Team,
Could you please guide on ,how to i use charts(bar) in my angular2 cli project.I am new to angular .Please guide me from scratch.
Thanks and regards
Venky
Did you manage to display any other charts with RC4 ?
It does not render from my side.
Same here , with rc4 there is no error but the charts does not appear in the browser
I have even tried to render simple canvas but no luck, may be it is angular2 rc.4 issue.
Working fine with angular2 rc4.
Used chart.js version is 2.1.3
Please can you explain more ? I'm new in using angular 2 and I don't get it
<body>
<my-app>Loading...</my-app>
<script src="assets/js/Chart.min.js"></script>
<script src="assets/js/Chart.bundle.min.js"></script>
</body>
doughnut chartimport { Component, Input } from '@angular/core'
import { ROUTER_DIRECTIVES } from '@angular/router'
import { CORE_DIRECTIVES, NgClass } from '@angular/common'
import { CHART_DIRECTIVES } from 'ng2-charts'
const template = require('./my-com.component.html')
const style = require('./my-com.component.css').toString()
@Component({
selector: 'my-comp',
template: template,
styles: [style],
directives: [ROUTER_DIRECTIVES, CHART_DIRECTIVES, CORE_DIRECTIVES, NgClass]
})
export class MyComp {
// Doughnut
public doughnutChartType:string = 'doughnut'
public doughnutChartLegend:boolean = false
public doughnutColors:any[] = [{ backgroundColor: ['#1ABB9C', '#E74C3C', '#9CC2CB'] }]
// Some data - depending on your case
public doughnutChartLabels:string[] = ['Passed', 'Failed', 'Not Assessed']
public doughnutChartData:number[] = [4, 5, 15]
// events
public chartClicked(e:any):void {
console.log(e);
}
public chartHovered(e:any):void {
console.log(e);
}
}
<base-chart class="chart"
[data]="doughnutChartData"
[labels]="doughnutChartLabels"
[legend]="doughnutChartLegend"
[colors]="doughnutColors"
[chartType]="doughnutChartType"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"></base-chart>
Hope it is more clear ;-)
thank you for your help @sahlouls but the problem persist :
.....
< script src="../node_modules/chart.js/dist/Chart.bundle.min.js" >< /script >
< script src="../node_modules/chart.js/dist/Chart.js" >< /script >
< /head >
< body >
< demo >
Loading...
< /demo >
< /body >
import {Component} from "@angular/core";
import {CHART_DIRECTIVES} from 'ng2-charts';
import {FORM_DIRECTIVES} from "@angular/forms";
import {CORE_DIRECTIVES, NgClass} from "@angular/common";
import {ROUTER_DIRECTIVES} from "@angular/router";
let template = require('./ChartComponent.html');
@Component({
selector: 'line-chart-demo',
template: template,
directives: [CHART_DIRECTIVES, NgClass, CORE_DIRECTIVES, FORM_DIRECTIVES,ROUTER_DIRECTIVES]
})
export class ChartComponent{
// Doughnut
public doughnutChartType:string = 'doughnut'
public doughnutChartLegend:boolean = false
public doughnutColors:any[] = [{ backgroundColor: ['#1ABB9C', '#E74C3C', '#9CC2CB'] }]
// Some data - depending on your case
public doughnutChartLabels:string[] = ['Passed', 'Failed', 'Not Assessed']
public doughnutChartData:number[] = [4, 5, 15]
// events
public chartClicked(e:any):void {
console.log(e);
}
public chartHovered(e:any):void {
console.log(e);
}
[labels]="doughnutChartLabels"
[legend]="doughnutChartLegend"
[colors]="doughnutColors"
[chartType]="doughnutChartType"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)">
i have installed the ng2-chart and the chart.js (thet are located in the nodes_modules )
the problem is solved from the #222 issue , i just added (display: block; width: 100%) to the chart div
thank you very much @sahlouls for your help :D :D
@alaa-bourouissi thanks you have shared the right place
I managed to get it work, but only in dev mode. Does it work for you guys with 'ng serve -prod'?
Hi guys I am facing integration issue in angular CLI so can anyone guide me the clear steps which is currently working , it will be great help.......
Hi, I'm trying to install ng2-charts under angular2 rc4 with npm install ng2-charts --save
The problem I'm facing is that ng2-charts adds angular2 alpha.46 as a dependency. As a consequence, npm shows duplication errors.
Also CHART_DIRECTIVES are not found when adding: import { CHART_DIRECTIVES } from 'ng2-charts'.
I can't figure out what's wrong or what's missing ?
Thanks for help.
I was stuck in the ng2-charts because I have RC-4. @sahlouls Thanks, buddy you helped me a lot.
Closing for inactivity. This package is now updated for Angular 7. If this issue persists please provide a stackblitz/codepen/... example which reproduces it.
Most helpful comment
the problem is solved from the #222 issue , i just added (display: block; width: 100%) to the chart div
thank you very much @sahlouls for your help :D :D