score:1
I resolved: We add script to file global:
if(window.Chartist && Chartist.Pie && !Chartist.Pie.prototype.resolveOverlap) {
Chartist.Pie.prototype.resolveOverlap = function() {
this.on('draw', function(ctx) {
if(ctx.type == 'label') {
let gText = $(ctx.group._node).find('text');
let ctxHeight = ctx.element.height();
gText.each(function(index, ele){
let item = $(ele);
let diff = ctx.element.attr('dy') - item.attr('dy');
if(diff == 0) {
return false;
}
if(Math.abs(diff) < ctxHeight) {
ctx.element.attr({dy: ctx.element.attr('dy') - ctxHeight});
}
});
}
});
};
}
and then:
new Chartist.Pie(element, data, options).resolveOverlap();
score:2
The real problem lies with the overlapping of the labels when the slices are small.You can use PieceLabel.js which solves the issue of overlapping labels by hiding it . You mentioned that you cannot hide labels so use legends, which will display names of all slices
Or if you want exact behavior you can go with the highcharts, but it requires licence for commercial use.
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
var ctx = document.getElementById("chart-area").getContext("2d");
var myDoughnut = new Chart(ctx, {
type: 'pie',
data: {
labels: ["January", "February", "March", "April", "May"],
datasets: [{
data: [
250,
30,
5,
4,
2,
],
backgroundColor: ['#ff3d67', '#ff9f40', '#ffcd56', '#4bc0c0', '#999999'],
borderColor: 'white',
borderWidth: 5,
}]
},
showDatapoints: true,
options: {
tooltips: {
enabled: false
},
pieceLabel: {
render: 'label',
arc: true,
fontColor: '#000',
position: 'outside'
},
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Testing',
fontSize: 20
},
animation: {
animateScale: true,
animateRotate: true
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="https://cdn.rawgit.com/emn178/Chart.PieceLabel.js/master/build/Chart.PieceLabel.min.js"></script>
<canvas id="chart-area"></canvas>
Fiddle demo
score:9
There is a new plugin (since a year), called chartjs-plugin-piechart-outlabels
Just import the source
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-piechart-outlabels"></script>
and use it with the outlabeledPie type
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
var ctx = document.getElementById("chart-area").getContext("2d");
var myDoughnut = new Chart(ctx, {
type: 'outlabeledPie',
data: {
labels: ["January", "February", "March", "April", "May"],
...
plugins: {
legend: false,
outlabels: {
text: '%l %p',
color: 'white',
stretch: 45,
font: {
resizable: true,
minSize: 12,
maxSize: 18
}
}
}
})
Source: stackoverflow.com
Related Query
- chart.js: Show labels outside pie chart
- Chart.js Show labels on Pie chart
- How to display data labels outside in pie chart with lines in ionic
- How to display labels outside the pie chart border?
- Char.js - How to show labels by default in pie chart
- chart.js: segment true is not working in labels outside pie chart : chart.piecelabel.js
- How to show labels above pie chart in chart.js
- Chart.js how to show cursor pointer for labels & legends in line chart
- Display values outside of pie chart in chartjs
- ChartJS: Show all labels of a mixed chart in the tooltip
- ChartJS 2.0 - Huddle labels on pie chart
- Show "No Data" message for Pie chart with no data
- Show labels on each sector to polar chart using angular js chart
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- Pie chart isn't loading, but the labels are
- Chart.js: How to get x-axis labels to show on top of bars in bar chart
- Display data labels on a pie chart in angular-chart.js
- How to show slice value inside of slice in pie chart using chart.js
- Hide labels from pie chart in chartjs
- Show values in Chart.js Pie chart parts
- How to get labels on ChartJS Pie chart segments
- On click event to show name of pie chart slice in chartsJS
- How to show the chartjs bar chart data values labels as text?
- ng2-Chart: can we show the tooltip data of pie chart on load?
- ChartJS Pie Chart How default just show 2 legend datas
- how can i show labels and value in both on bar chart
- Create a pie chart in chart js with labels
More Query from same tag
- chart.js - Second bar, with another label and different colors
- Placing JavaScript content in Bootstrap Popover
- How can I make streaming chart with react?
- chartjs is issue with large amount data
- Display point style on legend in chart.js
- How can I shade a portion of a ChartJS line grph=
- Chart JS Replace All Dataset Data
- How to map json array to two different array for chart
- How put dataset labels into multiTooltipTemplate?
- How to add Canvas tag inside repeater
- Creating a chart
- Chartjs barchart generate data for an array dataset
- ChartJS Update callbacks
- Is There any way to show image on top of the stacked bar, Am getting image on every color Instead of that i need only on top of each bar
- Hover over chart shows multiple datapoints
- getting chartsjs to show key of data label instead of value
- Place tooltip on the outer side of the doughnut chart
- Chartsjs 2 (Alpha) not working in IE8 (even with excanvas)
- chart.js pie chart - how to update dataset with smooth transition
- Can I set different fill color based on a given threshold in Chart.js?
- Building a 24h visualisation with chartjs
- Chart for Real time data with duplicate x axis
- How to use legendCallback or similar when using Chart.js with TypeScript
- Remove data text from Chart.js on hover
- Chart.js Draw a Stacked Bar Chart with Limit Line
- How can I pass my sqlite data to django, and make chart?
- Chart.js same Y axis on left and right
- Change section element every 20 seconds
- ChartJS: Limit Y Axis to cut outlimit values
- Limit labels number on Chart.js line chart