npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

solid-chartjs

v1.3.11

Published

SolidJS components for Chart.js

Downloads

5,466

Readme

solid-chartjs

version downloads telegram chat

The solid-chartjs library is a SolidJS wrapper around the Chart.js library, allowing you to easily create interactive charts in your SolidJS applications.

Quick start

Installation:

pnpm add solid-chartjs chart.js
# or
yarn add solid-chartjs chart.js
# or
npm i solid-chartjs chart.js

Demo: solid-chartjs.vychs.com

Usage:

import { onMount } from 'solid-js'
import { Chart, Title, Tooltip, Legend, Colors } from 'chart.js'
import { Line } from 'solid-chartjs'

const MyChart = () => {
    /**
     * You must register optional elements before using the chart,
     * otherwise you will have the most primitive UI
     */
    onMount(() => {
        Chart.register(Title, Tooltip, Legend, Colors)
    })

    const chartData = {
        labels: ['January', 'February', 'March', 'April', 'May'],
        datasets: [
            {
                label: 'Sales',
                data: [50, 60, 70, 80, 90],
            },
        ],
    }
    const chartOptions = {
        responsive: true,
        maintainAspectRatio: false,
    }

    return (
        <div>
            <Line data={chartData} options={chartOptions} width={500} height={500} />
        </div>
    )
}

If you don't want to import and register the controllers, elements, scales, and plugins you want to use, you can use the following solution:

[!NOTE]
It is considered to better use the tree-shakable way, to decrease the bundle size.

import 'chart.js/auto'
import { DefaultChart } from 'solid-chartjs'

<DefaultChart type="line" data={data} options={options} />

Chart Props

| Prop | Description | Type | | -------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- | | width | The width of the chart canvas in pixels. | number | undefined | | height | The height of the chart canvas in pixels. | number | undefined | | fallback | A fallback element to display when chart fails. | JSX.Element | | type | The type of the chart. | keyof ChartTypeRegistry | | data | The chart data object. | ChartData | undefined | | options | The chart options object. | ChartOptions | undefined | | plugins | The chart plugins object. | Plugin[] | undefined |

Examples

Check out /dev folder and run the SolidJs application to see how it works.

You can also use the DefaultChart components:

[!NOTE]
DefaultChart is a wrapper around Chart component, so you can use all the props from Chart component. DefaultChart component does not have its registrable elements registered by default, so you need to register them yourself unless you use chart.js/auto.

import { onMount } from 'solid-js'
import {
    Chart,
    LineController,
    CategoryScale,
    PointElement,
    LineElement,
    LinearScale,
} from 'chart.js'
import { DefaultChart } from 'solid-chartjs'

const MyChart = () => {
    onMount(() => {
        Chart.register(LineController, CategoryScale, PointElement, LineElement, LinearScale)
    })

    // ... your data and options objects

    return <DefaultChart type="line" data={data} options={options} width={400} height={300} />
}

Usage of fallback prop:

const fallback = () => {
    return (
        <div>
            <p>Chart is not available</p>
        </div>
    )
}

<DefaultChart type="bar" data={chartData} options={chartOptions} fallback={fallback} />

Credits