Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

chartjs

БесплатноБез исполняемых скриптовНе проверен

Chart.js draws bar, line, pie, doughnut, radar, scatter and bubble charts on an HTML canvas from a plain JavaScript config object. Use when a user asks to…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Chart.js — canvas charts from a config object

Overview

Chart.js renders charts into a <canvas>. Every chart is described by one object, { type, data, options, plugins }, and updated by changing that object and calling chart.update(). Version 4 is ESM and tree-shakeable: with a bundler you register only the controllers, elements, scales and plugins you use, or import chart.js/auto to get everything.

Choose it for a handful of standard charts with small code and a small bundle. Choose the neighbouring skills instead when:

  • recharts — you want charts as React components built from SVG elements.
  • echarts — you need very large datasets, maps, heatmaps, or many exotic series types.

Because Chart.js draws pixels on a canvas, there is no DOM per bar: tooltips and hit-testing are handled by the library, and charts cannot be rendered where no canvas exists (plain Node, server components); in Next.js or Nuxt create them in a client-only component after mount.

Instructions

Installation

npm install chart.js

For a time axis you also need a date library plus an adapter (the time scale does not work without one):

npm install chartjs-adapter-date-fns date-fns

For React there is a separate community wrapper that depends on chart.js 4 as a peer:

npm install react-chartjs-2

Registering components (tree-shaking)

Quickest start, everything included:

import Chart from 'chart.js/auto';

For a smaller bundle, register exactly what the chart type needs. A bar chart needs BarController, BarElement, CategoryScale and LinearScale; a line chart needs LineController, LineElement, PointElement and the same two scales; a doughnut or pie chart needs its controller plus ArcElement and no scales. Tooltip, Legend, Title and Filler are plugins and are only active when registered.

import {
  Chart, BarController, BarElement, CategoryScale, LinearScale, Tooltip, Legend, Title,
} from 'chart.js';

Chart.register(BarController, BarElement, CategoryScale, LinearScale, Tooltip, Legend, Title);

Register once, at app start. A missing registration shows up at runtime as "bar" is not a registered controller or "category" is not a registered scale; the fix is to register the named piece.

Creating a chart

The canvas needs its own relatively positioned container. Chart.js resizes the canvas from its parent, so put the size on the parent, never on the canvas.

<div style="position: relative; height: 320px; width: 100%">
  <canvas id="orders"></canvas>
</div>
import { Chart, type ChartConfiguration } from 'chart.js';

const config: ChartConfiguration<'bar', number[], string> = {
  type: 'bar',
  data: {
    labels: ['Jan', 'Feb', 'Mar'],
    datasets: [{ label: 'Orders', data: [120, 98, 143], backgroundColor: '#2563eb', borderRadius: 4 }],
  },
  options: {
    responsive: true,
    maintainAspectRatio: false,
    scales: { y: { beginAtZero: true, title: { display: true, text: 'Orders' } } },
    plugins: { legend: { position: 'bottom' }, title: { display: true, text: 'Orders per month' } },
  },
};

const canvas = document.getElementById('orders') as HTMLCanvasElement;
const chart = new Chart(canvas, config);

With maintainAspectRatio: false the chart fills the container height. With the default true the container height follows the width through aspectRatio.

Updating data and options

Mutate chart.data or chart.options in place, then call update(). Pass 'none' to skip the animation, which is the right choice for high-frequency live data.

chart.data.labels!.push('Apr');
chart.data.datasets[0].data.push(150);
chart.update();

chart.options.plugins!.title!.text = 'Orders, Jan to Apr';
chart.update('none');

Assigning a brand new chart.options object discards options Chart.js computed earlier, so prefer in-place mutation. To remove the chart, call chart.destroy(); creating a second chart on a canvas that still has one throws Canvas is already in use.

Time axes

Install the adapter, import it once for its side effect, and set the scale type to time:

import { Chart, LineController, LineElement, PointElement, LinearScale, TimeScale } from 'chart.js';
import 'chartjs-adapter-date-fns';

Chart.register(LineController, LineElement, PointElement, LinearScale, TimeScale);

const latency = new Chart(canvas, {
  type: 'line',
  data: { datasets: [{ label: 'p95 latency (ms)', data: [{ x: '2026-10-29T09:00:00Z', y: 212 }, { x: '2026-10-29T09:05:00Z', y: 187 }] }] },
  options: { scales: { x: { type: 'time', time: { unit: 'minute' } } } },
});

Plugins

A plugin is an object with an id and hooks such as beforeDraw, afterDatasetsDraw or afterUpdate. Pass it per chart in the top-level plugins array, or register it globally with Chart.register(plugin). Options for a plugin live under options.plugins.<id>.


Полный SKILL.md на GitHub

Установить chartjs в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл chartjs?

Chart.js draws bar, line, pie, doughnut, radar, scatter and bubble charts on an HTML canvas from a plain JavaScript config object. Use when a user asks to "add a chart to the page", "plot this data with Chart.js", "update a chart live", "make the chart responsive", "register Chart.js components for a smaller bundle", or "use Chart.js in React". Covers v4 ESM registration, config shape, updating data, plugins, responsive sizing, time scales and export to PNG.

Как установить скилл chartjs?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл chartjs запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить chartjs с