Skip to content
WebJs
Menu
Trace, Code Block and AI Elements

Beautiful Charts & Graphs

A collection of ready-to-use chart components, drawn as SVG on the server. From basic charts to rich data displays, copy and paste into your apps.

Area Charts

Area Chart

Code

View the code for the chart.

components/charts/chart-area-interactive.ts
/**
 * An interactive area chart, a chart block ported from shadcn/ui's chart-area-interactive.
 *
 * Installed by `npx @webjsdev/ui add chart-area-interactive` at
 * `components/charts/chart-area-interactive.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaInteractive()}`.
 *
 * The range picker is a native `<select>` inside `<ui-select>`, and all three
 * ranges are served; the card shows the chosen one through `:has()`, so the
 * picker works with JavaScript off. shadcn's re-renders one chart from React
 * state instead.
 */
import { html, svg } from '@webjsdev/core';
import { cn } from '../../lib/utils/cn.ts';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { selectTriggerClass } from '../ui/select.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { date: '2024-04-01', desktop: 222, mobile: 150 },
  { date: '2024-04-02', desktop: 97, mobile: 180 },
  { date: '2024-04-03', desktop: 167, mobile: 120 },
  { date: '2024-04-04', desktop: 242, mobile: 260 },
  { date: '2024-04-05', desktop: 373, mobile: 290 },
  { date: '2024-04-06', desktop: 301, mobile: 340 },
  { date: '2024-04-07', desktop: 245, mobile: 180 },
  { date: '2024-04-08', desktop: 409, mobile: 320 },
  { date: '2024-04-09', desktop: 59, mobile: 110 },
  { date: '2024-04-10', desktop: 261, mobile: 190 },
  { date: '2024-04-11', desktop: 327, mobile: 350 },
  { date: '2024-04-12', desktop: 292, mobile: 210 },
  { date: '2024-04-13', desktop: 342, mobile: 380 },
  { date: '2024-04-14', desktop: 137, mobile: 220 },
  { date: '2024-04-15', desktop: 120, mobile: 170 },
  { date: '2024-04-16', desktop: 138, mobile: 190 },
  { date: '2024-04-17', desktop: 446, mobile: 360 },
  { date: '2024-04-18', desktop: 364, mobile: 410 },
  { date: '2024-04-19', desktop: 243, mobile: 180 },
  { date: '2024-04-20', desktop: 89, mobile: 150 },
  { date: '2024-04-21', desktop: 137, mobile: 200 },
  { date: '2024-04-22', desktop: 224, mobile: 170 },
  { date: '2024-04-23', desktop: 138, mobile: 230 },
  { date: '2024-04-24', desktop: 387, mobile: 290 },
  { date: '2024-04-25', desktop: 215, mobile: 250 },
  { date: '2024-04-26', desktop: 75, mobile: 130 },
  { date: '2024-04-27', desktop: 383, mobile: 420 },
  { date: '2024-04-28', desktop: 122, mobile: 180 },
  { date: '2024-04-29', desktop: 315, mobile: 240 },
  { date: '2024-04-30', desktop: 454, mobile: 380 },
  { date: '2024-05-01', desktop: 165, mobile: 220 },
  { date: '2024-05-02', desktop: 293, mobile: 310 },
  { date: '2024-05-03', desktop: 247, mobile: 190 },
  { date: '2024-05-04', desktop: 385, mobile: 420 },
  { date: '2024-05-05', desktop: 481, mobile: 390 },
  { date: '2024-05-06', desktop: 498, mobile: 520 },
  { date: '2024-05-07', desktop: 388, mobile: 300 },
  { date: '2024-05-08', desktop: 149, mobile: 210 },
  { date: '2024-05-09', desktop: 227, mobile: 180 },
  { date: '2024-05-10', desktop: 293, mobile: 330 },
  { date: '2024-05-11', desktop: 335, mobile: 270 },
  { date: '2024-05-12', desktop: 197, mobile: 240 },
  { date: '2024-05-13', desktop: 197, mobile: 160 },
  { date: '2024-05-14', desktop: 448, mobile: 490 },
  { date: '2024-05-15', desktop: 473, mobile: 380 },
  { date: '2024-05-16', desktop: 338, mobile: 400 },
  { date: '2024-05-17', desktop: 499, mobile: 420 },
  { date: '2024-05-18', desktop: 315, mobile: 350 },
  { date: '2024-05-19', desktop: 235, mobile: 180 },
  { date: '2024-05-20', desktop: 177, mobile: 230 },
  { date: '2024-05-21', desktop: 82, mobile: 140 },
  { date: '2024-05-22', desktop: 81, mobile: 120 },
  { date: '2024-05-23', desktop: 252, mobile: 290 },
  { date: '2024-05-24', desktop: 294, mobile: 220 },
  { date: '2024-05-25', desktop: 201, mobile: 250 },
  { date: '2024-05-26', desktop: 213, mobile: 170 },
  { date: '2024-05-27', desktop: 420, mobile: 460 },
  { date: '2024-05-28', desktop: 233, mobile: 190 },
  { date: '2024-05-29', desktop: 78, mobile: 130 },
  { date: '2024-05-30', desktop: 340, mobile: 280 },
  { date: '2024-05-31', desktop: 178, mobile: 230 },
  { date: '2024-06-01', desktop: 178, mobile: 200 },
  { date: '2024-06-02', desktop: 470, mobile: 410 },
  { date: '2024-06-03', desktop: 103, mobile: 160 },
  { date: '2024-06-04', desktop: 439, mobile: 380 },
  { date: '2024-06-05', desktop: 88, mobile: 140 },
  { date: '2024-06-06', desktop: 294, mobile: 250 },
  { date: '2024-06-07', desktop: 323, mobile: 370 },
  { date: '2024-06-08', desktop: 385, mobile: 320 },
  { date: '2024-06-09', desktop: 438, mobile: 480 },
  { date: '2024-06-10', desktop: 155, mobile: 200 },
  { date: '2024-06-11', desktop: 92, mobile: 150 },
  { date: '2024-06-12', desktop: 492, mobile: 420 },
  { date: '2024-06-13', desktop: 81, mobile: 130 },
  { date: '2024-06-14', desktop: 426, mobile: 380 },
  { date: '2024-06-15', desktop: 307, mobile: 350 },
  { date: '2024-06-16', desktop: 371, mobile: 310 },
  { date: '2024-06-17', desktop: 475, mobile: 520 },
  { date: '2024-06-18', desktop: 107, mobile: 170 },
  { date: '2024-06-19', desktop: 341, mobile: 290 },
  { date: '2024-06-20', desktop: 408, mobile: 450 },
  { date: '2024-06-21', desktop: 169, mobile: 210 },
  { date: '2024-06-22', desktop: 317, mobile: 270 },
  { date: '2024-06-23', desktop: 480, mobile: 530 },
  { date: '2024-06-24', desktop: 132, mobile: 180 },
  { date: '2024-06-25', desktop: 141, mobile: 190 },
  { date: '2024-06-26', desktop: 434, mobile: 380 },
  { date: '2024-06-27', desktop: 448, mobile: 490 },
  { date: '2024-06-28', desktop: 149, mobile: 200 },
  { date: '2024-06-29', desktop: 103, mobile: 160 },
  { date: '2024-06-30', desktop: 446, mobile: 400 },
];

