UI组件前端【免费下载链接】shadcn-vueVue port of shadcn-ui项目地址https://gitcode.com/gh_mirrors/sh/shadcn-vue点击查看免费下载本文围绕 shadcn-vue 仓库中图表体系deprecated/www目录下基于 Unovis 构建的 Charts 模块里的AreaChart面积图组件展开完整梳理其全部 Props/Emit API、安装与 CSS 变量前置配置并结合仓库内的 Demo 与源码实现讲解基础面积图、Sparkline 迷你图、自定义 Tooltip 三类实战用法。读完本文你将能够在自己的 Vue 3 项目中独立接入并深度定制 AreaChart包括控制坐标轴、图例、渐变与曲线类型以及注入自定义提示框组件。一、AreaChart 是什么AreaChart面积图通过在折线下方填充区域来展示数据随时间变化的趋势与模式适合表达总量走势实际值与预测值对比等场景。在 shadcn-vue 仓库中它属于 Charts 图表模块 下的四种图表类型Area / Line / Bar / Donut之一官方文档对它的定位是An area chart visually represents data over time, displaying trends and patterns through filled-in areas under a line graph.需要说明的是该组件处于Legacy / Alpha状态官方文档明确标注 Component will be moved to extended repo with Tailwind v4 support且仅支持 Vue 3.3。当前仓库中的实现位于 deprecated/www/src/registry/new-york/ui/chart-area/底层构建于 Unovis模块化数据可视化框架之上设计上参考了 Tremor。组件对外暴露的 API 文档为自动生成的 AreaChart.md它被include到 面积图文档页 的 API 章节中下方所有参数说明均与该文件及 源码类型定义 保持一致。二、安装与前置配置1. 添加组件在项目根目录执行npx shadcn-vuelatest add chart-area该命令会向项目注入chart-area组件即 AreaChart.vue 及其导出同时还需要随附的chart相关子组件ChartLegend、ChartCrosshair等见 chart 目录。2. 全局 CSS 变量配置图表组件依赖 Unovis 的 CSS 变量来渲染 Tooltip 与坐标轴颜色。官方文档要求向tailwind.css的layer base中追加以下样式layer base { :root { /* ... */ --vis-tooltip-background-color: none !important; --vis-tooltip-border-color: none !important; --vis-tooltip-text-color: none !important; --vis-tooltip-shadow-color: none !important; --vis-tooltip-backdrop-filter: none !important; --vis-tooltip-padding: none !important; --vis-primary-color: var(--primary); /* change to any hsl value you want */ --vis-secondary-color: 160 81% 40%; --vis-text-color: var(--muted-foreground); } }要点--vis-tooltip-*系列变量统一置为none !important是为了让 Unovis 原生 Tooltip 样式失效从而使用 shadcn-vue 自绘的 ChartTooltip.vue / ChartCrosshair.vue--vis-primary-color建议映射到你的主题主色var(--primary)--vis-secondary-color默认为示例中的绿色可按需改成任意 hsl 值--vis-text-color用于坐标轴刻度文字颜色源码中两个VisAxis均通过tick-text-colorhsl(var(--vis-text-color))读取它见 AreaChart.vue。如果你的组件没有使用 CSS 变量体系则需要把--vis-primary-color与--vis-text-color替换为你想要的固定 hsl 值并且记得一并提供暗色模式下的取值。三、API 完整参考Props 与 Emits以下参数表完整继承了 AreaChart.md 的内容并与 index.ts 中的BaseChartProps泛型定义逐一对应T extends Recordstring, any表示数据项为字典对象。Props名称类型必填默认值说明dataRecordstring, any[]是—源数据每一项是一个字典对象categoriesstring[]是—从数据中挑选出的分类字段用于填充图例与 Tooltipindexstring是—设置映射到坐标轴的键X 轴分类键colorsstring[]否—自定义图表颜色默认由defaultColors按分类数量生成marginSpacing否{ top: 0, bottom: 0, left: 0, right: 0 }容器四周的边距filterOpacitynumber否0.2非选中图例中置灰字段的透明度xFormatter(tick: number \| Date, i: number, ticks: number[] \| Date[]) string否—格式化 X 轴标签的函数yFormatter(tick: number \| Date, i: number, ticks: number[] \| Date[]) string否—格式化 Y 轴标签的函数showXAxisboolean否true控制 X 轴显隐showYAxisboolean否true控制 Y 轴显隐showTooltipboolean否true控制 Tooltip 显隐showLegendboolean否true控制图例显隐showGridLineboolean否true控制网格线显隐customTooltipComponent否—传入自定义 Tooltip 组件curveTypeCurveType否CurveType.MonotoneX曲线类型来自unovis/tsshowGradientboolean否true控制面积渐变填充的显隐从源码实现看所有带默认值的 Props 都由withDefaults集中声明AreaChart.vue其中margin使用工厂函数返回新对象以避免共享引用。Emits名称载荷类型说明legendItemClick[d: BulletLegendItemInterface, i: number]点击图例某一项时触发参数为图例项对象与索引legendItemClick由内部的handleLegendItemClick转发见 AreaChart.vue可用于监听用户对图例项的交互例如联动外部筛选器。四、基础用法双分类面积图以官方 AreaChartDemo.vue 为例展示实际值 total 预测值 predicted双曲线面积图script setup langts import { AreaChart } from /registry/new-york/ui/chart-area const data [ { 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 }, { name: Apr, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, { name: May, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, { name: Jun, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, { name: Jul, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, ] /script template AreaChart :datadata indexname :categories[total, predicted] / /template关键点indexname把数据中的name字段映射为 X 轴分类键categories传入两个字段名图例与 Tooltip 会按这两个分类渲染不传colors时源码通过defaultColors(props.categories.length)见 AreaChart.vue按分类数量生成默认配色。也可以显式传colors覆盖默认色template AreaChart :datadata indexname :categories[total, predicted] :colors[blue, pink, orange, red] / /template五、Sparkline 迷你走势图把面积图变成极简的 Sparkline只需隐藏坐标轴、网格线与图例。官方 AreaChartSparkline.vue 给出了完整示例script setup langts import { CurveType } from unovis/ts import { AreaChart } from /registry/new-york/ui/chart-area const data [ { name: Jan, total: Math.floor(Math.random() * 2000) 1000 }, { name: Feb, total: Math.floor(Math.random() * 2000) 1000 }, { name: Mar, total: Math.floor(Math.random() * 2000) 1000 }, { name: Apr, total: Math.floor(Math.random() * 2000) 1000 }, { name: May, total: Math.floor(Math.random() * 2000) 1000 }, { name: Jun, total: Math.floor(Math.random() * 2000) 1000 }, { name: Jul, total: Math.floor(Math.random() * 2000) 1000 }, { name: Aug, total: Math.floor(Math.random() * 2000) 1000 }, { name: Sep, total: Math.floor(Math.random() * 2000) 1000 }, { name: Oct, total: Math.floor(Math.random() * 2000) 1000 }, { name: Nov, total: Math.floor(Math.random() * 2000) 1000 }, { name: Dec, total: Math.floor(Math.random() * 2000) 1000 }, ] /script template AreaChart classh-[100px] w-[400px] indexname :datadata :categories[total] :show-grid-linefalse :show-legendfalse :show-x-axisfalse :show-y-axisfalse :curve-typeCurveType.Linear / /template要点通过:show-x-axisfalse、:show-y-axisfalse、:show-grid-linefalse、:show-legendfalse关闭所有辅助元素组件根节点是w-full h-[400px]的容器通过class覆盖为h-[100px] w-[400px]控制尺寸源码在根节点使用cn(w-full h-[400px] flex flex-col items-end, $attrs.class ?? )合并类名见 AreaChart.vueCurveType.Linear换成直线曲线视觉效果更干脆。六、自定义 Tooltip如果默认 Tooltip 不满足需求可通过customTooltip传入一个自定义 Vue 组件。官方 AreaChartCustomTooltip.vue 示例script setup langts import { AreaChart } from /registry/new-york/ui/chart-area import CustomChartTooltip from ./CustomChartTooltip.vue const data [ { 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 }, { name: Apr, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, { name: May, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, { name: Jun, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, { name: Jul, total: Math.floor(Math.random() * 2000) 500, predicted: Math.floor(Math.random() * 2000) 500 }, ] /script template AreaChart indexname :datadata :categories[total, predicted] :custom-tooltipCustomChartTooltip / /template自定义组件接收固定的 Props 结构见 CustomChartTooltip.vuedefineProps{ title?: string data: { name: string color: string value: any }[] }()其中data数组的每一项对应一个分类name为分类名color为该分类在图中的颜色value为当前悬停点的数值。仓库自带的默认实现是 ChartTooltip.vue你可以参考它来编写自己的样式例如用Card组件把每项渲染成色条 名称 数值的布局script setup langts import { Card, CardContent } from /registry/new-york/ui/card defineProps{ title?: string data: { name: string color: string value: any }[] }() /script template Card classtext-sm CardContent classp-3 min-w-[180px] flex flex-col gap-2 div v-for(item, key) in data :keykey classflex justify-between items-center div classflex items-center span classw-1 h-7 mr-4 rounded-full :style{ background: item.color } / span{{ item.name }}/span /div span classfont-semibold ml-4{{ item.value }}/span /div /CardContent /Card /template注意customTooltip仅在showTooltip为true时生效源码中ChartCrosshair只有在showTooltip为真时才渲染并把custom-tooltip透传给它见 AreaChart.vue。七、源码实现剖析理解 AreaChart.vue 的实现有助于判断各 Props 的真实行为图层结构根容器下依次是ChartLegend图例受showLegend控制、VisXYContainerUnovis 坐标系容器内部通过v-for按categories分别渲染一组VisArea面积VisLine描边折线图层渐变填充组件使用useId()生成唯一 IDchartRef在defs中为每个颜色定义linearGradient。当showGradient为true时渐变从stop-opacity 0.45%过渡到095%关闭时则用纯色stop见 AreaChart.vue图例联动置灰面积与折线的透明度都读取legendItems中对应项的inactive状态被置灰的分类透明度降为filterOpacity默认0.2这是filterOpacity参数的真实作用点AreaChart.vue 与 L109坐标轴X 轴默认grid-linefalse且tick-linefalsetick 文案默认由data[v]?.[index]取回原始分类名Y 轴网格线由showGridLine控制并给网格线附加了text-muted样式类挂载时序通过useMounted()延迟设置容器高度为100%避免 SSR/首屏时 Unovis 容器高度计算异常响应式类型组件使用 Vue 3.3 的genericT extends Recordstring, any泛型语法这也是文档强调仅支持 Vue 3.3的直接原因。八、注意事项与局限Legacy 状态Charts 模块整体标注为 Legacy官方计划将其迁移到独立扩展仓库并适配 Tailwind v4当前仓库内实现对应 Tailwind v3 时代版本要求必须使用 Vue 3.3泛型 SFC 与useId依赖前置样式不可省略未配置--vis-tooltip-*与--vis-primary-color等变量会导致 Tooltip 样式异常或颜色缺失随机数据示例官方 Demo 使用Math.random()生成演示数据实际使用时应替换为稳定、真实的数据源避免每次渲染数值跳变尺寸控制组件默认高度400px通过class覆盖如需精确控制图表绘制区域可配合marginProp 调整容器边距。九、相关参考文件API 元数据自动生成AreaChart.md官方文档页area.md、charts.md组件实现AreaChart.vue、index.ts官方示例AreaChartDemo.vue、AreaChartSparkline.vue、AreaChartCustomTooltip.vue、CustomChartTooltip.vue配套子组件chart 目录赞分享UI组件前端【免费下载链接】shadcn-vueVue port of shadcn-ui项目地址https://gitcode.com/gh_mirrors/sh/shadcn-vue点击查看免费下载相关推荐ToolJet 表格组件服务端分页实战指南基于 limit/offset 实现大数据量表格的高性能加载ToolJet 表格组件服务端分页实战指南基于 limit/offset 实现大数据量表格的高性能加载 导读 当表格数据量达到数万甚至数十万行时把全部数据一UI组件前端p5.js WebGL 模式架构深度解析RendererGL、Shader、Texture 与 Geometry 四大核心对象p5.js WebGL 模式架构深度解析RendererGL、Shader、Texture 与 Geometry 四大核心对象 本文面向 p5.js 的贡献者UI组件前端shadcn-vue 组件注册表 FAQ 实战指南复杂组件结构、自定义 Tailwind 颜色与动画配置shadcn vue 组件注册表 FAQ 实战指南复杂组件结构、自定义 Tailwind 颜色与动画配置 组件注册表registry是 shadcn vuUI组件前端上一篇Ktor应用逆向实战android-reverse-engineering-skill如何抓出字符串路径与Auth插件下一篇Kubernetes AI控制台实战指南企业级K8M深度解析与最佳实践创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
企业数字化 ERP 产品动态
相关推荐
2 个参数、5 级目标:把 Home Assistant SmartTub 主过滤循环调到低电价时段的完整指南 2 个参数、5 级目标:把 Home Assistant SmartTub 主过滤循环调到低电价时段的完整指南 【免费下载链接】home-assistant.io :blue_book: Home Assistant User documentation 项目地址: https://gitcode.com/GitHub_Trending/ho/home-assistant.io
这个月的电… · 2026/9/24 13:48:49
3 步拿到电子课本 PDF:tchMaterial-parser 完整使用指南 3 步拿到电子课本 PDF:tchMaterial-parser 完整使用指南 【免费下载链接】tchMaterial-parser 国家中小学智慧教育平台 电子课本下载工具,帮助您从智慧教育平台中获取电子课本的 PDF 文件网址并进行下载,让您更方便地获取课本内容。 项目地… · 2026/9/24 13:48:43
RT-Thread 微芯 SAM C21 平台 Flash 驱动(HAL Flash)技术详解 操作系统嵌入式物联网嵌入式OSRTOS 【免费下载链接】rt-thread RT-Thread is an open source IoT Real-Time Operating System (RTOS). https://rt-thread.github.io/rt-thread/ 项目地址: https://gitcode.com/gh_mirrors/rt/rt-thread 点击查看 免费下载 本篇技术… · 2026/9/24 14:26:59
11_神经网络基础[pytorch框架与神经网络基础] 神经网络
人工神经网络( Artificial Neural Network, 简写为ANN)也简称为神经网络(NN),是一种模仿生物神经网络结构和功能的计算模型。是一种计算模型简称:NN1. 神经元与神经网络
1.1 神经元
生物神经元:当电信号通过树突进入到细胞核时,会逐渐聚集电荷。达到一定的电位后,细胞… · 2026/9/24 14:26:53
反激变压器设计实战:12V 1A电源从磁芯选型到绕制工艺 /* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views … · 2026/9/24 14:26:53
Tea 中间件机制深度解析:如何快速为仓颉 Web 框架打造请求拦截链 Tea 中间件机制深度解析:如何快速为仓颉 Web 框架打造请求拦截链 【免费下载链接】tea 仓颉语言轻量级的、函数式的、高效的HTTP Web后端框架 项目地址: https://gitcode.com/Cangjie-SIG/tea
🍵 Tea 是一个用仓颉(Cangjie)… · 2026/9/24 14:26:53
基于YOLOv8的渔船作业监控系统:从环境搭建到边缘部署全流程 简介:这是一套面向计算机、人工智能、自动化等专业学生与教师的毕业设计级项目资源,围绕YOLOv8实现渔船作业监控系统,可用于毕设、课程设计、大作业或项目立项演示。压缩包共97个文件,约24.21MB,以70个Python源码文件为… · 2026/9/24 0:00:13
1D-CNN时间序列建模实战:从Conv1d原理到工业落地 简介:面向时间序列数据建模的一维卷积神经网络完整实现,适合深度学习入门者及需要快速验证时序模型的研究者,能够从音频、文本、传感器或股价等序列中挖掘局部特征与时间依赖。压缩包体积很小,只有3KB,内含3个Python脚… · 2026/9/24 0:00:26
柔软的L:汉语语流中被忽视的舌肌张力控制 1. 这个“L”不是字母表里的L,而是舌尖上的L最近在几个方言群和语音教学社群里,反复看到有人发一句:“也说字母L:柔软的长舌”。初看以为是英语发音课笔记,点开才发现全是方言爱好者、播音系学生、语言康复师甚至戏曲演… · 2026/9/24 0:00:44