Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit e255385

Browse files
committed
add chart and canvass accessors
1 parent c4593a4 commit e255385

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ var MyComponent = React.createClass({
3737
* all other parameters will be passed through to the ```canvas``` element
3838

3939

40+
Chart References
41+
----------------
42+
The ```canvas``` element can be retrieved using ```getCanvass``` and the ```chartjs object``` can be retrieved using ```getChart```.
43+
44+
4045
### Other React projects that may interest you
4146

4247
* [jhudson8/react-mixin-manager](https://github.com/jhudson8/react-mixin-manager)

lib/core.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module.exports = {
44
displayName: chartType + 'Chart',
55
getInitialState: function() { return {}; },
66
render: function() {
7-
var _props = {};
7+
var _props = {
8+
ref: 'canvass'
9+
};
810
for (var name in this.props) {
911
if (this.props.hasOwnProperty(name)) {
1012
if (name !== 'data' && name !== 'options') {
@@ -46,6 +48,16 @@ module.exports = {
4648
this.state.chart = chart;
4749
};
4850

51+
// return the chartjs instance
52+
classData.getChart = function() {
53+
return this.state.chart;
54+
};
55+
56+
// return the canvass element that contains the chart
57+
classData.getCanvass = function() {
58+
return this.refs.canvass.getDOMNode();
59+
};
60+
4961
var i;
5062
for (i=0; i<extras.length; i++) {
5163
extra(extras[i]);

0 commit comments

Comments
 (0)