| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| `cutoutPercentage` | `number` | `50` - for doughnut, `0` - for pie | The percentage of the chart that is cut out of the middle.
+| `outerRadius` | `number`\|`string` | `100%` | The outer radius of the chart. If `string` and ending with '%', percentage of the maximum radius. `number` is considered to be pixels.
| `rotation` | `number` | 0 | Starting angle to draw arcs from.
| `circumference` | `number` | 360 | Sweep to allow arcs to cover.
| `animation.animateRotate` | `boolean` | `true` | If true, the chart will animate in with a rotation animation. This property is in the `options.animation` object.
import DatasetController from '../core/core.datasetController';
import {formatNumber} from '../core/core.intl';
-import {isArray, valueOrDefault} from '../helpers/helpers.core';
+import {isArray, numberOrPercentageOf, valueOrDefault} from '../helpers/helpers.core';
import {toRadians, PI, TAU, HALF_PI} from '../helpers/helpers.math';
/**
const spacing = me.getMaxBorderWidth() + me.getMaxOffset(arcs);
const maxWidth = (chartArea.right - chartArea.left - spacing) / ratioX;
const maxHeight = (chartArea.bottom - chartArea.top - spacing) / ratioY;
- const outerRadius = Math.max(Math.min(maxWidth, maxHeight) / 2, 0);
+ const maxRadius = Math.max(Math.min(maxWidth, maxHeight) / 2, 0);
+ const outerRadius = numberOrPercentageOf(me.options.outerRadius, maxRadius);
const innerRadius = Math.max(outerRadius * cutout, 0);
const radiusLength = (outerRadius - innerRadius) / me._getVisibleDatasetWeightTotal();
me.offsetX = offsetX * outerRadius;
rotation: 0,
// The total circumference of the chart.
- circumference: 360
+ circumference: 360,
+
+ // The outr radius of the chart
+ outerRadius: '100%'
},
indexAxis: 'r',
PieController.defaults = {
datasets: {
// The percentage of the chart that we cut out of the middle.
- cutoutPercentage: 0,
+ cutout: 0,
// The rotation of the chart, where the first data arc begins.
rotation: 0,
// The total circumference of the chart.
- circumference: 360
+ circumference: 360,
+
+ // The outr radius of the chart
+ outerRadius: '100%'
}
};
return typeof value === 'undefined' ? defaultValue : value;
}
+export const numberOrPercentageOf = (value, dimension) =>
+ typeof value === 'string' && value.endsWith('%') ?
+ parseFloat(value) / 100 * dimension
+ : +value;
+
/**
* Calls `fn` with the given `args` in the scope defined by `thisArg` and returns the
* value returned by `fn`. If `fn` is not a function, this method returns undefined.
--- /dev/null
+module.exports = {
+ config: {
+ type: 'doughnut',
+ data: {
+ labels: ['A', 'B', 'C', 'D', 'E'],
+ datasets: [{
+ data: [1, 5, 10, 50, 100],
+ backgroundColor: [
+ 'rgba(255, 99, 132, 0.8)',
+ 'rgba(54, 162, 235, 0.8)',
+ 'rgba(255, 206, 86, 0.8)',
+ 'rgba(75, 192, 192, 0.8)',
+ 'rgba(153, 102, 255, 0.8)'
+ ],
+ borderColor: [
+ 'rgb(255, 99, 132)',
+ 'rgb(54, 162, 235)',
+ 'rgb(255, 206, 86)',
+ 'rgb(75, 192, 192)',
+ 'rgb(153, 102, 255)'
+ ]
+ }]
+ },
+ options: {
+ outerRadius: '30%',
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'doughnut',
+ data: {
+ labels: ['A', 'B', 'C', 'D', 'E'],
+ datasets: [{
+ data: [1, 5, 10, 50, 100],
+ backgroundColor: [
+ 'rgba(255, 99, 132, 0.8)',
+ 'rgba(54, 162, 235, 0.8)',
+ 'rgba(255, 206, 86, 0.8)',
+ 'rgba(75, 192, 192, 0.8)',
+ 'rgba(153, 102, 255, 0.8)'
+ ],
+ borderColor: [
+ 'rgb(255, 99, 132)',
+ 'rgb(54, 162, 235)',
+ 'rgb(255, 206, 86)',
+ 'rgb(75, 192, 192)',
+ 'rgb(153, 102, 255)'
+ ]
+ }]
+ },
+ options: {
+ outerRadius: 150,
+ }
+ }
+};
export interface DoughnutControllerChartOptions {
/**
+ * Sweep to allow arcs to cover.
+ * @default 360
+ */
+ circumference: number;
+
+ /**
* The percentage of the chart that is cut out of the middle. (50 - for doughnut, 0 - for pie)
* @default 50
*/
- cutoutPercentage: number;
+ cutoutPercentage: number;
+
+ /**
+ * The outer radius of the chart. String ending with '%' means percentage of maximum radius, number means pixels.
+ * @default '100%'
+ */
+ outerRadius: Scriptable<number | string, ScriptableContext<number>>;
/**
* Starting angle to draw arcs from.
*/
rotation: number;
- /**
- * Sweep to allow arcs to cover.
- * @default 360
- */
- circumference: number;
-
animation: DoughnutAnimationOptions;
}
--- /dev/null
+import { Chart } from '../../index.esm';
+
+const chart = new Chart('id', {
+ type: 'doughnut',
+ data: {
+ labels: [],
+ datasets: [{
+ data: [],
+ }]
+ },
+ options: {
+ outerRadius: () => Math.random() > 0.5 ? 50 : '50%',
+ }
+});