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
- How to use percentage scale with Chart.js
- Cannot visualise chartJS data in ASP .NET Core
- pie chart inside donut chart using chart js
- Chart.js - Line Chart format data to Lacs/Crores
- Destroying chart.js is not working when chart created inside function - chart.destroy() is not a function
- Chartjs in Reactjs - how can I update data dynamically?
- How to remove transparency from images downloaded in Chart.js
- Chart js nested pie label colors in legend
- set my chart min yaxis to 0
- Chart.js - hide / remove label on second dataset
- Passing Array to Chart.js not working, chart not rendering
- Is there a way to represent date hole in chartjs time series?
- Chart.js doughnut chart tooltip size?
- ChartJS – is there any way to remove blank space around pie charts?
- How to reduce the distance between yAxes in Chart.js?
- Can you remove the xAxes border line and keep the ticks only?
- Chart.js 2.9.4 - error using bundle from CDN - "chart is not defined"
- bower degrades chart.js each time installing other packages
- ChartJS: how to change data in hover box?
- ChartJS ReactJS Object of Objects
- How to perform an histogram with the following dictionary?
- chartjs add dots to bars in grouped bar chart
- legend not displayed for radar Angular-chart.js
- Always display ChartJS custom tooltips
- Performance issue, what causes it?
- Bar Chart in Angular JS Using Chartjs
- Chart.js passing value data dynamic
- Chart Js , loading data on selection but bar graph displaying old values as well on hovering
- Drill down charts dynamic functionality
- ChartJs - Footer color dynamically