RevenueChart.js
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import $ from 'jquery';
import { Row, Col } from 'reactstrap';
/* eslint-disable */
import 'imports-loader?jQuery=jquery,this=>window!flot';
import 'imports-loader?jQuery=jquery,this=>window!flot/jquery.flot.pie';
/* eslint-enable */
export default class RevenueChart extends PureComponent {
static propTypes = {
data: PropTypes.any,
};
static defaultProps = {
data: [],
};
componentDidMount() {
this.initChart();
window.addEventListener('resize', this.initChart.bind(this));
}
componentWillUnmount() {
window.removeEventListener('resize', this.initChart.bind(this));
}
initChart() {
$.plot(this.$chartContainer, this.props.data, {
series: {
pie: {
innerRadius: 0.8,
show: true,
fill: 0.5,
},
},
colors: ['#ffc247', '#f55d5d', '#9964e3'],
legend: {
noColumns: 1,
container: this.$chartLegend,
labelBoxBorderColor: '#ffffff',
},
});
}
render() {
return (
<Row>
<Col xs={12} md={6} lg={7} className="text-center">
<div ref={(r) => { this.$chartContainer = $(r); }} style={{ height: '100px' }} />
</Col>
<Col xs={12} md={5} lg={4} className="display-flex flex-column justify-content-center">
<div ref={(r) => { this.$chartLegend = $(r); }} />
</Col>
</Row>
);
}
}