Charts

Bar Chart

A bar chart made of markup: each bar's height is a percentage in a CSS variable rather than SVG. The chart stays text, so it scales and prints.

  • chart
  • bar
  • analytics
  • no-svg

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/chart-002?lang=en

Component installs by month
42Окт: 42
58Ноя: 58
91Дек: 91
74Янв: 74
86Фев: 86
118Мар: 118
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "chart-002" (Bar Chart) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/chart-002.json

Registry item: https://vibeui.ru/r/chart-002.json
Installs to: components/vibeui/chart-002.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A bar chart made of markup: each bar's height is a percentage in a CSS variable rather than SVG. The chart stays text, so it scales and prints.

A bar chart built from markup: values above the bars, one bar highlighted in the accent, hover shading and axis labels. The height comes from a percentage in a CSS variable, so neither SVG nor a charting library is needed. Zero dependencies, one file, its own palette, no client JS.

## 3. How to use it
import { Chart002 } from "@/components/vibeui/chart-002"

<Chart002
  title="Installs by month"
  bars={[{ label: "Feb", value: 86 }, { label: "Mar", value: 118, highlight: true }]}
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-chart-002-* palette — do not swap it for your theme tokens (bg-primary, --chart-1 and the like)
- the percentage-driven bar height: converting to pixels breaks whenever the plot height changes
- the min-height on a bar — otherwise a zero value disappears and the data looks missing
- the grid as a background of the plot area rather than elements: it then stays out of the bars' layout
- the hidden label and value inside each bar together with aria-hidden on the axis — otherwise a screen reader reads the labels twice
- highlighting a bar through a data attribute rather than a colour in the data
- the <style> block inside the component — it holds the palette, the grid and the bars

## 6. You may change
- the bars array: label, value and the highlight flag
- title — the chart heading
- unit — the unit beside the values
- showValues — whether numbers appear above the bars
- the accent through the accent prop — it colours the highlighted bar
- the plot height through --vibeui-chart-002-height and outer spacing through className

## 7. Rules
- More than twelve bars will not fit: the labels start colliding.
- The axis always starts at zero, as it should. A truncated scale exaggerates the difference.
- Comparing two series needs a different component: grouped bars require a legend.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/chart-002.json
https://vibeui.ru/r/chart-002.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-chart-002-*. Столбцы — обычные элементы во flex-раскладке; высота каждого приходит переменной --vibeui-chart-002-bar-height в процентах от максимума. Сетка нарисована повторяющимся градиентом фона области, а не отдельными элементами. Подписи оси помечены aria-hidden, потому что каждое значение уже прочитано скрытым текстом внутри столбца.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import type { CSSProperties } from "react"

export type Chart002Bar = {
  label: string
  value: number
  /** Выделить столбец: текущий период, план, аномалия. */
  highlight?: boolean
}

export type Chart002Props = {
  bars?: Chart002Bar[]
  title?: string
  unit?: string
  /** Показывать значение над столбцом. */
  showValues?: boolean
  accent?: string
  className?: string
  style?: CSSProperties
}

// Идея компонента: столбцы — это раскладка, а не рисунок. Высота задаётся
// процентом в CSS-переменной каждого столбца, поэтому график остаётся
// текстом и разметкой: он масштабируется, копируется и печатается, а SVG
// и библиотека графиков не нужны.
const STYLES = `
:where([data-vibeui-block="chart-002"]){
--vibeui-chart-002-fg:oklch(0.24 0.016 265);
--vibeui-chart-002-muted:oklch(0.55 0.014 265);
--vibeui-chart-002-bg:oklch(1 0 0);
--vibeui-chart-002-border:oklch(0.91 0.006 265);
--vibeui-chart-002-grid:oklch(0.94 0.005 265);
--vibeui-chart-002-bar:oklch(0.88 0.03 262);
--vibeui-chart-002-accent:oklch(0.55 0.2 262);
--vibeui-chart-002-radius:0.875rem;
--vibeui-chart-002-height:9rem;
--vibeui-chart-002-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="chart-002"]{
display:flex;flex-direction:column;gap:1rem;
width:100%;box-sizing:border-box;padding:1.125rem 1.25rem 1rem;
border:1px solid var(--vibeui-chart-002-border);
border-radius:var(--vibeui-chart-002-radius);
background:var(--vibeui-chart-002-bg);color:var(--vibeui-chart-002-fg);
font-family:var(--vibeui-chart-002-font);
}
[data-vibeui-block="chart-002"] [data-part="title"]{margin:0;font-size:0.9375rem;font-weight:600}
/* Сетка — фон области, а не элементы: три линии повторяющимся градиентом. */
[data-vibeui-block="chart-002"] [data-part="plot"]{
position:relative;
display:flex;align-items:flex-end;gap:0.5rem;
height:var(--vibeui-chart-002-height);
background:repeating-linear-gradient(to top,transparent 0 calc(50% - 1px),var(--vibeui-chart-002-grid) calc(50% - 1px) 50%);
}
[data-vibeui-block="chart-002"] [data-part="column"]{
display:flex;flex-direction:column;justify-content:flex-end;align-items:center;gap:0.375rem;
flex:1 1 0;min-width:0;height:100%;
}
[data-vibeui-block="chart-002"] [data-part="value"]{
font-size:0.6875rem;font-variant-numeric:tabular-nums;color:var(--vibeui-chart-002-muted);
}
[data-vibeui-block="chart-002"] [data-part="bar"]{
width:100%;border-radius:0.3125rem 0.3125rem 0 0;
height:calc(var(--vibeui-chart-002-bar-height,0) * 1%);
min-height:0.25rem;
background:var(--vibeui-chart-002-bar);
transition:background-color .16s ease;
}
[data-vibeui-block="chart-002"] [data-part="column"]:hover [data-part="bar"]{background:color-mix(in oklab,var(--vibeui-chart-002-accent) 45%,var(--vibeui-chart-002-bar))}
[data-vibeui-block="chart-002"] [data-part="column"][data-highlight="true"] [data-part="bar"]{background:var(--vibeui-chart-002-accent)}
[data-vibeui-block="chart-002"] [data-part="column"][data-highlight="true"] [data-part="value"]{color:var(--vibeui-chart-002-accent);font-weight:650}
[data-vibeui-block="chart-002"] [data-part="axis"]{
display:flex;gap:0.5rem;font-size:0.6875rem;color:var(--vibeui-chart-002-muted);
}
[data-vibeui-block="chart-002"] [data-part="axis"] span{flex:1 1 0;min-width:0;text-align:center;overflow:hidden;text-overflow:ellipsis}
[data-vibeui-block="chart-002"] [data-part="sr"]{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="chart-002"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_BARS: Chart002Bar[] = [
  { label: "Окт", value: 42 },
  { label: "Ноя", value: 58 },
  { label: "Дек", value: 91 },
  { label: "Янв", value: 74 },
  { label: "Фев", value: 86 },
  { label: "Мар", value: 118, highlight: true },
]

/**
 * Столбчатая диаграмма на разметке: высота задаётся переменной, SVG не нужен.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Chart002({
  bars = DEFAULT_BARS,
  title = "Установок компонентов по месяцам",
  unit = "",
  showValues = true,
  accent,
  className,
  style,
}: Chart002Props) {
  const palette = {
    ...(accent ? { "--vibeui-chart-002-accent": accent } : null),
    ...style,
  } as CSSProperties

  const max = Math.max(...bars.map((bar) => bar.value)) || 1

  return (
    <>
      <style href="vibeui-chart-002" precedence="medium">
        {STYLES}
      </style>
      <figure
        data-vibeui-block="chart-002"
        className={className}
        style={palette}
      >
        <figcaption data-part="title">{title}</figcaption>
        <div data-part="plot">
          {bars.map((bar) => (
            <div
              key={bar.label}
              data-part="column"
              data-highlight={bar.highlight || undefined}
            >
              {showValues ? (
                <span data-part="value">
                  {bar.value}
                  {unit}
                </span>
              ) : null}
              <span
                data-part="bar"
                style={
                  {
                    "--vibeui-chart-002-bar-height": (bar.value / max) * 100,
                  } as CSSProperties
                }
              />
              <span data-part="sr">
                {bar.label}: {bar.value}
                {unit}
              </span>
            </div>
          ))}
        </div>
        <div data-part="axis" aria-hidden="true">
          {bars.map((bar) => (
            <span key={bar.label}>{bar.label}</span>
          ))}
        </div>
      </figure>
    </>
  )
}