Skip to content

zingchart/zingchart-react

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zingchart-react

A React component for ZingChart

Quickly create dynamic JavaScript charts that react when your data changes by utilizing the ZingChart library and Facebook's React together.

1. Install

Install the zingchart-react package via npm

$ npm install zingchart-react

2. Include ZingChart in the component you are utilizing.

import React, { Component } from 'react';
import ZingChart from '../ZingChart.jsx';

3. Usage

Create a class containing the chart and it's configuration.

import React, { Component } from 'react';
import ZingChart from '../ZingChart.jsx';

class MyChart extends Component {
  constructor(props) {
    super(props);
    this.state = {
      config: {
        type: 'bar',
        series: [{
          values: [4,5,3,4,5,3,5,4,11]
        }]
      }
    }
    this.chart = React.createRef();
  }
  render() {
    return (
      <div >
        <ZingChart ref={this.chart} data={this.state.config}/>
      </div>
    );
  }
}

export default MyChart;

Parameters

data[object]

  <ZingChart data={this.state.config}/>
...
constructor() {
  this.state = {
    config: {
      type: 'bar',
      series: [{
        values: [4,5,3,4,5,3,5,4,11]
      }]
    }
  }
}
...

id[string]

The id for the DOM element for ZingChart to attach to. If no id is specified, the id will be autogenerated in the form of zingchart-react-#

series[array] (optional)

Accepts an array of series objects, and overrides a series if it was supplied into the config object. Varries by chart type used - Refer to the ZingChart documentation for more details.

  <ZingChart data={this.state.config} series={this.state.series}/>
...
constructor() {
  this.state = {
    config: {
      type: 'bar'
    },
    series: [{
      values: [4,5,3,4,5,3,5,4,11]
    }]
  }
}
...

width [string or number] (optional)

The width of the chart. Defaults to 100%

height [string or number] (optional)

The height of the chart. Defaults to 480px.

theme[object] (optional)

The theme or 'defaults' object defined by ZingChart. More information available here: https://www.zingchart.com/docs/api/themes

Events

All zingchart events are readily available on the component to listen to. For example, to listen for the 'complete' event when the chart is finished rendering:

  <ZingChart data={this.state.config} complete={this.chartRendered}/>
...
  constructor() {
    ...
    this.chartRendered = this.chartRendered.bind(this);
    ...
  }
  chartRendered(result) {
    console.log(result.ev);
  }
...

For a list of all the events that you can listen to, refer to the complete documentation on https://www.zingchart.com/docs/events

Methods

  <ZingChart data={this.state.config} ref={this.chart}/>
  <button onClick={this.addPlot}>AddPlot</button>
...
  constructor() {
    ...
    this.chart = React.createRef();
    this.addPlot = this.addPlot.bind(this);
    ...
  }
  addPlot() {
    this.chart.current.addplot({
      data: {
        values: [3,5,6,4,3,4,6,6],
        text: "My new plot"
      }
    });
  }
...

Hello World and Examples

This repository contains a sample React application to give you an easy way to see the component in action.

About

Quickly create dynamic JavaScript charts with ZingChart & React.

Topics

Resources

License

Stars

93 stars

Watchers

12 watching

Forks

Packages

 
 
 

Contributors