Charts

Ranking Bars

A ranking in horizontal bars: length is easier to compare than angle, and the numbers on the right answer "by how much".

  • chart
  • ranking
  • bars
  • top

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-004?lang=en

Views this week
  1. Каталог4820
  2. Главная3140
  3. Страница компонента2260
  4. Блоки1180
  5. Документация640
Единица измерения: visits
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-004" (Ranking Bars) 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-004.json

Registry item: https://vibeui.ru/r/chart-004.json
Installs to: components/vibeui/chart-004.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 ranking in horizontal bars: length is easier to compare than angle, and the numbers on the right answer "by how much".

A horizontal ranking: label, number and bar per row, the leader highlighted, shares measured against the maximum. Zero dependencies, one file, no client JS.

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

<Chart004 rows={[{ label: "Catalog", value: 4820 }]} unit="visits" />

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-004-* palette — do not swap it for your theme tokens
- horizontal bars: length compares better than height or angle
- the numbers beside the bars — without them you see who leads, not by how much
- role="img" with a label on every bar
- marking the leader by saturation rather than a separate colour
- the row grid: numbers must line up in a column

## 6. You may change
- the rows array and their order
- title and unit
- the accent through the accent prop
- the bar height

## 7. Rules
- Rows are not sorted automatically: the caller sets the order, usually descending.
- Beyond seven rows a ranking becomes a list: fold the rest into "other".
- Shares are relative to the maximum, not the sum: this is a ranking, not a breakdown.
- 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-004.json
https://vibeui.ru/r/chart-004.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-chart-004-*. Серверный: хуков нет. Каждая строка — сетка из подписи, числа и полосы во всю ширину, поэтому числа стоят ровным столбцом. Ширина заливки — процент от максимума, у полосы есть role="img" с подписью, лидер выделен насыщенностью.

Component source

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

import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Chart004Row = {
  label: string
  value: number
}

export type Chart004Props = Omit<
  ComponentPropsWithoutRef<"figure">,
  "children" | "title"
> & {
  title?: string
  rows?: Chart004Row[]
  unit?: string
  accent?: string
}

// Идея компонента: рейтинг горизонтальными полосами. Длину глаз сравнивает
// точнее, чем высоту и угол, поэтому топ-5 всегда ложится в горизонтальные
// полосы. Числа стоят справа от каждой полосы: без них диаграмма отвечает
// «кто больше», но не «насколько».
const STYLES = `
:where([data-vibeui-block="chart-004"]){
--vibeui-chart-004-bg:oklch(1 0 0);
--vibeui-chart-004-fg:oklch(0.22 0.014 265);
--vibeui-chart-004-muted:oklch(0.56 0.014 265);
--vibeui-chart-004-border:oklch(0.91 0.006 265);
--vibeui-chart-004-track:oklch(0.95 0.004 265);
--vibeui-chart-004-accent:oklch(0.55 0.17 265);
--vibeui-chart-004-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="chart-004"]{
display:flex;flex-direction:column;gap:0.625rem;
width:100%;max-width:22rem;box-sizing:border-box;margin:0;padding:0.875rem;
background:var(--vibeui-chart-004-bg);
border:1px solid var(--vibeui-chart-004-border);border-radius:0.875rem;
color:var(--vibeui-chart-004-fg);font-family:var(--vibeui-chart-004-font);
}
[data-vibeui-block="chart-004"] [data-part="title"]{margin:0;font-size:0.875rem;font-weight:650}
[data-vibeui-block="chart-004"] ol{display:flex;flex-direction:column;gap:0.5rem;margin:0;padding:0;list-style:none}
/* Подпись, полоса и число в одной сетке: колонки не разъезжаются между
   строками, и числа стоят ровным столбцом. */
[data-vibeui-block="chart-004"] [data-part="row"]{
display:grid;grid-template-columns:1fr auto;gap:0.25rem 0.75rem;
font-size:0.8125rem;
}
[data-vibeui-block="chart-004"] [data-part="label"]{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
[data-vibeui-block="chart-004"] [data-part="value"]{font-weight:650;font-variant-numeric:tabular-nums}
[data-vibeui-block="chart-004"] [data-part="track"]{
grid-column:1 / -1;height:0.5rem;border-radius:9999px;
background:var(--vibeui-chart-004-track);overflow:hidden;
}
[data-vibeui-block="chart-004"] [data-part="fill"]{
display:block;height:100%;border-radius:inherit;
background:var(--vibeui-chart-004-accent);
}
/* Первая строка ярче: лидер должен читаться сразу. */
[data-vibeui-block="chart-004"] li:first-child [data-part="fill"]{background:var(--vibeui-chart-004-accent)}
[data-vibeui-block="chart-004"] li:not(:first-child) [data-part="fill"]{
background:color-mix(in oklab,var(--vibeui-chart-004-accent) 55%,oklch(0.9 0.01 265));
}
[data-vibeui-block="chart-004"] [data-part="unit"]{font-size:0.75rem;color:var(--vibeui-chart-004-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="chart-004"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ROWS: Chart004Row[] = [
  { label: "Каталог", value: 4820 },
  { label: "Главная", value: 3140 },
  { label: "Страница компонента", value: 2260 },
  { label: "Блоки", value: 1180 },
  { label: "Документация", value: 640 },
]

/**
 * Рейтинг горизонтальными полосами: длину глаз сравнивает точнее угла.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Chart004({
  title = "Просмотры за неделю",
  rows = DEFAULT_ROWS,
  unit = "визитов",
  accent,
  className,
  style,
  ...props
}: Chart004Props) {
  const max = Math.max(...rows.map((row) => row.value), 1)

  const palette = {
    ...(accent ? { "--vibeui-chart-004-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-chart-004" precedence="medium">
        {STYLES}
      </style>
      <figure
        {...props}
        data-vibeui-block="chart-004"
        className={className}
        style={palette}
      >
        <figcaption data-part="title">{title}</figcaption>
        <ol>
          {rows.map((row) => (
            <li key={row.label} data-part="row">
              <span data-part="label">{row.label}</span>
              <span data-part="value">{row.value}</span>
              <span
                data-part="track"
                role="img"
                aria-label={`${row.label}: ${row.value} ${unit}`}
              >
                <span
                  data-part="fill"
                  style={{ width: `${Math.max(2, (row.value / max) * 100)}%` }}
                />
              </span>
            </li>
          ))}
        </ol>
        <figcaption data-part="unit">Единица измерения: {unit}</figcaption>
      </figure>
    </>
  )
}