Skip to content

Instantly share code, notes, and snippets.

@suisho
Created June 13, 2015 04:15
Show Gist options
  • Save suisho/1ba1cba2d0e1b2cada36 to your computer and use it in GitHub Desktop.
Save suisho/1ba1cba2d0e1b2cada36 to your computer and use it in GitHub Desktop.
Reactから外部のライブラリを直接使う ref: http://qiita.com/suisho/items/c55db2700111acb298f6
var data = [
["foo", "baz", "bar"],
[1, 10, 20]
]
var body = document.querySelector('.container')
React.render(<Chart data={data} />, body);
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>
}
}
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