
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
vue-css-donut-chart
Advanced tools
Live demo can be found on the project page – https://dumptyd.github.io/vue-css-donut-chart
Playground – https://jsfiddle.net/dumptyd/ujvypcd3/
:black_medium_small_square: No external dependencies.
:black_medium_small_square: Small size footprint.
:black_medium_small_square: High test coverage.
:black_medium_small_square: Performs automatic font size recalculation as the size of the donut changes.
:black_medium_small_square: Supports responsive donut and pie charts.
yarn
or npm
yarn add vue-css-donut-chart
OR
npm install vue-css-donut-chart
vue-css-donut-chart
:black_medium_small_square: ES6
import Donut from 'vue-css-donut-chart';
import 'vue-css-donut-chart/dist/vcdonut.css';
Vue.use(Donut);
<link rel="stylesheet" href="https://unpkg.com/vue-css-donut-chart@1/dist/vcdonut.css">
<script src="https://unpkg.com/vue-css-donut-chart@1"></script>
<script>
Vue.use(vcdonut.default);
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vue-css-donut-chart@1/dist/vcdonut.css">
<script src="https://cdn.jsdelivr.net/npm/vue-css-donut-chart@1/dist/vcdonut.umd.min.js"></script>
<script>
Vue.use(vcdonut.default);
</script>
With sane defaults in place, basic usage is as simple as passing a sections
array with objects containing a value
property.
This will create a donut with 2 sections that take up 25% each.
<template>
<vc-donut :sections="sections">Basic donut</vc-donut>
</template>
<script>
export default {
data() {
return {
sections: [{ value: 25 }, { value: 25 }]
};
}
};
</script>
<template>
<vc-donut
background="white" foreground="grey"
:size="200" unit="px" :thickness="30"
has-legend legend-placement="top"
:sections="sections" :total="100"
:start-angle="0"
@section-click="handleSectionClick"
>
<h1>75%</h1>
</vc-donut>
</template>
<script>
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) {
console.log(`${section.label} clicked.`);
}
}
};
</script>
Making the component look like a pie chart is as simple as setting the thickness
to 100
.
<template>
<vc-donut
:sections="[{ value: 35 }, { value: 15 }, { value: 15 }, { value: 35 }]"
:thickness="100">
</vc-donut>
</template>
Note: setting thickness
to 100 will completely hide the diagram's text or slot content. The content will still be present in the DOM, however it won't be visible for obvious reasons.
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. |
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. |
Event | Parameter | Description |
---|---|---|
section-click | section object | Emitted when a section is clicked. section object of the clicked section is passed as an argument. Consider adding a custom property (eg: name ) to the section objects to uniquely identify them. |
Slot | Description |
---|---|
default slot | section object |
legend | Slot for plugging in your own legend. |
Issues – https://github.com/dumptyd/vue-css-donut-chart/issues
Code released under MIT license.
FAQs
Lightweight Vue component for creating donut charts
The npm package vue-css-donut-chart receives a total of 3,187 weekly downloads. As such, vue-css-donut-chart popularity was classified as popular.
We found that vue-css-donut-chart demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.