i'm trying to understand how React works.
I want to use react-chartjs library. (https://github.com/jhudson8/react-chartjs). How can i import it in my project?
i tried in this way:
in a file MyComponent.js:
var LC = React.createClass({
render: function(){
var xfield = this.props.xfield;
var yfield = this.props.yfield;
var data = {
labels: xfield,
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: yfield
}]
}
return(
<LineChart data={data} width="600" height="250" />
);
}});
var MyComponent = React.createClass({
render: function(){
return(
<LC xfield={a} yfield={b} />
);
}});
React.render(<MyComponent />, document.getElementById('content'));
i'm assuming a e b are arrays of values.
my index page is this:
<html>
<head>
<!-- React -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/JSXTransformer.js"></script>
<script src="js/react-chartjs.js"></script>
<script type="text/jsx;harmony=true" src="MyComponent.js"></script>
</head>
<body>
<div id="content"></div>
</body>
react-chartjs.js should be the compiled chartjs component.
Running the index in this way i have this error:
Uncaught ReferenceError: LineChart is not defined
i need to use this line
var LineChart = require("react-chartjs").Line;
but in MyComponent.js i have the error that require is not defined
What's wrong??