const chartConfig = {
  visitors: {
    label: 'Visitors',
  },
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
  mobile: {
    label: 'Mobile',
    color: 'var(--chart-2)',
  },
} satisfies ChartConfig;

// Gradient ids are per range, since all three charts sit on one page and an
// id must be unique in the document.
const gradients = (days: number) => svg`
  <linearGradient id=${`fillDesktop-${days}d`} x1="0" y1="0" x2="0" y2="1">
    <stop offset="5%" stop-color="var(--color-desktop)" stop-opacity="0.8"></stop>
    <stop offset="95%" stop-color="var(--color-desktop)" stop-opacity="0.1"></stop>
  </linearGradient>
  <linearGradient id=${`fillMobile-${days}d`} x1="0" y1="0" x2="0" y2="1">
    <stop offset="5%" stop-color="var(--color-mobile)" stop-opacity="0.8"></stop>
    <stop offset="95%" stop-color="var(--color-mobile)" stop-opacity="0.1"></stop>
  </linearGradient>`;

const RANGES = [
  { value: '90d', label: 'Last 3 months', days: 90 },
  { value: '30d', label: 'Last 30 days', days: 30 },
  { value: '7d', label: 'Last 7 days', days: 7 },
];

// The rows from `days` before the last one, as shadcn's filter keeps them.
function rangeData(days: number) {
  const start = Date.parse('2024-06-30') - days * 86400000;
  return chartData.filter((item) => Date.parse(item.date) >= start);
}

