score:8
Accepted answer
Here is an example:
var value = 75;
var data = {
labels: [
"My val",
""
],
datasets: [
{
data: [value, 100-value],
backgroundColor: [
"#FF6384",
"#AAAAAA"
],
hoverBackgroundColor: [
"#FF6384",
"#AAAAAA"
],
hoverBorderColor: [
"#FF6384",
"#ffffff"
]
}]
};
var myChart = new Chart(document.getElementById('myChart'), {
type: 'doughnut',
data: data,
options: {
responsive: true,
legend: {
display: false
},
cutoutPercentage: 80,
tooltips: {
filter: function(item, data) {
var label = data.labels[item.index];
if (label) return item;
}
}
}
});
textCenter(value);
function textCenter(val) {
Chart.pluginService.register({
beforeDraw: function(chart) {
var width = chart.chart.width,
height = chart.chart.height,
ctx = chart.chart.ctx;
ctx.restore();
var fontSize = (height / 114).toFixed(2);
ctx.font = fontSize + "em sans-serif";
ctx.textBaseline = "middle";
var text = val+"%",
textX = Math.round((width - ctx.measureText(text).width) / 2),
textY = height / 2;
ctx.fillText(text, textX, textY);
ctx.save();
}
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.js"></script>
<canvas id="myChart"></canvas>
Source: stackoverflow.com
Related Query
- How to create single value Doughnut or Pie chart using Chart.js?
- how to add percentage value to legend field in pie chart using chart.js
- How to show slice value inside of slice in pie chart using chart.js
- How to create a Doughnut chart in django admin interface using foreign key field data?
- How to plot a single value with line in line chart graph using charts.js?
- 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 create stacked bar chart using react-chartjs-2?
- How to display the labels in doughnut chart using ng2 charts?
- How to create a gantt chart using Chart.js and populate dates?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- How to create two pie charts using Chart.js API?
- How to add text inside the doughnut chart using Chart.js version 3.2.1
- How to highlight single bar in bar chart using Chartjs
- How to create Waterfall model chart using QuickChart?
- how to show speedometer on Doughnut chart in chart.js using reactjs
- How do I customise doughnut chart using chart.js
- How to add text inside the doughnut chart using Chart.js AngularJS 2.0?
- How to display the values inside the pie chart of PrimeNG (chart) using JavaScript or Angular
- How do you create a Radar chart using chart.js with a y-axis of 0 to 100?
- How to add image inside the doughnut chart using chart.js?
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- How to set up a simple pie chart using React in ChartJS on codesandbox
- Can't draw pie chart using chartjs - TypeError: Cannot create property '_meta' on number '16'
- Trying to create a custom tooltip in a doughnut chart using chartsjs, but it is not working
- How to make a max value in doughnut chart
- How can I show "No Data" message in Pie Chart when there is no data using VueJS?
- Create multiple pie chart simultaneously using chart.js
- Create a pie chart using an array from a data table in chart.js
- How to create a line on a chart using chartjs-plugin-annotation
More Query from same tag
- Lograthmic yaxsis setting not working in chartjs
- ChartJS - Why is the transition on the first dataset bad?
- ChartJs 3.x: ResizeObserver is not a constructor
- chart.js Failed to create chart: can't acquire context from the given item
- Zoom is very slow in ChartJS Zoom Plugin
- How to Change the Label Strike-Through with light gray on a ChartJS Doughnut?
- Chart.js how to set cutoutPercentages for each dataset
- Drawing line chart in chart.js with json response
- Chart JS change pointBackgroundColor based on data value
- OnClick event on Custom legends Chart.js / Angular 5
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Uncaught TypeError: fn is not a function in chart.js
- Chart.js bar thickness
- Chart Js Stacked Bar Chart with Multiple levels or categories
- Barchart reducing space between bars
- If date not in queryset add default value
- Where is the documention for the chart.js Chart constructor?
- Angular-chart.js - Make line chart does not curve
- error TS2322: Type 'string' is not assignable to type 'keyof ChartTypeRegistry'
- How to add space between datasets in ng2 doughnut chart
- Chart.js dataset label issue
- How to modify chartjs tooltip so i can add customized strings in tooltips
- Inserting an array in Chart.JS
- How can I remove two labels from my legend with an alternative to item.datasetIndex !== 1 && item.datasetIndex !== 4; ? (Charts.js)
- Is there any way to get y of specific x which not belongs to the dataset in Chart.js graph?
- Using Chart.js, how do I avoid having tooltips overlap?
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Chart JS no animation line chart
- How do I horizontally center a line chart when their is a single X-Axis value?
- Chart.Js vers2 multiline to version 3