React
This document shows you haw you can create an FlowChart JS React project.
-
Create a new project:
npx create-react-app flowchart
-
Go to the project root folder:
cd flowchart
-
Install FlowChart JS:
- Download and extract the installation package.
- Add flowchart.js in your project \src\ folder.
-
Create file mychart.js in the src folder with the following content:
import React, { Component } from 'react'; import FlowChart from "./flowchart.js"; export default class Tree extends Component { constructor(props) { super(props); this.divRef = React.createRef(); } shouldComponentUpdate() { return false; } componentDidMount() { this.chart = new FlowChart('#chart', { }); this.chart.load( { nodes: [ { id: 1, templateId: 'startEnd', x: 400, y: 150, text: "Start"}, ] } ); } render() { return ( <div id="chart" ref={this.divRef}></div> ); } }
-
Change app.js as follows:
import React, { Component } from 'react'; import FlowChart from './mychart'; export default class App extends Component { render() { return ( <FlowChart /> ); } }
-
Add the CSS in the index.css file:
#chart { height: 700px; width: 700px; }
-
Start the project:
npm start