const day = (value: unknown, opts: Intl.DateTimeFormatOptions) =>
  new Date(String(value)).toLocaleDateString('en-US', { ...opts, timeZone: 'UTC' });

function chart(days: number) {
  return areaChart({
    config: chartConfig,
    class: 'aspect-auto h-[250px] w-full',
    width: 1260,
    height: 250,
    data: rangeData(days),
    title: `Visitors, the last ${days} days`,
    defs: gradients(days),
    grid: { vertical: false },
    xAxis: {
      dataKey: 'date',
      tickLine: false,
      axisLine: false,
      tickMargin: 8,
      minTickGap: 32,
      tickFormatter: (value) => day(value, { month: 'short', day: 'numeric' }),
    },
    tooltip: { cursor: false, indicator: 'dot', labelFormatter: (value) => day(value, { month: 'short', day: 'numeric' }) },
    legend: {},
    areas: [
      { dataKey: 'mobile', type: 'natural', fill: `url(#fillMobile-${days}d)`, stroke: 'var(--color-mobile)', stackId: 'a' },
      { dataKey: 'desktop', type: 'natural', fill: `url(#fillDesktop-${days}d)`, stroke: 'var(--color-desktop)', stackId: 'a' },
    ],
  });
}

export default function ChartAreaInteractive() {
  return html`
    <div data-slot="card" class=${cn(cardClass(), 'group/chart pt-0')}>
      <div data-slot="card-header" class=${cn(cardHeaderClass(), 'flex items-center gap-2 space-y-0 border-b py-5 sm:flex-row')}>
        <div class="grid flex-1 gap-1">
          <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Interactive</div>
          <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 3 months</div>
        </div>
        <ui-select class="hidden sm:ml-auto sm:flex">
          <select aria-label="Select a value" class=${cn(selectTriggerClass(), 'w-[160px] rounded-lg')}>
            ${RANGES.map((r) => html`<option value=${r.value} ?selected=${r.value === '90d'}>${r.label}</option>`)}
          </select>
        </ui-select>
      </div>
      <div data-slot="card-content" class=${cn(cardContentClass(), 'px-2 pt-4 sm:px-6 sm:pt-6')}>
        <div class="group-has-[option[value=30d]:checked]/chart:hidden group-has-[option[value=7d]:checked]/chart:hidden">${chart(90)}</div>
        <div class="hidden group-has-[option[value=30d]:checked]/chart:block">${chart(30)}</div>
        <div class="hidden group-has-[option[value=7d]:checked]/chart:block">${chart(7)}</div>
      </div>
    </div>
  `;
}
Area Chart - Interactive
Showing total visitors for the last 3 months
Apr 1Apr 2Apr 3Apr 4Apr 5Apr 6Apr 7Apr 8Apr 9Apr 10Apr 11Apr 12Apr 13Apr 14Apr 15Apr 16Apr 17Apr 18Apr 19Apr 20Apr 21Apr 22Apr 23Apr 24Apr 25Apr 26Apr 27Apr 28Apr 29Apr 30May 1May 2May 3May 4May 5May 6May 7May 8May 9May 10May 11May 12May 13May 14May 15May 16May 17May 18May 19May 20May 21May 22May 23May 24May 25May 26May 27May 28May 29May 30May 31Jun 1Jun 2Jun 3Jun 4Jun 5Jun 6Jun 7Jun 8Jun 9Jun 10Jun 11Jun 12Jun 13Jun 14Jun 15Jun 16Jun 17Jun 18Jun 19Jun 20Jun 21Jun 22Jun 23Jun 24Jun 25Jun 26Jun 27Jun 28Jun 29Jun 30
Desktop
Mobile
Area Chart

Code

View the code for the chart.

