-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add legend support to charts * added polyfill for find
- Loading branch information
1 parent
3a3323f
commit 6e32667
Showing
7 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import {Pie} from 'react-chartjs-2'; | ||
|
||
const data = { | ||
labels: [ | ||
'Red', | ||
'Green', | ||
'Yellow' | ||
], | ||
datasets: [{ | ||
data: [300, 50, 100], | ||
backgroundColor: [ | ||
'#FF6384', | ||
'#36A2EB', | ||
'#FFCE56' | ||
], | ||
hoverBackgroundColor: [ | ||
'#FF6384', | ||
'#36A2EB', | ||
'#FFCE56' | ||
] | ||
}] | ||
}; | ||
|
||
const legendOpts = { | ||
onClick: (e, item) => alert(`Item with text ${item.text} and index ${item.index} clicked`), | ||
onHover: (e, item) => alert(`Item with text ${item.text} and index ${item.index} hovered`), | ||
}; | ||
|
||
export default React.createClass({ | ||
displayName: 'LegendExample', | ||
|
||
getInitialState() { | ||
return { | ||
legend: legendOpts | ||
} | ||
}, | ||
|
||
applyLegendSettings() { | ||
const { value } = this.legendOptsInput; | ||
|
||
try { | ||
const opts = JSON.parse(value); | ||
this.setState({ | ||
legend: opts | ||
}); | ||
} catch(e) { | ||
alert(e.message); | ||
throw Error(e); | ||
} | ||
}, | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<h2>Legend Handlers Example</h2> | ||
<p>Hover over label and click</p> | ||
<Pie data={data} legend={this.state.legend} /> | ||
</div> | ||
); | ||
} | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import {Pie} from 'react-chartjs-2'; | ||
|
||
const data = { | ||
labels: [ | ||
'Red', | ||
'Green', | ||
'Yellow' | ||
], | ||
datasets: [{ | ||
data: [300, 50, 100], | ||
backgroundColor: [ | ||
'#FF6384', | ||
'#36A2EB', | ||
'#FFCE56' | ||
], | ||
hoverBackgroundColor: [ | ||
'#FF6384', | ||
'#36A2EB', | ||
'#FFCE56' | ||
] | ||
}] | ||
}; | ||
|
||
const legendOpts = { | ||
display: true, | ||
position: 'top', | ||
fullWidth: true, | ||
reverse: false, | ||
labels: { | ||
fontColor: 'rgb(255, 99, 132)' | ||
} | ||
}; | ||
|
||
export default React.createClass({ | ||
displayName: 'LegendExample', | ||
|
||
getInitialState() { | ||
return { | ||
legend: legendOpts | ||
} | ||
}, | ||
|
||
applyLegendSettings() { | ||
const { value } = this.legendOptsInput; | ||
|
||
try { | ||
const opts = JSON.parse(value); | ||
this.setState({ | ||
legend: opts | ||
}); | ||
} catch(e) { | ||
alert(e.message); | ||
throw Error(e); | ||
} | ||
}, | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<h2>Legend Options Example</h2> | ||
<textarea | ||
cols="40" | ||
rows="15" | ||
ref={input => { this.legendOptsInput = input; }} | ||
defaultValue={JSON.stringify(this.state.legend, null, 2)}></textarea> | ||
<div> | ||
<button onClick={this.applyLegendSettings}>Apply legend settings</button> | ||
</div> | ||
<Pie data={data} legend={this.state.legend} redraw /> | ||
</div> | ||
); | ||
} | ||
}) |
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
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
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
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
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