LineChart.js
1.16 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
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import $ from 'jquery';
/* eslint-disable */
import 'imports-loader?jQuery=jquery,this=>window!jquery-sparkline';
/* eslint-enable */
export default class LineChart extends PureComponent {
static propTypes = {
color: PropTypes.string.isRequired,
}
componentDidMount() {
this.initChart(this.getData());
}
getData() { // eslint-disable-line
const randomData = [];
for (let i = 0; i < 150; i += 1) {
randomData.push((i/9+Math.sin(i/6)*8+Math.random() * 2).toFixed(2));
}
return randomData;
}
initChart(data) {
this.$chartContainer.sparkline(data, {
type: 'line',
lineWidth: 1.67,
lineColor: this.props.color,
normalRangeMin: '10px',
width: '160px',
height: '20px',
fillColor: false,
spotColor: false,
minSpotColor: false,
maxSpotColor: false,
highlightSpotColor: false,
highlightLineColor: false,
drawNormalOnTop: false,
tooltipClassname: 'line-chart-tooltip'
});
}
render() {
return (
<div ref={(r) => { this.$chartContainer = $(r); }} />
);
}
}