components/charts/chart-area-default.ts
/**
 * A simple area chart, a chart block ported from shadcn/ui's chart-area-default.
 *
 * Installed by `npx @webjsdev/ui add chart-area-default` at
 * `components/charts/chart-area-default.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaDefault()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186 },
  { month: 'February', desktop: 305 },
  { month: 'March', desktop: 237 },
  { month: 'April', desktop: 73 },
  { month: 'May', desktop: 209 },
  { month: 'June', desktop: 214 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

export default function ChartAreaDefault() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop visitors, January to June',
          margin: { left: 12, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false, indicator: 'line' },
          areas: [{ dataKey: 'desktop', type: 'natural', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)' }],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart
Showing total visitors for the last 6 months
JanFebMarAprMayJun
Area Chart

Code

View the code for the chart.

components/charts/chart-area-linear.ts
/**
 * A linear area chart, a chart block ported from shadcn/ui's chart-area-linear.
 *
 * Installed by `npx @webjsdev/ui add chart-area-linear` at
 * `components/charts/chart-area-linear.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaLinear()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186 },
  { month: 'February', desktop: 305 },
  { month: 'March', desktop: 237 },
  { month: 'April', desktop: 73 },
  { month: 'May', desktop: 209 },
  { month: 'June', desktop: 214 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

export default function ChartAreaLinear() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Linear</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop visitors, January to June',
          margin: { left: 12, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false, indicator: 'dot', hideLabel: true },
          areas: [{ dataKey: 'desktop', type: 'linear', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)' }],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Linear
Showing total visitors for the last 6 months
JanFebMarAprMayJun
Area Chart

Code

View the code for the chart.

components/charts/chart-area-step.ts
/**
 * A step area chart, a chart block ported from shadcn/ui's chart-area-step.
 *
 * Installed by `npx @webjsdev/ui add chart-area-step` at
 * `components/charts/chart-area-step.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaStep()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186 },
  { month: 'February', desktop: 305 },
  { month: 'March', desktop: 237 },
  { month: 'April', desktop: 73 },
  { month: 'May', desktop: 209 },
  { month: 'June', desktop: 214 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
    icon: () => Activity(),
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

// lucide's activity, the series icon in the config.
const Activity = () => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="lucide lucide-activity"><path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"></path></svg>`;

export default function ChartAreaStep() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Step</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop visitors, January to June',
          margin: { left: 12, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false, hideLabel: true },
          areas: [{ dataKey: 'desktop', type: 'step', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)' }],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Step
Showing total visitors for the last 6 months
JanFebMarAprMayJun
Area Chart

Code

View the code for the chart.

components/charts/chart-area-legend.ts
/**
 * An area chart with a legend, a chart block ported from shadcn/ui's chart-area-legend.
 *
 * Installed by `npx @webjsdev/ui add chart-area-legend` at
 * `components/charts/chart-area-legend.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaLegend()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186, mobile: 80 },
  { month: 'February', desktop: 305, mobile: 200 },
  { month: 'March', desktop: 237, mobile: 120 },
  { month: 'April', desktop: 73, mobile: 190 },
  { month: 'May', desktop: 209, mobile: 130 },
  { month: 'June', desktop: 214, mobile: 140 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
  mobile: {
    label: 'Mobile',
    color: 'var(--chart-2)',
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

export default function ChartAreaLegend() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Legend</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop and mobile visitors, January to June',
          margin: { left: 12, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false, indicator: 'line' },
          legend: {},
          areas: [
            { dataKey: 'mobile', type: 'natural', fill: 'var(--color-mobile)', fillOpacity: 0.4, stroke: 'var(--color-mobile)', stackId: 'a' },
            { dataKey: 'desktop', type: 'natural', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)', stackId: 'a' },
          ],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Legend
Showing total visitors for the last 6 months
JanFebMarAprMayJun
Desktop
Mobile
Area Chart

Code

View the code for the chart.

components/charts/chart-area-stacked.ts
/**
 * A stacked area chart, a chart block ported from shadcn/ui's chart-area-stacked.
 *
 * Installed by `npx @webjsdev/ui add chart-area-stacked` at
 * `components/charts/chart-area-stacked.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaStacked()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186, mobile: 80 },
  { month: 'February', desktop: 305, mobile: 200 },
  { month: 'March', desktop: 237, mobile: 120 },
  { month: 'April', desktop: 73, mobile: 190 },
  { month: 'May', desktop: 209, mobile: 130 },
  { month: 'June', desktop: 214, mobile: 140 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
  mobile: {
    label: 'Mobile',
    color: 'var(--chart-2)',
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

export default function ChartAreaStacked() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Stacked</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop and mobile visitors, January to June',
          margin: { left: 12, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false, indicator: 'dot' },
          areas: [
            { dataKey: 'mobile', type: 'natural', fill: 'var(--color-mobile)', fillOpacity: 0.4, stroke: 'var(--color-mobile)', stackId: 'a' },
            { dataKey: 'desktop', type: 'natural', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)', stackId: 'a' },
          ],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Stacked
Showing total visitors for the last 6 months
JanFebMarAprMayJun
Area Chart

Code

View the code for the chart.

components/charts/chart-area-stacked-expand.ts
/**
 * A stacked area chart with expand stacking, a chart block ported from shadcn/ui's chart-area-stacked-expand.
 *
 * Installed by `npx @webjsdev/ui add chart-area-stacked-expand` at
 * `components/charts/chart-area-stacked-expand.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaStackedExpand()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186, mobile: 80, other: 45 },
  { month: 'February', desktop: 305, mobile: 200, other: 100 },
  { month: 'March', desktop: 237, mobile: 120, other: 150 },
  { month: 'April', desktop: 73, mobile: 190, other: 50 },
  { month: 'May', desktop: 209, mobile: 130, other: 100 },
  { month: 'June', desktop: 214, mobile: 140, other: 160 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
  mobile: {
    label: 'Mobile',
    color: 'var(--chart-2)',
  },
  other: {
    label: 'Other',
    color: 'var(--chart-3)',
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

export default function ChartAreaStackedExpand() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Stacked Expanded</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Each source\'s share of visitors, January to June',
          margin: { left: 12, right: 12, top: 12 },
          stackOffset: 'expand',
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false, indicator: 'line' },
          areas: [
            { dataKey: 'other', type: 'natural', fill: 'var(--color-other)', fillOpacity: 0.1, stroke: 'var(--color-other)', stackId: 'a' },
            { dataKey: 'mobile', type: 'natural', fill: 'var(--color-mobile)', fillOpacity: 0.4, stroke: 'var(--color-mobile)', stackId: 'a' },
            { dataKey: 'desktop', type: 'natural', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)', stackId: 'a' },
          ],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Stacked Expanded
Showing total visitors for the last 6months
JanFebMarAprMayJun
Area Chart

Code

View the code for the chart.

components/charts/chart-area-icons.ts
/**
 * An area chart with icons, a chart block ported from shadcn/ui's chart-area-icons.
 *
 * Installed by `npx @webjsdev/ui add chart-area-icons` at
 * `components/charts/chart-area-icons.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaIcons()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186, mobile: 80 },
  { month: 'February', desktop: 305, mobile: 200 },
  { month: 'March', desktop: 237, mobile: 120 },
  { month: 'April', desktop: 73, mobile: 190 },
  { month: 'May', desktop: 209, mobile: 130 },
  { month: 'June', desktop: 214, mobile: 140 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
    icon: () => TrendingDown(),
  },
  mobile: {
    label: 'Mobile',
    color: 'var(--chart-2)',
    icon: () => TrendingUp(),
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

// lucide's trending-down, the desktop series icon.
const TrendingDown = () => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="lucide lucide-trending-down"><path d="M16 17h6v-6"></path><path d="m22 17-8.5-8.5-5 5L2 7"></path></svg>`;

export default function ChartAreaIcons() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Icons</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop and mobile visitors, January to June',
          margin: { left: 12, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false, indicator: 'line' },
          legend: {},
          areas: [
            { dataKey: 'mobile', type: 'natural', fill: 'var(--color-mobile)', fillOpacity: 0.4, stroke: 'var(--color-mobile)', stackId: 'a' },
            { dataKey: 'desktop', type: 'natural', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)', stackId: 'a' },
          ],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Icons
Showing total visitors for the last 6 months
JanFebMarAprMayJun
Desktop
Mobile
Area Chart

Code

View the code for the chart.

components/charts/chart-area-gradient.ts
/**
 * An area chart with gradient fill, a chart block ported from shadcn/ui's chart-area-gradient.
 *
 * Installed by `npx @webjsdev/ui add chart-area-gradient` at
 * `components/charts/chart-area-gradient.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaGradient()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186, mobile: 80 },
  { month: 'February', desktop: 305, mobile: 200 },
  { month: 'March', desktop: 237, mobile: 120 },
  { month: 'April', desktop: 73, mobile: 190 },
  { month: 'May', desktop: 209, mobile: 130 },
  { month: 'June', desktop: 214, mobile: 140 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
  mobile: {
    label: 'Mobile',
    color: 'var(--chart-2)',
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

const gradients = svg`
  <linearGradient id="fillDesktopGradient" x1="0" y1="0" x2="0" y2="1">
    <stop offset="5%" stop-color="var(--color-desktop)" stop-opacity="0.8"></stop>
    <stop offset="95%" stop-color="var(--color-desktop)" stop-opacity="0.1"></stop>
  </linearGradient>
  <linearGradient id="fillMobileGradient" x1="0" y1="0" x2="0" y2="1">
    <stop offset="5%" stop-color="var(--color-mobile)" stop-opacity="0.8"></stop>
    <stop offset="95%" stop-color="var(--color-mobile)" stop-opacity="0.1"></stop>
  </linearGradient>`;

export default function ChartAreaGradient() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Gradient</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop and mobile visitors, January to June',
          defs: gradients,
          margin: { left: 12, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          tooltip: { cursor: false },
          areas: [
            { dataKey: 'mobile', type: 'natural', fill: 'url(#fillMobileGradient)', fillOpacity: 0.4, stroke: 'var(--color-mobile)', stackId: 'a' },
            { dataKey: 'desktop', type: 'natural', fill: 'url(#fillDesktopGradient)', fillOpacity: 0.4, stroke: 'var(--color-desktop)', stackId: 'a' },
          ],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Gradient
Showing total visitors for the last 6 months
JanFebMarAprMayJun
Area Chart

Code

View the code for the chart.

components/charts/chart-area-axes.ts
/**
 * An area chart with axes, a chart block ported from shadcn/ui's chart-area-axes.
 *
 * Installed by `npx @webjsdev/ui add chart-area-axes` at
 * `components/charts/chart-area-axes.ts`. It is app code you own, so edit it
 * freely, and render it from any page with `${ChartAreaAxes()}`.
 */
