Charts can also be rendered using JSON data API. Below example shows Candlestick Chart created using JSON data source. It also includes react source code that you can try running locally.
/* App.js */ import React, { Component } from 'react'; import CanvasJSReact from '@canvasjs/react-charts'; //var CanvasJSReact = require('@canvasjs/react-charts'); var CanvasJS = CanvasJSReact.CanvasJS; var CanvasJSChart = CanvasJSReact.CanvasJSChart; class App extends Component { constructor() { super(); this.state = { dataPoints: [], isLoaded: false }; } render() { const options = { exportEnabled: true, title: { text: "Microsoft Corporation Stock Price - December 2017" }, axisX: { valueFormatString: "D MMM" }, axisY: { title: "Price", prefix: "$" }, data: [{ type: "candlestick", name: "Microsoft Corporation Price", showInLegend: true, yValueFormatString: "$##0.00", xValueType: "dateTime", dataPoints: this.state.dataPoints }] } return ( <div> {this.state.isLoaded && <CanvasJSChart options={options} onRef={ref => this.chart = ref} />} {/*You can get reference to the chart instance as shown above using onRef. This allows you to access all chart properties and methods*/} </div> ); } componentDidMount() { fetch('https://canvasjs.com/data/gallery/react/microsoft-stock-price.json') .then((response) => { return response.json(); }) .then((data) => { var dps = []; for (var i = 0; i < data.length; i++) { dps.push({ x: data[i].x, y: data[i].y }); } this.setState({ isLoaded: true, dataPoints: dps }) }); } } export default App;
Export feature of the chart can be achieved by setting the exportEnabled property to true. You can also export the chart programatically by using the exportChart() method. Some other frequently used customization options are animationEnabled, type, etc.
Note For step by step instructions, follow our React Integration Tutorial