score:15
Try something like the following ...
public pieChartColors: Array < any > = [{
backgroundColor: ['red', 'yellow', 'rgba(148,159,177,0.2)'],
borderColor: ['rgba(135,206,250,1)', 'rgba(106,90,205,1)', 'rgba(148,159,177,1)']
}];
...
not a 'ng2-charts' pro, but afaik this should work.
score:1
I agree with above answer, I would like to provide details if someone needs it. my example is in PIE chart it works for others too.
Step-1:
Add the following in your component.ts file
public pieChartOptions: ChartOptions = {
responsive: true,
};
public pieChartLabels: Label[] = [['Not', 'Completed'], ['Completed', 'Tasks'], 'Pending Tasks'];
public pieChartData: SingleDataSet = [300, 500, 100];
public pieChartType: ChartType = 'pie';
public pieChartLegend = true;
public pieChartPlugins = [];
public pieChartColors: Array < any > = [{
backgroundColor: ['#fc5858', '#19d863', '#fdf57d'],
borderColor: ['rgba(252, 235, 89, 0.2)', 'rgba(77, 152, 202, 0.2)', 'rgba(241, 107, 119, 0.2)']
}];
chartClicked(e){
console.log(e);
console.log('=========Chart clicked============');
}
chartHovered(e){
console.log(e);
console.log('=========Chart hovered============');
}
Step-2 :
Your component.html should look something like below:
<canvas baseChart
[data]="pieChartData"
[labels]="pieChartLabels"
[chartType]="pieChartType"
[options]="pieChartOptions"
[plugins]="pieChartPlugins"
[legend]="pieChartLegend"
[colors]="pieChartColors"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"
>
</canvas>
score:6
Solved this problem by adding *ngIf="pieChartLabels && pieChartData"
condition in the HTML template:
<div class="card">
<div class="card-header">
Pie Chart
</div>
<div class="card-body">
<div class="chart-wrapper" *ngIf="pieChartLabels && pieChartData">
<canvas baseChart class="chart"
[data]="pieChartData"
[labels]="pieChartLabels"
[chartType]="pieChartType"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)">
</canvas>
</div>
</div>
</div>
Source: stackoverflow.com
Related Query
- Chart.js ng2-charts colors in pie chart not showing
- Pie Chart using chart.js not showing up but bar charts are?
- Chart.js pie chart not showing in Google Chrome canvas
- Chart JS - Grid colors and gradient fill not showing
- Legend color not working with randomly generated background colors in chartjs pie chart
- Chart.js colors in bar chart not showing
- Chart.js pie chart not showing
- Chart.js not showing all labels on pie chart
- Mixed chart not showing both charts simultaneously chart.js
- Colors not showing up on charts in ionic 3
- ChartJs - pie chart not showing
- angular-chart not showing Pie Chart
- Chartjs pie chart not showing from dynamic data
- how to not repeat code while creating multiple charts in chart js
- Chart js pie chart not showing dynamic data using JSON
- Chartjs random colors for each part of pie chart with data dynamically from database
- chartjs + Angular6 is not showing charts or any error
- Chart.JS Mixed Chart - Bars Not Showing
- Charts js not showing
- Chart.js: width and height of a pie chart not respected
- Series Details Not Showing in Angular Chart with Charts.js
- How do you set pie chart colors in angular-chart.js
- Chart JS custom tooltip not showing
- Pie chart is not getting rendered in ChartJS
- Chart JS not showing On hover with small data
- Configure Pie Chart Colors Using Chart.js and PHP
- My pie chart (chartJs) does not appear
- Chart.js tooltip not showing on line chart
- chart annotations not showing in Angular 2
- Charts not showing in wicked pdf
More Query from same tag
- ChartJS "half donut" chart not displaying properly
- react-chartjs: difference between `scales.x`/`xAxes`/`xAxes[]`
- How do I group legend entries using Chartjs?
- Updating a Pie Chart in React as Data is Entered
- How do I prevent Chartjs tooltip callback returning multiple instances of the same value?
- How to add background image in bar chart column in Chart.js?
- Is there anyway add 2 or more chart with foreach loop
- Select All and Unselect Option for chart.js
- show multiple responsive chart in the same page using chart.js
- How can I set y-axis label on Chart.js?
- Chart.js Error: You may need an appropriate loader to handle this file type
- chart.js datapoint offset multiple charts
- ChartJS Realtime Animation
- How do I change axis, title, legend formatting on chartjs template
- Use chartjs with rails
- Make a chart clickable when placed under another SVG <View>
- Chart.js: Don't stretch axes beyond chart
- angular chart js type line setting chart-options not working
- Set xAxes labels to format YYYY-MM-DD HH:mm:ss in Chart.js
- Chart.js won't display percentage label when value is above 1000?
- line graph spot in the top middle of the bar graph
- chart.js: Show labels outside pie chart
- Can not update bar chart values in Chart.js 2.0.0 alpha3
- How can I modify category labels font size in Chart.JS V2?
- Angular 6 ChartJS create canvas dynamically and create graph on it - an example?
- Dynamically Creating Json Array Javascript
- Getting rid of Chart.js canvas subpixels
- Chart.js, PHP and JSON loop issue
- Chart.js 2.0: How to change title of tooltip
- display vertical axis label in line chart using chart.js