score:3
Accepted answer
This is because, the way you are constructing the chart is incorrect (it's for Chart.js 1.x).
Here is the correct / proper way of creating a chart in Chart.js 2.x :
$(document).ready(function() {
loadDonutChart();
});
function loadDonutChart() {
var ctx = document.getElementById("MydonutChart").getContext("2d");
var data = {
datasets: [{
data: [30, 50, 100, 40, 120],
backgroundColor: ["#F7464A", "#E2EAE9", "#D4CCC5", "#949FB1", "#4D5360"]
}]
};
var options = {
animation: {
easing: 'easeInOutQuart',
duration: 1000
}
};
var myPieChart = new Chart(ctx, {
type: 'pie',
data: data,
options: options
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.min.js"></script>
<canvas id="MydonutChart"></canvas>
score:0
First of all, your data-variable is wrong. In the docs I've not found any info that you could use an array of objects. Data has to be an Object!
This is yours, it's wrong:
var data = [{
value: 30,
color: "#F7464A"
}, {
value: 50,
color: "#E2EAE9"
}, {
value: 100,
color: "#D4CCC5"
}, {
value: 40,
color: "#949FB1"
}, {
value: 120,
color: "#4D5360"
}];
Maybe have a look at this example: http://www.chartjs.org/docs/latest/getting-started/usage.html
Source: stackoverflow.com
Related Query
- Pie chart is not getting rendered in ChartJS
- pie chart not rendered properly in flask app
- Legend color not working with randomly generated background colors in chartjs pie chart
- chartJS pie chart not updating after axios GET
- Chart JS - Bubble Chart is not getting rendered when loaded Dynamically
- updating chartjs pie chart by using .keypress() not working
- ChartJs - pie chart not showing
- Chartjs pie chart not showing from dynamic data
- Chartjs random colors for each part of pie chart with data dynamically from database
- ReferenceError: Chart is not defined - chartjs
- chartjs datalabels change font and color of text displaying inside pie chart
- show label in tooltip but not in x axis for chartjs line chart
- Display values outside of pie chart in chartjs
- Chart.js ng2-charts colors in pie chart not showing
- Chart.js: width and height of a pie chart not respected
- Chartjs not rendering chart and no error thrown
- Chart.js pie chart not showing in Google Chrome canvas
- ChartJS is not rendered
- ChartJS 2.0 - Huddle labels on pie chart
- Angular 8 & ChartJs change color in pie chart
- ChartJS Doughnout Chart Pie Offset on Hover
- Custom data in label on ChartJS pie chart
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- Use transparent stroke color with chartjs pie chart
- Primevue Chart not rendered
- Chartjs (Non Vue) Not Rendering Graph Chart inside V-if/V-show
- Print pie chart in chartjs
- ChartJS "half donut" chart not displaying properly
- My pie chart (chartJs) does not appear
- ChartJS version 3 how to add percentage to pie chart tooltip
More Query from same tag
- ChartJS tooltip label for pie cart being cut
- Applying Callback To One Y-Axis
- Problems with max and min value of Chart.js [line chart]
- Chart.js Radial axes: is it possible to use multiple axes on radar chart?
- Angular-chart.js Configuration
- Custom alphanumerical values in chart.js?
- Chartjs Polar Area Chart - Data labels shown don't rotate with startAngle
- Chart.js bar chart: show tooltip on label hover
- Show point values in Radar Chart using chart.js
- Chartjs v2.5 - only show min and max on scale, absolute positioning on scale
- Rest api / json error while using it with react chartjs
- No rendered annotation line on Line Chart
- Duplicate of legends are Produced in ng2 chart
- Chartjs - onAnimationComplete fires before the animation actually completes
- How to remove strikethrough from label once click on legend
- Vue Chart JS options aren't used
- Chart.js - How to push a collection of array into dataset
- ChartJS plugin with live label update
- Add dynamic data in a demo chart.js file of a django template
- Highlighting point in all datasets on hover over
- Make a Histogram in Chart.js
- Line Chart: background of RangeSlider
- Get data from sql database in chartjs using codeigniter
- Chart JS attempt to stacked bar chart tooltip for only one dataset
- How can I get A radar chart like this by chart.js
- How can I display fixed labels on X-axis while having data on that axis?
- chartjs removing/redrawing canvas, graph not responsive
- Mixed chart scatter plot with chart.js
- Exporting dynamic chartjs to jspdf
- What are these line-boxes called in Chart.js, and how do I turn them off?