Created
September 14, 2018 10:57
-
-
Save lsongdev/1465d098a6a9b9d6d2fcb45241893b5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
class LineChart extends React.Component { | |
render() { | |
const lines = []; | |
const { data } = this.props; | |
data.reduce((y, y2, x) => { | |
lines.push({ x, y, y2 }); | |
return y2; | |
}, 0); | |
return ( | |
<div> | |
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400" height="150"> | |
<rect width="400" height="150" fill="rgb(250, 230, 210)" strokeWidth="1" stroke="rgb(0, 0, 0)" /> | |
<g stroke="black"> | |
{ | |
lines.map(({ x, y, y2, h = 150 }) => | |
<line key={x} x1={x*10} y1={h-y} x2={x*10+10} y2={h-y2} strokeWidth="1" />) | |
} | |
</g> | |
</svg> | |
</div> | |
); | |
} | |
} | |
export default LineChart; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment