score:4
Accepted answer
this answers the issue contained in the question's title:
how to show slice value inside of slice in pie chart using chart.js
the code snippet below show how to display the values inside the slices with the use of chartjs-plugin-labels
. the code of the samples was extracted from the chartjs-plugin-labels
demo page.
var canvas = document.getelementbyid('mychart');
new chart(canvas, {
type: 'pie',
data: {
labels: ['january', 'february', 'march'],
datasets: [{
data: [50445, 33655, 15900],
backgroundcolor: ['#ff6384', '#36a2eb','#ffce56']
}]
},
options: {
responsive: true,
maintainaspectratio: true,
plugins: {
labels: {
render: 'value',
fontcolor: ['green', 'white', 'red']
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.3/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-labels/src/chartjs-plugin-labels.js"></script>
<canvas id="mychart"></canvas>
if you want to display the percentage of each slice, you can do the following:
var canvas = document.getelementbyid('mychart');
new chart(canvas, {
type: 'pie',
data: {
labels: ['january', 'february', 'march'],
datasets: [{
data: [50445, 33655, 15900],
backgroundcolor: ['#ff6384', '#36a2eb','#ffce56']
}]
},
options: {
responsive: true,
maintainaspectratio: true,
plugins: {
labels: {
render: 'percentage',
fontcolor: ['green', 'white', 'red'],
precision: 2
}
},
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.3/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/emn178/chartjs-plugin-labels/src/chartjs-plugin-labels.js"></script>
<canvas id="mychart"></canvas>
Source: stackoverflow.com
Related Query
- How to show slice value inside of slice in pie chart using chart.js
- How to create single value Doughnut or Pie chart using Chart.js?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- how to add percentage value to legend field in pie chart using chart.js
- How to display the values inside the pie chart of PrimeNG (chart) using JavaScript or Angular
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- How can I show "No Data" message in Pie Chart when there is no data using VueJS?
- how to show data value on bar chart body rather than using tooltip?
- How to add text inside the doughnut chart using Chart.js?
- Angular chart how to show the legend data value by default along with legend name
- How to add text inside the doughnut chart using Chart.js version 3.2.1
- How to plot chart from external JSON and format X-AXIS to show time using Chart.JS?
- pie chart inside donut chart using chart js
- On click event to show name of pie chart slice in chartsJS
- How to show tooltip value of all data falling on the same axis in chart js?
- how to show speedometer on Doughnut chart in chart.js using reactjs
- ChartJS Pie Chart How default just show 2 legend datas
- how can i show labels and value in both on bar chart
- How to add text inside the doughnut chart using Chart.js AngularJS 2.0?
- how to put a second pie chart right next to first pie chart inside the bootstrap card
- How to add image inside the doughnut chart using chart.js?
- Char.js - How to show labels by default in pie chart
- How to set up a simple pie chart using React in ChartJS on codesandbox
- How to show bar chart labels clearly using ChartJS?
- How to display label inside pie chart in Chartkick?
- how to show chart using chart js
- How to run Chart.js samples using source code
- How to make the size of pie chart fixed without using canvas (chart.js)
- I want to show the value of label inside the pie graph. (vue-chartjs / pieceLabel)
- How to display pie slice data and tooltip together using chart.js
More Query from same tag
- ChartJs error in displaying my array data
- Chart js not showing negative y axis
- chartjs is issue with large amount data
- Calling a TypeScript function from a Chart.js option callback
- How can I show gridlines only of the even value ones withchartjs?
- How to fix page layout with embedded frame
- Querying mongoDB for some chart data - my pipeline seems convoluted
- Passing Array to Chart.js not working, chart not rendering
- Chart.js line chart not showing in Google Chrome canvas(only in Microsoft Edge)
- ChartJS bar chart - trigger hover even when the cursor is outside of the bar
- How to generate color code dynamically by swapping 2 characters within a string using PHP
- React.js made a Custom Line Chart
- Can't change the time of the xAxes in the Chart.js
- How can I draw lines inside the bars in charts.js?
- How to increase space between chart and legend? (googlecharts)
- Chartjs – change tooltip border radius
- Multiple usage of Javascript function
- Chart.js | Trouble refreshing line chart with "setInterval"
- How to load data values from cookie into Chart.js
- Chart.js PolarArea Chart. Changing the labels to a 45 degree angle
- How can I get chart.js to automatically add colours for dynamic labels?
- Overlap chart datasets with different view types in Chart.js
- Change tooltip positioning in doughnut chart using Chart.js
- Angular 12 Chart.js - Cannot display doughnut
- chart.js - Add corporate design to chart
- Maintain Y axis scale in graph with scroll in the X axis when the dataset grows bigger. Aspect-ratio problem
- Removing ChartJS 2 border and shadow from point style legend
- Chart.js the point's limit supported
- not able to move my range slector
- Responsive Chart.js Doughnut Chart with minimum height