Veil UI
Components

Chart Grid

A themed Cartesian grid for Recharts charts.

Installation

$ npx veil-ui@latest add chart-grid

Usage

import { CartesianGrid } from "recharts";

import { ChartGrid } from "@/components/ui/chart-grid";

<ChartGrid />;

Examples

Basic

Vertical

API reference

The package exports chart-grid along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.

Accessibility

  • Charts render inside a container with an explicit height so they stay responsive without layout shift.
  • Color is never the only encoding; pair charts with labels, summaries or a data table for critical information.
  • Tooltips and legends are rendered as HTML, so their text is available to assistive technology.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add chart-grid --framework vue or switch the framework in components.json.

<script setup lang="ts">
withDefaults(
  defineProps<{
    width?: number;
    height?: number;
    ticks?: number;
    vertical?: boolean;
  }>(),
  { width: 560, height: 220, ticks: 4, vertical: false },
);
</script>

<template>
  <g data-slot="chart-grid">
    <line
      v-for="tick in ticks"
      :key="`h-${tick}`"
      x1="0"
      :y1="((height - 24) / ticks) * (tick - 1) + 12"
      :x2="width"
      :y2="((height - 24) / ticks) * (tick - 1) + 12"
      stroke="var(--border)"
      stroke-dasharray="3 3"
    />
    <line
      v-for="tick in vertical ? ticks : 0"
      :key="`v-${tick}`"
      :x1="(width / ticks) * (tick - 1)"
      y1="0"
      :x2="(width / ticks) * (tick - 1)"
      :y2="height - 24"
      stroke="var(--border)"
      stroke-dasharray="3 3"
    />
  </g>
</template>

On this page