score:2
You can use chartjs-plugin-datalabels as follows:
new Chart(document.getElementById("myChart"), {
type: "bar",
data: {
labels: ['A', 'B', 'C'],
datasets: [{
label: "X",
data: [15, 8, 12],
backgroundColor: "red"
},
{
label: "Y",
data: [7, 6, 15],
backgroundColor: "blue"
},
{
label: "Z",
data: [6, 12, 10],
backgroundColor: "green"
}
]
},
options: {
plugins: {
datalabels: {
formatter: (value, context) => {
let total = context.chart.data.datasets[context.dataIndex].data.reduce((a, b) => a + b, 0);
return Math.round(1000 / total * value) / 10 + '%';
},
color: 'white'
}
},
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true
}]
}
}
});
canvas {
max-width: 400px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels"></script>
<canvas id="myChart" width="10" height="5"></canvas>
Source: stackoverflow.com
Related Query
- How to add additional label in the middle of each bar using ChartJS
- How to use set the color for each bar in a bar chart using chartjs?
- how to show bar value on the top of each bar in chartjs
- How to add the value for each label to pie legend
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- How can I add a label above just the last bar in a Chart.JS bar chart?
- How to custom index label on each bar chart using chartjs?
- How to add label square to Bar Chart using Chart.js
- How to add vertical line in bar chart using chartJs and ng2-charts?
- How to add space Between Columns in Bar chartjs and remove the space in the end
- How to add text inside the doughnut chart using Chart.js?
- How to add text in centre of the doughnut chart using Chart.js?
- How to add label for ChartJs Legend
- How to change the color of legend in chartjs and be able to add one more legend?
- How to change the cursor to a pointer when I hover over a bar in a ChartJS bar chart?
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Chart.js - How to Add Text in the Middle of the Chart?
- How to set a full length background color for each bar in chartjs bar
- Gradient color for each bar in a bar graph using ChartJS
- PrimeNg bar chart how to show a label for the y-axis
- unable to add background color to the canvas using jspdf and chartjs
- Add a custom label to the top or bottom of a stacked bar chart
- How can I add some text in the middle of a half doughnut chart in Chart.JS?
- how to reset the graph/chart after zoomin, pan using chartjs
- How to Increase the label font size and decrease the size of my pie using chart.js?
- How to add ChartJS code in Html2Pdf to view image
- How to Change the Label Strike-Through with light gray on a ChartJS Doughnut?
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- ChartJS - How to increase the maximum degree of label rotation on x-axis?
- chartJS label on each side of the chart
More Query from same tag
- Chart.js Bar chart resizes again when revisiting the tab
- Is there a way to hide/customize ChartJS' above legend?
- ChartJS 3.0 - Number format
- Is there a way to change the react-chart-js tooltip only on a graph?
- Stacked Bar Chart, Two on Same Line w/ Same Color
- Click event on stacked bar chart - ChartJs
- Puppeteer and PDF generation with canvas
- Chart.js displaying each letter of label and data as a single value on chart. The data and labels provided are arrays
- Chart.js: How can I set paddings and draw a background box in a line chart?
- Formatting axis labels using ChartsJS
- Chart.js Vertically Aligned points on single x axis
- How to convert a bar legend to line legend in chart.js 2.7.2?
- How can I keep my menu from moving other elements in the page?
- How can I hide tick marks on Chart.js?
- Chart.js get the nearest point when clicked on canvas
- ChartJS - tooltip of one element is covering point that user should be able to select
- Set max value of chart.js bar chart
- Cant assign data to ng2 piechart after receiving it in HTTP response
- Show statistics in my diagram (php mysqli)
- Chart.js multiple columns of data for the same label
- ChartJs Horizontal line
- Average 2 Keys in ChartJS
- assigning line chart data in chartjs
- chart js in an especific label
- Chart.js Start Y-Axis at a defined value
- How get values on legend label withn Chart js on Angular
- tring to get data into chart.js from Javascript or PHP
- Chart.js is not showing data
- ChartJs different data for Tooltips
- ChartJS -- How do I change scale color when I have to scales?