CSS Donut Chart is a lightweight vue component for drawing donut charts on applications using CSS. Compatible with both Vue 3 and Vue.2.
css donut chart js, vue css donut chart, donut pie chart css animation, svg donut chart, donut chart html css javascript, svg donut chart
Angular Library For Creating Beautiful Data Charts | NgxBeautifulCharts
How to make use of it:
Install and download:
# Yarn $ yarn add vue-css-donut-chart # NPM $ npm install vue-css-donut-chart --save
1. Import and register the component.
import Donut from 'vue-css-donut-chart'; import 'vue-css-donut-chart/dist/vcdonut.css'; Vue.use(Donut);
2. The example shows how to create a basic pie chart.
<template> <vc-donut :sections="sections">Basic donut</vc-donut> </template>
export default { data() { return { sections: [ { label: 'Red section', value: 25, color: 'red' }, { label: 'Green section', value: 25, color: 'green' }, { label: 'Blue section', value: 25, color: 'blue' } ] }; }, methods: { handleSectionClick(section, event) { console.log(`${section.label} clicked.`); } } };
3. Component props available.
// diameter of the donut size: { type: Number, default: 250, validator: v => v > 0 }, // unit to use for `size` unit: { type: String, default: 'px' }, // percentage of donut ring's thickness thickness: { type: Number, default: 20, validator: v => v >= 0 && v <= 100 }, // text in the middle of the donut, this can also be passed using the default slot text: { type: String, default: null }, autoAdjustTextSize: { type: Boolean, default: true }, // color to use for the middle of the donut // set this to `transparent` or `thickness` to 100 to make a pie chart instead background: { type: String, default: '#ffffff' }, // color to use for the empty ring areas foreground: { type: String, default: '#eeeeee' }, // sections of the donut, must have a `value` property // other valid properties are `label` and `color` (default is `dodgerblue`) sections: { type: Array, default: () => [], validator(sections) { for (let i = 0; i < sections.length; ++i) { /* istanbul ignore if - already covered by unit tests for sectionValidator */ if (!sectionValidator(sections[i])) return false; } return true; } }, total: { type: Number, default: 100, validator: v => v > 0 }, hasLegend: { type: Boolean, default: false }, legendPlacement: { type: String, default: placement.BOTTOM, validator: val => !!placement[val.toUpperCase()] }, // degree angle at which the first section begins startAngle: { type: Number, default: 0 }
API
Props
Prop | Type | Required | Default | Description |
---|---|---|---|---|
size | Number | No | 250 | Diameter of the donut. Can be any positive value. |
unit | String | No | 'px' | Unit to use for size . Can be any valid CSS unit. Use % to make the donut responsive. |
thickness | Number | No | 20 | Percent thickness of the donut ring relative to size . Can be any positive value between 0-100 (inclusive). Set this to 0 to draw a pie chart instead. |
text | String | No | – | Text to show in the middle of the donut. This can also be provided through the default slot. |
background | String | No | '#ffffff' | Background color of the donut. In most cases, this should be the background color of the parent element. |
foreground | String | No | '#eeeeee' | Foreground color of the donut. This is the color that is shown for empty region of the donut ring. |
start-angle | Number | No | 0 | Angle measure in degrees where the first section should start. |
total | Number | No | 100 | Total for calculating the percentage for each section. |
has-legend | Boolean | No | false | Whether the donut should have a legend. |
legend-placement | String | No | 'bottom' | Where the legend should be placed. Valid values are top , right , bottom and left . Doesn’t have an effect if has-legend is not true. |
auto-adjust-text-size | Boolean | No | true | Whether the font-size of the donut content is calculated automatically to fit the available space. |
sections | Array
| No | [] | An array of objects. Each object in the array represents a section. |
section.value | Number | Yes | – | Value of the section. The component determines what percent of the donut should be taken by a section based on this value and the total prop. Sum of all the sections’ value should not exceed total , an error is thrown otherwise. |
section.color | String | Read description | Read description | Color of the section. The component comes with 24 predefined colors, so this property is optional if you have <= 24 sections without the color property. |
section.label | String | No | 'Section <section number>' | Name of the section. This is used in the legend as well as the tooltip text of the section. |
Pure CSS Donut Charts Plugin/Github
See Demo And Download
Official Website(dumptyd): Click Here
This superior jQuery/javascript plugin is developed by dumptyd. For extra Advanced usage, please go to the official website.