The category bar component is used to display a list of categories with a selected category highlighted.
<script lang="ts" setup>
import {
BarChart,
BarChartCategory,
} from '@returnless/focus-ui';
type Record = {
name: string;
total: number;
predicted: number;
};
const data: Record[] = [
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
];
const categories: BarChartCategory<Record>[] = [
{ label: 'Predicted', accessorKey: 'predicted', color: 'green' },
];
</script>
<template>
<BarChart :data="data" :categories="categories" label-accessor-key="name" />
</template><script lang="ts" setup>
import {
BarChart,
BarChartCategory,
} from '@returnless/focus-ui';
type Record = {
name: string;
total: number;
predicted: number;
};
const data: Record[] = [
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
];
const categories: BarChartCategory<Record>[] = [
{ label: 'Predicted', accessorKey: 'predicted', color: 'green' },
{ label: 'Total', accessorKey: 'total', color: 'purple' },
];
</script>
<template>
<BarChart :data="data" :categories="categories" label-accessor-key="name" />
</template>Use the stacked prop to display a stacked bar chart.
<script lang="ts" setup>
import {
BarChart,
BarChartCategory,
} from '@returnless/focus-ui';
type Record = {
name: string;
total: number;
predicted: number;
};
const data: Record[] = [
{ name: 'Jan', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
{ name: 'Feb', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
{ name: 'Mar', total: Math.floor(Math.random() * 2000) + 500, predicted: Math.floor(Math.random() * 2000) + 500 },
];
const categories: BarChartCategory<Record>[] = [
{ label: 'Predicted', accessorKey: 'predicted', color: 'green' },
{ label: 'Total', accessorKey: 'total', color: 'purple' },
];
</script>
<template>
<BarChart :data="data" :categories="categories" label-accessor-key="name" stacked />
</template>