UIStatistic
UIStatistic
A component for displaying statistical data with support for titles, trends, and graphs.
<template> <UIStatistic :title="$t('stats.views')" :type="'success'" :trendTitle="$t('stats.trend')" :showGraph="true" :titleTooltipContent="$t('stats.tooltip')" > 1,234,567 <template #badge> <div class="flex items-center gap-1 text-success-600"> <ArrowUpIcon class="w-4 h-4" /> <span>23.4%</span> </div> </template> <template #graph> <SparklineChart :data="chartData" /> </template> </UIStatistic></template>
<script setup lang="ts">const chartData = ref([30, 40, 35, 50, 49, 60, 70, 91, 125])</script>Props
title(string): Statistic titletype(‘success’ | ‘error’ | ‘warning’ | ‘info’): Statistic typetrendTitle(string): Trend descriptionshowGraph(boolean): Show trend graphtitleTooltipContent(string): Tooltip content for titleoptions(Array): Dropdown optionsloading(boolean): Show loading stateprecision(number): Number of decimal placesprefix(string): Prefix for the valuesuffix(string): Suffix for the valueseparator(string): Thousand separatordecimal(string): Decimal separator
Events
update:value: Emitted when value changesoptionSelect: Emitted when dropdown option is selected
Slots
default: Main content (number/value)prefix: Content before the valuesuffix: Content after the valuebadge: Badge/trend indicator contentgraph: Custom graph contenttitle: Custom title contenticon: Custom icon content
Usage Examples
- Basic Usage:
<template> <UIStatistic title="Total Users"> 12,346 </UIStatistic></template>- With Trend Indicator:
<template> <UIStatistic title="Revenue" type="success" prefix="$" > 23,456 <template #badge> <div class="flex items-center text-success-600"> <ArrowUpIcon /> <span>12.3%</span> </div> </template> </UIStatistic></template>- With Graph:
<template> <UIStatistic title="Page Views" :showGraph="true" > 45,678 <template #graph> <LineChart :data="viewsData" :height="50" :width="120" /> </template> </UIStatistic></template>- Loading State:
<template> <UIStatistic title="Processing" :loading="isLoading" > {{ processedCount }} </UIStatistic></template>Best Practices
-
Data Display:
- Use appropriate number formatting
- Show relevant trends
- Include helpful tooltips
- Provide context with icons
-
Visual Hierarchy:
- Emphasize important numbers
- Use consistent styling
- Group related statistics
- Apply appropriate spacing
-
Accessibility:
- Include descriptive labels
- Provide trend descriptions
- Use semantic markup
- Support screen readers
-
Responsiveness:
- Adapt to container width
- Handle long numbers
- Resize graphs appropriately
- Stack on smaller screens
-
Performance:
- Optimize graph rendering
- Cache calculations
- Lazy load graphs
- Minimize animations
Common Patterns
- Dashboard Stats:
<template> <div class="grid grid-cols-1 md:grid-cols-3 gap-4"> <UIStatistic title="Users" type="info" :showGraph="true" > {{ userCount }} </UIStatistic>
<UIStatistic title="Revenue" type="success" prefix="$" > {{ revenue }} </UIStatistic>
<UIStatistic title="Conversion" type="warning" suffix="%" > {{ conversionRate }} </UIStatistic> </div></template>- Comparison Stats:
<template> <div class="flex gap-4"> <UIStatistic title="This Month" :type="monthlyTrend.type" > {{ monthlyTrend.value }} <template #badge> {{ monthlyTrend.percentage }}% </template> </UIStatistic>
<UIStatistic title="Last Month" type="info" > {{ lastMonth }} </UIStatistic> </div></template>