Created
October 26, 2016 07:40
-
-
Save MaciekLesiczka/cf87f8dca965f2cd1481d90f334a5857 to your computer and use it in GitHub Desktop.
React+D3
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
<html> | |
<body> | |
<div id="container"></div> | |
<script src="https://unpkg.com/react@15/dist/react.min.js"></script> | |
<script src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script> | |
var Container = React.createClass({ | |
componentDidMount:function(){ | |
renderGraph(this.refs['container'], this.props.data) | |
}, | |
render:function() { | |
return React.createElement('div', {ref:'container'}); | |
} | |
}) | |
var renderGraph = function(container,data){ | |
d3.select(container) | |
.selectAll('h2') | |
.data(data) | |
.enter() | |
.append('h2') | |
.text(function(x){return x}) | |
.style('color', 'red') | |
.transition() | |
.style('color', 'blue').delay(1000); | |
} | |
ReactDOM.render( | |
React.createElement(Container, {data:[1,2]}), | |
document.getElementById('container') | |
); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment