• Stars
    star
    118
  • Rank 299,923 (Top 6 %)
  • Language
    JavaScript
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight React Charts

React Frappe Charts

React wrapper for Frappe Charts with TypeScript definitions and Storybook playground

Bundlephobia Bundlephobia Storybook

Installation

React Frappe Charts requires React 16.8.0 or later.

$ npm install --save frappe-charts react-frappe-charts

Usage

import ReactFrappeChart from "react-frappe-charts";

export default function MyChart(props) {
  return (
    <ReactFrappeChart
      type="bar"
      colors={["#21ba45"]}
      axisOptions={{ xAxisMode: "tick", yAxisMode: "tick", xIsSeries: 1 }}
      height={250}
      data={{
        labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        datasets: [{ values: [18, 40, 30, 35, 8, 52, 17, 4] }],
      }}
    />
  );
}

Updating the data prop would update the chart with new data.

With Next.js

The underlying frappe-charts library should be transpiled to avoid module loading issues. Install next-transpile-modules with your package manager and then use the following code snippet:

/* next.config.js */
const withTM = require("next-transpile-modules")(["frappe-charts", "react-frappe-charts"]);
module.exports = withTM({
  /* Optionally, specify additional settings here */
});

Export Chart

In order to export a chart we need to forward a ref to invoke the chart.export() feature from Frappe Charts.

Example:

import React, { useRef } from "react";
import ReactFrappeChart from "react-frappe-charts";

export default function MyChart(props) {
  const chartRef = useRef();

  const exportChart = () => {
    if (chartRef && chartRef.current) {
      chartRef.current.export();
    }
  };

  return (
    <div>
      <ReactFrappeChart
        ref={chartRef}
        type="bar"
        colors={["#21ba45"]}
        axisOptions={{ xAxisMode: "tick", yAxisMode: "tick", xIsSeries: 1 }}
        height={250}
        data={{
          labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
          datasets: [{ values: [18, 40, 30, 35, 8, 52, 17, 4] }],
        }}
      />
      <button onClick={exportChart} type="button">
        Export
      </button>
    </div>
  );
}

Playground

Use Storybook Playground to tweak different props and see their effect on the chart rendered

Contributing

PRs are welcome!

More Repositories

1

freshlytics

Open source privacy-friendly analytics
TypeScript
354
star
2

rustmart-yew-example

Single Page Application (SPA) written using Rust, Wasm and Yew
Rust
270
star
3

Chital

A native macOS app for chatting with local LLMs
Swift
239
star
4

rust-error-handling-examples

Rust
29
star
5

mouji

Minimal Web Analytics
Go
29
star
6

starterkit

Fullstack project starter kit
TypeScript
8
star
7

PowerShell-Minify

PS scripts to concatenate and minify JS/CSS
PowerShell
5
star
8

airhealth

Air Quality Index App
JavaScript
4
star
9

sheshbabu.github.io

HTML
3
star
10

gitrmbr

CLI for deleting git branches
JavaScript
3
star
11

react-pageview-tracking-demo

Example repo for showing how to automatically track pageview events using react router
JavaScript
3
star
12

fastapi-structured-json-logging-demo

Python
3
star
13

readable-scraper

JavaScript
3
star
14

RNLocalScheduledNotificationDemo

Demo repo for showing local and scheduled notifications in RN app
Objective-C
2
star
15

express-https-localhost-demo

Example repo for exposing Express via HTTPS in localhost
JavaScript
2
star
16

seamark

Web performance dashboard (WIP)
TypeScript
2
star
17

unveil

Feature flag service written using Rust, Actix, Postgres and React
TypeScript
2
star
18

Subtoise

Simple TortoiseSVN plugin for Sublime Text 2
Python
2
star
19

fastapi-asyncpg-demo

Python
1
star
20

react-native-in-production

Notes on how RN is used in production
1
star
21

wpt-ui

UI for WebPagetest
JavaScript
1
star
22

Tamatar

Material Design Pomodoro Timer
JavaScript
1
star
23

gonime

Simple website to view the current season's popular anime
Go
1
star
24

wpt-ui-example

Example for wpt-ui repo
JavaScript
1
star
25

Blog

Pug
1
star
26

express-next-demo

Demo app for ExpressJS next() callback
JavaScript
1
star
27

NewAnimeEpisodeNotifier

RN app to notify when new anime episode is broadcasted
JavaScript
1
star
28

web-share-api-demo

🎏 A small demo for the Web Share API
HTML
1
star