import { html, svg } from '@webjsdev/core';
import {
  cardClass, cardContentClass, cardDescriptionClass, cardFooterClass, cardHeaderClass, cardTitleClass,
} from '../ui/card.ts';
import { areaChart, type ChartConfig } from '../ui/chart.ts';

const chartData = [
  { month: 'January', desktop: 186, mobile: 80 },
  { month: 'February', desktop: 305, mobile: 200 },
  { month: 'March', desktop: 237, mobile: 120 },
  { month: 'April', desktop: 73, mobile: 190 },
  { month: 'May', desktop: 209, mobile: 130 },
  { month: 'June', desktop: 214, mobile: 140 },
];

const chartConfig = {
  desktop: {
    label: 'Desktop',
    color: 'var(--chart-1)',
  },
  mobile: {
    label: 'Mobile',
    color: 'var(--chart-2)',
  },
} satisfies ChartConfig;

// lucide's trending-up, the icon in shadcn's footer.
const TrendingUp = (cls = '') => svg`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class=${'lucide lucide-trending-up ' + cls}><path d="M16 7h6v6"></path><path d="m22 7-8.5 8.5-5-5L2 17"></path></svg>`;

export default function ChartAreaAxes() {
  return html`
    <div data-slot="card" class=${cardClass()}>
      <div data-slot="card-header" class=${cardHeaderClass()}>
        <div data-slot="card-title" class=${cardTitleClass()}>Area Chart - Axes</div>
        <div data-slot="card-description" class=${cardDescriptionClass()}>Showing total visitors for the last 6 months</div>
      </div>
      <div data-slot="card-content" class=${cardContentClass()}>
        ${areaChart({
          config: chartConfig,
          data: chartData,
          title: 'Desktop and mobile visitors, January to June',
          margin: { left: -20, right: 12 },
          grid: { vertical: false },
          xAxis: { dataKey: 'month', tickLine: false, axisLine: false, tickMargin: 8, tickFormatter: (value) => String(value).slice(0, 3) },
          yAxis: { tickLine: false, axisLine: false, tickMargin: 8, tickCount: 3 },
          tooltip: { cursor: false },
          areas: [
            { dataKey: 'mobile', type: 'natural', fill: 'var(--color-mobile)', fillOpacity: 0.4, stroke: 'var(--color-mobile)', stackId: 'a' },
            { dataKey: 'desktop', type: 'natural', fill: 'var(--color-desktop)', fillOpacity: 0.4, stroke: 'var(--color-desktop)', stackId: 'a' },
          ],
        })}
      </div>
      <div data-slot="card-footer" class=${cardFooterClass()}>
        <div class="flex w-full items-start gap-2 text-sm">
          <div class="grid gap-2">
            <div class="flex items-center gap-2 leading-none font-medium">
              Trending up by 5.2% this month ${TrendingUp('h-4 w-4')}
            </div>
            <div class="flex items-center gap-2 leading-none text-muted-foreground">January - June 2024</div>
          </div>
        </div>
      </div>
    </div>
  `;
}
Area Chart - Axes
Showing total visitors for the last 6 months
JanFebMarAprMayJun0300600