GithubHelp home page GithubHelp logo

aquinojardim / react-d3-pie-chart Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wonism/react-d3-pie-chart

1.0 0.0 0.0 303 KB

React component for rendering pie chart with d3

License: MIT License

JavaScript 100.00%

react-d3-pie-chart's Introduction

React D3 Pie Chart

React component for rendering pie chart with d3

Getting Started

$ npm i -S react react-dom react-d3-pie-chart

Development

$ npm run demo

Bundling for production

$ npm run bundle

How to Use

Parameters

Parameter Type
data (required) array
colors (optional) array
width (optional) number
height (optional) number
transition (optional) number
renderLabel (optional) function

Basic

import React, { PureComponent } from 'react';
import { render } from 'react-dom';
import fp from 'lodash/fp';
import ReactD3PieChart from '../src';

const appRoot = document.getElementById('root');

class DemoApp extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      data: [
        { label: 'A', value: 10 },
        { label: 'B', value: 22 },
        { label: 'C', value: 5 },
        { label: 'D', value: 0 },
        { label: 'E', value: 8 },
      ],
    };
  }

  handleClick = () => {
    const lastData = fp.last(this.state.data);
    const { label } = lastData;
    const newLabel = String.fromCharCode(label.charCodeAt() + 1);
    const newValue = Math.floor(Math.random() * 31);

    this.setState({
      data: [
        ...this.state.data,
        { label: newLabel, value: newValue },
      ],
    });
  }

  renderLabel = d => `Label is ${d.data.label}`

  render() {
    return (
      <main>
        <ReactD3PieChart data={this.state.data} tooltip renderLabel={this.renderLabel} />
        <button onClick={this.handleClick}>Add Data</button>
      </main>
    );
  }
}

render(<DemoApp />, appRoot);

Change Log

1.0.0

  • Initial release

1.0.1

  • Migrate webpack v4
  • Fix renderLabel method

1.0.2

  • Fix bug (to not pass the callback in setState)

1.0.3

  • change library target into commonjs

react-d3-pie-chart's People

Contributors

wonism avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.