Shadcn Chart Donut

VShadcnChartDonut component renders a donut or pie chart using the Unovis library. It supports custom tooltips, a legend, and the ability to configure various chart properties such as colors, sorting, and label formatting.

Usage

This component uses the unovis library, which must be installed in your project. If not already added, you can install it using:

bash
yarn add @unovis/ts @unovis/vue

Import the VShadcnChartDonut component into your Vue file:

vue
import VShadcnChartDonut from 'UiKit/components/VCharts/VShadcnChartDonut/VShadcnChartDonut.vue';

Props

PropTypeDescriptionDefault
dataArray<T>The data to be displayed in the chart.-
colorsArray<string>The colors to be used for each segment of the chart.-
indexstringThe key for the index of each data item in the chart.-
marginFunctionA function returning the margin configuration for the chart.{ top: 0, bottom: 0, left: 0, right: 0 }
showLegendBooleanWhether to display the legend.true
showTooltipBooleanWhether to show the tooltip.true
filterOpacityNumberThe opacity for inactive segments.0.2
categoryKeyOfTThe name of the key containing the quantitative chart values.-
type`'donut''pie'`The type of the chart.
sortFunctionFunctionA function to sort the segments of the chart.undefined
valueFormatterFunctionA function to format the value displayed on the chart.(tick: number) => \${tick}``
customTooltipComponentA custom tooltip component to render.-
showCenterBooleanWhether to show a central label in the donut chart.-
titleStringThe title to display above the chart.-

Example Usage

vue
<script setup lang="ts">
import VShadcnChartDonut from 'UiKit/components/VCharts/VShadcnChartDonut/VShadcnChartDonut.vue';
const data = [
  { name: 'Jan', total: 10 },
  { name: 'Feb', total: 20 },
  { name: 'Mar', total: 25 },
  { name: 'Apr', total: 5 },
  { name: 'May', total: 30 },
  { name: 'Jun', total: 10 },
];
const valueFormatter = (tick: number) => `${tick} %`;
</script>

<template>
      <VShadcnChartDonut
          title="Geographic Diversification"
          index="name"
          category="total"
          :data="data"
          :value-formatter="valueFormatter"
        />
</template>
Help Ukraine to stop russian aggression