chart
shadcn-vue/chartFreeComponent
shadcn-vue publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by shadcn-vue on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-vue.com/r/styles/new-york/chart.jsonSource
1<script setup lang="ts">2import type { BulletLegendItemInterface } from "@unovis/ts"3import type { Component } from "vue"4import { omit } from "@unovis/ts"5import { VisCrosshair, VisTooltip } from "@unovis/vue"6import { createApp } from "vue"7import { ChartTooltip } from "."89const props = withDefaults(defineProps<{10 colors: string[]11 index: string12 items: BulletLegendItemInterface[]13 customTooltip?: Component14}>(), {15 colors: () => [],16})1718// Use weakmap to store reference to each datapoint for Tooltip19const wm = new WeakMap()20function template(d: any) {21 if (wm.has(d)) {22 return wm.get(d)23 }24 else {25 const componentDiv = document.createElement("div")26 const omittedData = Object.entries(omit(d, [props.index])).map(([key, value]) => {27 const legendReference = props.items.find(i => i.name === key)28 return { ...legendReference, value }29 })30 const TooltipComponent = props.customTooltip ?? ChartTooltip31 createApp(TooltipComponent, { title: d[props.index].toString(), data: omittedData }).mount(componentDiv)32 wm.set(d, componentDiv.innerHTML)33 return componentDiv.innerHTML34 }35}3637function color(d: unknown, i: number) {38 return props.colors[i] ?? "transparent"39}40</script>4142<template>43 <VisTooltip :horizontal-shift="20" :vertical-shift="20" />44 <VisCrosshair :template="template" :color="color" />45</template>
What it pulls in
npm packages
Files it writes
More from shadcn-vue
All 65 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | shadcn-vue | Components | Free | 2 deps · 5 files | |
| alertalert | shadcn-vue | Components | Free | no deps · 4 files | |
| alert-dialogalert-dialog | shadcn-vue | Components | Free | 2 deps · 10 files | |
| aspect-ratioaspect-ratio | shadcn-vue | Components | Free | 1 dep · 2 files | |
| attachmentattachment | shadcn-vue | Components | Free | 1 dep · 10 files | |
| avataravatar | shadcn-vue | Components | Free | 2 deps · 4 files | |
| badgebadge | shadcn-vue | Components | Free | 2 deps · 2 files | |
| breadcrumbbreadcrumb | shadcn-vue | Components | Free | 1 dep · 8 files |
