score:8
Use borderAlign: "inner"
https://www.chartjs.org/docs/latest/charts/doughnut.html
new Chart(document.getElementById('example-pie-chart-1'), {
type: 'pie',
data: {
labels: [
'{% blocktrans %}Views{% endblocktrans %}',
'{% blocktrans %}Print Requests{% endblocktrans %}',
'{% blocktrans %}PDF Downloads{% endblocktrans %}',
'{% blocktrans %}DOCX Downloads{% endblocktrans %}',
],
datasets: [{
backgroundColor: [
'rgba(71, 101, 160, 0.3)', // #4765a0.
'rgba(0, 0, 0, 0.3)', // #000000.
'rgba(52, 137, 219, 0.3)', // #3489db.
'rgba(179, 179, 179, 0.3)', // #b3b3b3.
],
hoverBackgroundColor: [
'rgba(71, 101, 160, 0.6)', // #4765a0.
'rgba(0, 0, 0, 0.6)', // #000000.
'rgba(52, 137, 219, 0.6)', // #3489db.
'rgba(179, 179, 179, 0.6)', // #b3b3b3.
],
borderColor: [
'rgba(71, 101, 160, 1)', // #4765a0.
'rgba(0, 0, 0, 1)', // #000000.
'rgba(52, 137, 219, 1)', // #3489db.
'rgba(179, 179, 179, 1)', // #b3b3b3.
],
borderAlign: "inner",
data: [6, 3, 2, 2]
}]
},
options: {
title: {
display: false,
text: '{% blocktrans %}Overall Statistics{% endblocktrans %}'
}
}
});
<canvas id="example-pie-chart-1" width="200" height="200"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
score:2
After doing some research, I have found that the borders actually overlaps each-other.
Here, the first slice of the pie is drawn at first. So, all of its borders gets colored by the color you provided. Then the second slice is drawn in the same way.
As there is no distance between this two slices border, the right border of 2nd slice overlaps the left border of first slice.
This process continues until the drawing of last slice. When the last slice is drawn, its left border overlaps with the right border of second last slice and then its right border overlaps with the left border of the first slice.
So, we can see only one border of first slice, three borders of the last slice and two borders of other slices are colored properly.
Any proof of the above description?
Well, according my assumption,this problem can be overcome by adding space in between the slices so that ones border cannot overlap others borders. But I could not find anything to add spaces between the slices of pie chart. However, I have got one example in this issue. In this example, if we click on a slice, it gets larger. I have attached the code below. When a slice gets larger, we can see that the three borders are of the same color that we provided. So, this issue is actually happening due to overlapping border.
Here is the live demo:
var selectedIndex = null;
var myChart = new Chart(document.getElementById('example-pie-chart-1'), {
type: 'pie',
data: {
labels: [
'{% blocktrans %}Views{% endblocktrans %}',
'{% blocktrans %}Print Requests{% endblocktrans %}',
'{% blocktrans %}PDF Downloads{% endblocktrans %}',
'{% blocktrans %}DOCX Downloads{% endblocktrans %}',
],
datasets: [{
backgroundColor: [
'rgba(71, 101, 160, 0.3)', // #4765a0.
'rgba(0, 0, 0, 0.3)', // #000000.
'rgba(52, 137, 219, 0.3)', // #3489db.
'rgba(179, 179, 179, 0.3)', // #b3b3b3.
],
hoverBackgroundColor: [
'rgba(71, 101, 160, 0.6)', // #4765a0.
'rgba(0, 0, 0, 0.6)', // #000000.
'rgba(52, 137, 219, 0.6)', // #3489db.
'rgba(179, 179, 179, 0.6)', // #b3b3b3.
],
borderColor: [
'rgba(71, 101, 160, 1)', // #4765a0.
'rgba(0, 0, 0, 1)', // #000000.
'rgba(52, 137, 219, 1)', // #3489db.
'rgba(179, 179, 179, 1)', // #b3b3b3.
],
data: [6, 3, 2, 2]
}]
},
options: {
title: {
display: false,
text: '{% blocktrans %}Overall Statistics{% endblocktrans %}'
},
onClick: function(evt, elements) {
if (elements && elements.length) {
var segment = elements[0];
myChart.update();
if (selectedIndex !== segment["_index"]) {
selectedIndex = segment["_index"];
segment._model.outerRadius += 30;
} else {
selectedIndex = null;
}
}
}
}
});
<canvas id="example-pie-chart-1" width="200" height="200"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.js"></script>
So, there are two options for you and they are -
- Analyze the source code of chart.js. And tweak the implementation to solve the problem
- Create a new issue to their GitHub repository
Hope, this helps. Thanks!
Source: stackoverflow.com
Related Query
- Pie chart.js - show all 3 segment borders
- ChartJS: Show all tooltips with Total for Multi Pie chart
- PrimeNg Pie Chart - By default show all tooltip?
- Chart.js Show labels on Pie chart
- chart.js: Show labels outside pie chart
- Chartjs - show elements in all datasets on hover using bar chart
- ChartJS: Show all labels of a mixed chart in the tooltip
- Show all values in Chart js y axis
- Show "No Data" message for Pie chart with no data
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- How to show slice value inside of slice in pie chart using chart.js
- ChartJS: chart not show all data
- Show values in Chart.js Pie chart parts
- How can I change the cursor on pie chart segment hover in ChartJS 3?
- 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?
- ng2-Chart: can we show the tooltip data of pie chart on load?
- ChartJS Pie Chart How default just show 2 legend datas
- Char.js - How to show labels by default in pie chart
- Show/hide All nested data in ChartJS Pie chart when outer is shown/hidden
- How can I remove the white border from Chart.js pie chart when all legends are hidden?
- How remove duplicates xAxis labels and show all values on chart
- How can I show "No Data" message in Pie Chart when there is no data using VueJS?
- Remove all borders from my chart in angular-chart-js
- Chart.js not showing all labels on pie chart
- Vue pie chart show after a while (like show console with a warning)
- How to eliminate all borders from chartjs2 stacked chart
- Show Donut / Pie Chart in bootstrap modal with legends
- chart.js: segment true is not working in labels outside pie chart : chart.piecelabel.js
- Chart.js - add data to line chart from clicking pie chart segment
More Query from same tag
- How to make a Chart.js Bar chart stay in its place
- How to use dates as X axis with Chart.js even when there is no Y axis value related
- Setting up min and max in chartjs did not work
- Chart.js multiple doughnut charts above pie chart
- Changing Dataset for a chart in angular 10
- How to configure chart.js line chart with very low minimum height, and only 0 and 1 (no decimals) as ticks on the y-axis
- Tooltip backgroundColor depending on chart color ChartJS
- Chart.js - y axis custom label
- Chart.js Graph Overrunning Container
- Angular-Chart.js it doesn't display the chart
- How to add data to chart.js with a for loop
- chart.js legend not working for pie chart
- Angular 4:PrimeNg DoughnutChart dynamic data issue.
- Not able to remove legent from Radar Chart in chart.js even using legent: {display : false}
- My ChartJS dates don't show up correctly from coinranking API
- Assigning data structures to chartjs properties, NOT individually
- Return 0 as data for months with no data
- How to include Chart.js in my AngularJS project?
- Display Date Label in axes - chart js/ng2 charts
- chart.js with json data and jquery - error :-(
- Chart.js (line chart) tooltip duration/delay
- How to remove bars for those bars with zero value in Chartjs bar chart?
- How to add text inside the doughnut chart using Chart.js AngularJS 2.0?
- How to prevent empty bars from taking up width in Chart.js bar chart
- Polar Area in Chart JS Rotates When Adding Labels
- chart.js stacked graph that overlaps
- Implement ng2-charts in an Angular-Seed
- Legend for only specific datasets - chart.js
- Get the data from node.js for Chart.js
- Remove slice onClick events on Pie Charts in Chart.js