Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

svelte wrapper for chart.js

License

NotificationsYou must be signed in to change notification settings

nstringham/svelte-chartjs

 
 

Repository files navigation

svelte-chartjs logo

Svelte wrapper forchart.js Open for PRs and contributions!

npm versionFOSSA Statusnpm


Install  •  Usage  •  Migration guide  •  Examples  •  Slack  •  Stack Overflow

Install

Install this library with peer dependencies:

pnpm add svelte-chartjs chart.js# oryarn add svelte-chartjs chart.js# ornpm i svelte-chartjs chart.js

Need an API to fetch data? ConsiderCube, an open-source API for data apps.


supported by Cube

Usage

<script>import {Line }from'svelte-chartjs'</script><Linedata={...} />

Custom Size

In order for Chart.js to obey the custom size you need to setmaintainAspectRatio to false, example:

<Linedata={data}width={100}height={50}options={{maintainAspectRatio:false }}/>

Migration from v1 to v2

With v2, this library introduces a number of breaking changes. In order to improve performance, offer new features, and improve maintainability, it was necessary to break backwards compatibility, but we aimed to do so only when worth the benefit.

Change component import path

v1:

importLinefrom'svelte-chartjs/src/Line.svelte'

v2:

import{Line}from'svelte-chartjs'

Tree-shaking

v2 of this library,just like Chart.js v3, is tree-shakable. It means that you need to import and register the controllers, elements, scales, and plugins you want to use.

For a list of all the available items to import, seeChart.js docs.

v1:

importLinefrom'svelte-chartjs/src/Line.svelte'

v2 — lazy way:

import{Line}from'svelte-chartjs'import'chart.js/auto';

v2 — tree-shakable way:

import{Line}from'svelte-chartjs'import{ChartasChartJS,Title,Tooltip,Legend,LineElement,LinearScale,PointElement,CategoryScale}from'chart.js';ChartJS.register(Title,Tooltip,Legend,LineElement,LinearScale,PointElement,CategoryScale);

Using the "lazy way" is okay to simplify the migration, but please consider using the tree-shakable way to decrease the bundle size.

Please note that typed chart components register their controllers by default, so you don't need to register them by yourself. For example, when using the Pie component, you don't need to register PieController explicitly.

import{Pie}from'svelte-chartjs';import{ChartasChartJS,Title,Tooltip,Legend,ArcElement,CategoryScale}from'chart.js'ChartJS.register(Title,Tooltip,Legend,ArcElement,CategoryScale)

Examples

Docs for v1

Full Documentation and demo for v1here

License

FOSSA Status

About

svelte wrapper for chart.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript50.3%
  • Svelte24.1%
  • JavaScript21.6%
  • HTML4.0%

[8]ページ先頭

©2009-2025 Movatter.jp