score:1
I had this problem using <p-chart>
primeNG.
Just add this in your index.html:
<script src= "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js" charset="utf-8"></script>
And that´s it, you don´t have to import in your typescript.
I found that in chart documentation
-then use a Chart.js CDN.
score:1
I tried. this works for me easy to implements https://valor-software.com/ng2-charts/
score:2
If you are using webpack you may try adding the chart.js file (or the minified version) to the entry property as follows:
...
entry: {
'chartJS': './node_modules/chart.js/dist/Chart.bundle.min.js',
// Other mappings
}
...
score:5
Here is the best module out of few on npmjs:
Then you can use it like this in your module:
import { ChartModule } from 'angular2-chartjs';
@NgModule({
imports: [ ChartModule ]
// ...
})
export class AppModule {
}
And in html template:
<chart [type]="type" [data]="data" [options]="options"></chart>
Don't forget to fill it with data ;)
score:22
In the template don't forget to enclose canvas in a div. If canvas is a direct child of custom directive in dom, then chart might not load.
<div><canvas id="myChart"></canvas></div>
I have wasted lot of time in finding this issue.
score:32
I had a similar issue, it turned out I was referencing an old example.
First, as you've already correctly done, install the library using NPM:
npm install chart.js --save
Then, in your component, import the library:
import Chart from 'chart.js';
To get up and running with a quick example, have a look at the example code in the Chart.js documentation or see my example below.
dashboard.component.ts
import Chart from 'chart.js';
import { ViewChild, Component, ElementRef, OnInit } from '@angular/core';
@Component({
selector: 'app-dashboard',
template: '<canvas #donut></canvas>'
})
export class DashboardComponent implements OnInit {
@ViewChild('donut') donut: ElementRef;
constructor(
) { }
ngOnInit() {
let donutCtx = this.donut.nativeElement.getContext('2d');
var data = {
labels: [
"Value A",
"Value B"
],
datasets: [
{
"data": [101342, 55342], // Example data
"backgroundColor": [
"#1fc8f8",
"#76a346"
]
}]
};
var chart = new Chart(
donutCtx,
{
"type": 'doughnut',
"data": data,
"options": {
"cutoutPercentage": 50,
"animation": {
"animateScale": true,
"animateRotate": false
}
}
}
);
}
}
Source: stackoverflow.com
Related Query
- How to implement chart.js in Angular2
- How to print a chart rendered by code
- How do I destroy/update Chart Data in this chart.js code example?
- How to implement chart js using viewbag in mvc razor
- How do i have to implement my code to get correct json?
- How to run Chart.js samples using source code
- How to implement scattered chart using chart.js which is not available by default?
- how to not repeat code while creating multiple charts in chart js
- How to add text inside the doughnut chart using Chart.js?
- How to clear a chart from a canvas so that hover events cannot be triggered?
- Chart.js - How to set a line chart dataset as disabled on load
- chart js 2 how to set bar width
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How can I make two of my lines in Chart JS thicker
- How to prevent first/last bars from being cut off in a chart with time scale
- How set color family to pie chart in chart.js
- Chart.js Bar Chart - how to chart bars from 0
- How to add an on click event to my Line chart using Chart.js
- Chart.js how to show cursor pointer for labels & legends in line chart
- How do you hide the title of a chart tooltip?
- How to put rounded corners on a Chart.js Bar chart
- chartjs : how to set custom scale in bar chart
- How can I make a stepline or stepped chart in chart.js or D3?
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to Draw Gantt chart using chart js or other libraries
- How to fix chart Legends width-height with overflow scroll in ChartJS
- How to display Line Chart dataset point labels with Chart.js?
- chart js how to fill legend box with colour
- How to add an offset to a dataset in Chart js
More Query from same tag
- Chartjs : data labels getting overlapped in smaller datasets using chartjs-plugin-datalabels
- Chart.js pie chart in table shows weird behavior on page resize
- impressions in google analytics is zero while sessions and users are more
- Tooltips on multiple charts in chart.js showing the wrong values
- Hide x-axis labels but show tooltips in chart.js
- Reproduce Error in Chartjs v2 Polar chart not plotting all supplied data
- Can't reuse a template in Vue.js
- How to set static labels for ng2-charts bar charts?
- Javascript not populate chart after retrieve json data
- Chart.js extra undefined column
- How to display "%" sign on mouse hover in Pie-Chart
- Map JSON for Chartjs with Angular 7
- Trouble setting options for radar chart on Quickchart.io
- Chart.js Chart in Angular does not load until resizing browser window
- ChartJs x axis labels on waterfall chart
- chartjs-plugin-zoom not working with my React project
- ChartJS autoskip:False not working on line chart
- Chart.js how can we have a column not start at 0
- How to display value labels above graph bars using chart.js
- Calculate Ideal Burndown
- chart.js time graph for Full day
- How can I add a euro sign (€) to all tooltips in my chart js line chart
- Loading Laravel Chart consoletvs/charts:7.*
- Uncaught Error: Can't resolve all parameters for Chart: (?, ?) in Ionic2
- Best API/code library to build a timeline/chart
- chart.js My DATA doesn't go along with the label,
- Implement ng2-charts in an Angular-Seed
- A chart Js error issue are occured in my Laravel other page?
- Chart.js not showing/skipping labels
- Make Chart.js canvas responsive inside the resizeable div