Created
June 13, 2015 04:15
-
-
Save suisho/1ba1cba2d0e1b2cada36 to your computer and use it in GitHub Desktop.
Reactから外部のライブラリを直接使う ref: http://qiita.com/suisho/items/c55db2700111acb298f6
This file contains 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
var data = [ | |
["foo", "baz", "bar"], | |
[1, 10, 20] | |
] | |
var body = document.querySelector('.container') | |
React.render(<Chart data={data} />, body); | |
This file contains 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
class Chart extends React.Component{ | |
constructor(){ | |
super() | |
this.chartClassName = "chart" | |
this.renderer = new ChartistRenderer() | |
} | |
componentDidMount(){ | |
this.renderChart() | |
} | |
componentDidUpdate(){ | |
this.renderChart() | |
} | |
renderChart(){ | |
var targetSelector = "." + this.chartClassName | |
this.renderer.render(targetSelector, this.props) | |
} | |
render(){ | |
return <div className={this.chartClassName} ></div> | |
} | |
} |
This file contains 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
class ChartistRenderer{ | |
render(targetSelector, props){ | |
let {data} = props | |
// 必要があればここでデータ加工したり。 | |
var chart = new Chartist.Bar(targetSelector, { | |
labels: data[0], | |
series: [ data[1] ] | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment