ComponentesComponents

GráficoChart

Línea y barras sin dependencias; los datos viven en una tabla HTML.Line and bar charts with no dependencies; data lives in an HTML table.

DiseñoDesign: W3C WAI, Complex imagesMITherramienta · densidaddensity alta · sobriaMarkdownJSON

CódigoCode

<figure class="c-chart" data-c-chart data-type="line">
  <figcaption class="c-chart__head">
    <span class="c-chart__title">Visitas por semana</span>
    <span class="c-chart__note">Datos de ejemplo</span>
  </figcaption>
  <div class="c-chart__legend" aria-hidden="true"></div>
  <div class="c-chart__plot" tabindex="0"></div>
  <p class="c-chart__readout" aria-live="polite"></p>
  <details class="c-chart__data">
    <summary>Ver datos</summary>
    <table>
      <thead><tr><th scope="col">Semana</th><th scope="col">2026</th><th scope="col">2025</th></tr></thead>
      <tbody>
        <tr><th scope="row">S1</th><td>1200</td><td>980</td></tr>
        <tr><th scope="row">S2</th><td>1350</td><td>1010</td></tr>
        <tr><th scope="row">S3</th><td>1280</td><td>1100</td></tr>
        <tr><th scope="row">S4</th><td>1620</td><td>1150</td></tr>
        <tr><th scope="row">S5</th><td>1780</td><td>1190</td></tr>
        <tr><th scope="row">S6</th><td>1710</td><td>1240</td></tr>
        <tr><th scope="row">S7</th><td>2050</td><td>1300</td></tr>
        <tr><th scope="row">S8</th><td>2240</td><td>1360</td></tr>
      </tbody>
    </table>
  </details>
</figure>

<figure class="c-chart" data-c-chart data-type="bar">
  <figcaption class="c-chart__head">
    <span class="c-chart__title">Pedidos por canal</span>
    <span class="c-chart__note">Datos de ejemplo</span>
  </figcaption>
  <div class="c-chart__legend" aria-hidden="true"></div>
  <div class="c-chart__plot" tabindex="0"></div>
  <p class="c-chart__readout" aria-live="polite"></p>
  <details class="c-chart__data">
    <summary>Ver datos</summary>
    <table>
      <thead><tr><th scope="col">Canal</th><th scope="col">Septiembre</th><th scope="col">Agosto</th></tr></thead>
      <tbody>
        <tr><th scope="row">Web</th><td>420</td><td>380</td></tr>
        <tr><th scope="row">Tienda</th><td>310</td><td>330</td></tr>
        <tr><th scope="row">WhatsApp</th><td>260</td><td>190</td></tr>
        <tr><th scope="row">Marketplace</th><td>140</td><td>150</td></tr>
      </tbody>
    </table>
  </details>
</figure>

«Todo» trae tokens, dependencias y componente en un solo archivo, listo para abrir o dárselo a un agente.“All” bundles tokens, dependencies and the component in one file, ready to open or hand to an agent.

InstalaciónInstallation

  1. Agrega una vezAdd once tokens.css (colores, radios, tema oscuro).(colors, radii, dark theme).
  2. Copia los archivos:Copy the files: chart.html, chart.css, chart.js.
  3. Para el tema oscuro, pon la claseFor the dark theme, add the class dark ento <html>.

Cuándo usarloWhen to use it

ÚsaloUse it

  • Para mostrar una tendencia (línea) o comparar categorías (barras).
  • Hasta 3 series.
  • To show a trend (line) or compare categories (bars).
  • Up to 3 series.

Mejor noAvoid

  • Para 2 o 3 números: escríbelos.
  • Para partes de un todo con muchas categorías: usa una tabla.
  • For 2 or 3 numbers: write them.
  • For parts of a whole with many categories: use a table.

AccesibilidadAccessibility

imgtable
← →Recorre los puntos y anuncia sus valoresMoves through points and announces values
Inicio FinPrimer o último puntoFirst or last point
  • El SVG tiene un resumen en aria-label; los valores exactos están en «Ver datos».
  • Las series se distinguen por color y por trazo (continuo, discontinuo, punteado).
  • Colores solo del tema: --primary y --muted-foreground; sin degradados ni animación.
  • The SVG has a summary in aria-label; exact values are under “View data”.
  • Series differ by color and stroke (solid, dashed, dotted).
  • Theme colors only: --primary and --muted-foreground; no gradients or animation.

Cómo probarloHow to test it

  • Enfoca el gráfico con Tab y pulsa →: se anuncia «S2: 2026 1350, 2025 1010».
  • Tab to the chart and press →: “S2: 2026 1350, 2025 1010” is announced.

CréditosCredits