Code Monkey home page Code Monkey logo

react-dc's Introduction

React-dc

React-dc is a wrapper around dc.js charts for React. Dc.js is an awesome library, but like many charting libraries, its API is imperative, meaning you have to select a DOM element by its id to transform it into a chart. The goal of this library is to make it very easy for you to create and use dc.js charts as React components.

Table of contents

Installation

Using npm (recommended)

npm install --save react-dc

Without npm

An UMD build is available on unpkg:

<script src="https://unpkg.com/react-dc"></script>
<link rel="stylesheet" src="https://unpkg.com/react-dc/dist/react-dc.css">

Warning: You will also need React, which is a peer dependency of this library. The reasoning behind this is that you are probably already using React in your project, and don't want to end up with two versions of React in your final bundle. If you haven't already installed React, you can install it from npm with npm install --save react, or use a CDN version.

Usage

React-js comes with two versions: an UMD ES5 build, and an ES6 module version to allow for a better integration with your module bundler (like Webpack or Rollup), if you use one. Rollup has a great article on this topic on their wiki.

In an ES6 environment

import {BarChart, PieChart, RowChart} from 'react-dc'
import '~react-dc/react-dc.css'

In an ES5 environment

The library is available as a global variable: ReactDc

Charts

BarChart

import React from 'react'
import d3 from 'd3'
import crossfilter from 'crossfilter'
import {BarChart} from 'react-dc'

const records = [{x: 0, y: 1}, {x: 1, y: 3}, {x: 2, y: 5}, {x: 3, y: 1}, {x: 4, y: 2}]
const data = crossfilter(records)
const dimension = data.dimension(record => record.x)
const group = dimenion.group().reduceSum(record => record.y)

export default () => <BarChart dimension={dimension} group={group} x={d3.scale.linear().domain([0, 5])} />

Roadmap

  • Document all components (charts)
  • Add a component for every dc chart
    • BarChart
    • BaseChart
    • BoxPlot
    • BubbleChart
    • BubbleOverlay
    • DataCount
    • DataGrid
    • DataTable
    • CompositeChart
    • GeoChoroplethChart
    • Heatmap
    • LineChart
    • NumberDisplay
    • PieChart
    • RowChart
    • ScatterPlot
    • SelectMenu
    • SeriesChart
  • Make sure charts are properly re-rendered when props change
  • Make charts responsive

Common issues

When using Webpack, you might see the following error in your console Module not found: Error: Can't resolve 'crossfilter' or Uncaught Error: Cannot find module "crossfilter". This issue is not a problem with react-dc itself. This is due to dc.js' use of a library called crossfilter2, which is a fork of crossfilter. See this issue for more information. It can be fixed using Webpack's resolve feature:

{
  resolve: {
    alias: {
     'crossfilter': 'crossfilter2'
    }
  }
}

FAQ

Is React-dc production ready ?

Not yet. This library is still being actively developed, and needs to be thoroughly tested before being production-ready. However, you can use it for a personal project. If you encounter any bug, please open an issue.

react-dc's People

Contributors

waldojeffers avatar

Watchers

James Cloos avatar NurulC avatar  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.