Skip to content

Instantly share code, notes, and snippets.

@lsongdev
Created September 14, 2018 10:57
Show Gist options
  • Save lsongdev/1465d098a6a9b9d6d2fcb45241893b5f to your computer and use it in GitHub Desktop.
Save lsongdev/1465d098a6a9b9d6d2fcb45241893b5f to your computer and use it in GitHub Desktop.
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