I wanted to run this demo https://github.com/reactjs/react-chartjs
Installation (I have run this part)
This is a CommonJS component only (to be used with something like Webpack or Browserify)
npm install --save react-chartjs
You must also include chart.js and React as dependencies.
npm install --save chart.js@^1.1.1 react react-dom
I don't know how to run this below part:
Example Usage
var LineChart = require("react-chartjs").Line;
var MyComponent = React.createClass({
render: function() {
return <LineChart data={chartData} options={chartOptions} width="600" height="250"/>
}
});
This is my complete html file:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
<script src="https://unpkg.com/babel-core@5.8.38/browser.min.js"></script>
<script src="dist/react-chartjs.js"></script>
<body>
<script>
var LineChart = require("react-chartjs").Line;
/*var MyComponent = React.createClass({
render: function() {
return <LineChart data={chartData} options={chartOptions} width="600" height="250"/>
}
});
*/
</script>
</body>
</html>
It generates errors like:
test.html:14 Uncaught ReferenceError: require is not defined(…)
or
test.html:18 Uncaught SyntaxError: Unexpected token <
Update
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
<script src="https://unpkg.com/babel-core@5.8.38/browser.min.js"></script>
<script src="dist/react-chartjs.js"></script>
<script src="js/require.js"></script>
<body>
<script type='text/babel'>
var LineChart = require("react-chartjs").Line;
var MyComponent = React.createClass({
render: function() {
return <LineChart data={chartData} options={chartOptions} width="600" height="250"/>
}
});
</script>
</body>
</html>
now the error is:
Uncaught Error: Module name "react-chartjs" has not been loaded yet for context: _. Use require([])(…)