1 var React
= require('react');
2 var CanvasJS
= require('./canvasjs.min');
3 CanvasJS
= CanvasJS
.Chart
? CanvasJS
: window
.CanvasJS
;
5 class CanvasJSChart
extends React
.Component
{
6 static _cjsContainerId
= 0
9 this.options
= props
.options
? props
.options
: {};
10 this.containerProps
= props
.containerProps
? props
.containerProps
: {width
: "100%", position
: "relative"};
11 this.containerProps
.height
= props
.containerProps
&& props
.containerProps
.height
? props
.containerProps
.height
: this.options
.height
? this.options
.height
+ "px" : "400px";
12 this.chartContainerId
= "canvasjs-react-chart-container-" + CanvasJSChart
._cjsContainerId
++;
15 //Create Chart and Render
16 this.chart
= new CanvasJS
.Chart(this.chartContainerId
, this.options
);
20 this.props
.onRef(this.chart
);
22 shouldComponentUpdate(nextProps
, nextState
){
23 //Check if Chart-options has changed and determine if component has to be updated
24 return !(nextProps
.options
=== this.options
);
26 componentDidUpdate() {
27 //Update Chart Options & Render
28 this.chart
.options
= this.props
.options
;
31 componentWillUnmount() {
32 //Destroy chart and remove reference
35 this.props
.onRef(undefined);
38 //return React.createElement('div', { id: this.chartContainerId, style: this.containerProps });
39 return <div id
= {this.chartContainerId
} style
= {this.containerProps
}/>
44 CanvasJSChart
: CanvasJSChart
,
48 export default CanvasJSReact
;