score:1
You can add padding to the layout options and set the out-label color value to an array.
const COLORS = [
"#2ecc71",
"#3498db",
"#95a5a6",
"#9b59b6",
"#f1c40f",
"#e74c3c",
"#34495e"
];
new Chart(document.querySelector('.chart').getContext('2d'), {
type: 'pie',
data: {
labels: ["Green", "Blue", "Gray", "Purple", "Yellow", "Red", "Black"],
datasets: [{
backgroundColor: COLORS,
data: [12, 19, 3, 17, 28, 24, 7]
}]
},
options: {
layout: {
padding: 50
},
legend: {
display: false
},
plugins: {
outlabels: {
backgroundColor: null,
color: COLORS,
stretch: 30,
font: {
resizable: true,
minSize: 15,
maxSize: 20,
},
zoomOutPercentage: 100,
textAlign: 'start',
backgroundColor: null
}
}
}
});
body { background: #111; }
.doughnut-canvas-container { background: #FFF; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-piechart-outlabels@0.1.4/dist/chartjs-plugin-piechart-outlabels.min.js"></script>
<div class="doughnut-canvas-container">
<canvas class="chart" class="chartjs-render-monitor"></canvas>
</div>
Source: stackoverflow.com
Related Query
- Fit outlabels to canvas and use different colors chartjs
- ChartJS canvas not displaying rgba colors in IE, Safari and Firefox
- unable to add background color to the canvas using jspdf and chartjs
- Chartjs with multiple y axes and different scales
- Chartjs different row background colors according to Y axis values
- Trying to use axios, vuejs and a dummy api for my chartjs and googlecharts (get requests only)
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- How to properly feed data to ChartJS with different number of x(labels) and y(data) points
- How to hide/show bars differentiate by a colors and by click on labels, using chartjs bar charts?
- Angular 6 ChartJS create canvas dynamically and create graph on it - an example?
- How to use plugins in chartjs and laravel chart consoletvs/chartsjs
- chartjs display data in one bar line with 3 different data sets in 3 different colors
- Chartjs different length of labels and datasets
- ChartJs multiaxis chart show different label bottom and top
- Chartjs annotation plugin colored box colors get summed after switching back and forth
- 'require is not defined' error when attempting to use chartjs in javascript code
- Different color for each bar in a bar graph in ChartJS and VueJS
- ChartJS canvas not displaying colors in edge browser
- React - how to get array from store before first render and use it as dataset for ChartJS
- ChartJS - Returning labels and data from server on different calls
- Chartjs - Loop thru dataset and assign colors
- Angular and ChartJS colors
- Placeholder on canvas of ChartJs and Angular
- chart.js - Second bar, with another label and different colors
- Different color for each bar in a bar chart; ChartJS
- ChartJS - Different color per data point
- Chartjs random colors for each part of pie chart with data dynamically from database
- Truncating canvas labels in ChartJS while keeping the full label value in the tooltips
- Chartjs v2 - format tooltip for multiple data sets (bar and line)
- how to plot multiple time series in chartjs where each time series has different times
More Query from same tag
- Draw points and lines inside a bar in bar chart
- Convert a dynamic piechart from CanvasJS to Google Charts?
- react-chartjs-2 how to set multiple background levels within a line chart
- Chart JS not working with Dynamic Data
- Pushing API Data into Chart.js
- Chart not rendering on ChartJS
- Trouble with chart scaling and zooming using Chart.js and chartjs-zoom-plugin
- TypeScript issue with custom plugin and afterDraw callback Chart.js and react-chartjs-2
- Why my ng2-chart data isn't scaled properly?
- “lazy-initialize” In ChartJS
- Chart.js create line graph using dates in the x-axis that reflect real time intervals (not evenly distributed)
- Chart Js Cannot read property 'length' of undefined
- Chartjs Line chart options display increase and decrease percentage between each datapoint
- ERROR TypeError: Cannot read properties of undefined (reading 'skip') Typescript/Api
- How to set up a simple pie chart using React in ChartJS on codesandbox
- How to create range based ticks in chart js? (like in attached image)
- Add DataSet Bar Chart - Chart.JS
- Using chartjs v2 to show categorical values on axis instead of numeric
- Convert charts from vue-chartjs to a PDF
- 0 line style of Chart.js line chart
- How do you add custom text to tooltips in charts.js
- ChartJS - Show/hide data individually instead of entire dataset on bar/line charts
- How to run Chart.js samples using source code
- chartjs is issue with large amount data
- how to display table from chart js data in canvas.js using java script .?
- json file to charts
- Chart js legend are being cut off if the bar height is equal to port height - chart js
- Remove x-axis label/text in chart.js
- hide label on doughnut chart of chartjs
- Chart.js scatter chart plot data joins start and finish points together