Skip to content

Commit c2862ec

Browse files
committed
Add mix type example
close #4
1 parent cfd9937 commit c2862ec

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

example/src/components/mix.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React from 'react';
2+
import {Bar} from 'react-chartjs-2';
3+
4+
const data = {
5+
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
6+
datasets: [{
7+
label: 'Sales',
8+
type:'line',
9+
data: [51, 65, 40, 49, 60, 37, 40],
10+
fill: false,
11+
borderColor: '#EC932F',
12+
backgroundColor: '#EC932F',
13+
pointBorderColor: '#EC932F',
14+
pointBackgroundColor: '#EC932F',
15+
pointHoverBackgroundColor: '#EC932F',
16+
pointHoverBorderColor: '#EC932F',
17+
yAxisID: 'y-axis-2'
18+
},{
19+
type: 'bar',
20+
label: 'Visitor',
21+
data: [200, 185, 590, 621, 250, 400, 95],
22+
fill: false,
23+
backgroundColor: '#71B37C',
24+
borderColor: '#71B37C',
25+
hoverBackgroundColor: '#71B37C',
26+
hoverBorderColor: '#71B37C',
27+
yAxisID: 'y-axis-1'
28+
}]
29+
};
30+
31+
const options = {
32+
responsive: true,
33+
tooltips: {
34+
mode: 'label'
35+
},
36+
elements: {
37+
line: {
38+
fill: false
39+
}
40+
},
41+
scales: {
42+
xAxes: [
43+
{
44+
display: true,
45+
gridLines: {
46+
display: false
47+
},
48+
labels: {
49+
show: true
50+
}
51+
}
52+
],
53+
yAxes: [
54+
{
55+
type: 'linear',
56+
display: true,
57+
position: 'left',
58+
id: 'y-axis-1',
59+
gridLines: {
60+
display: false
61+
},
62+
labels: {
63+
show: true
64+
}
65+
},
66+
{
67+
type: 'linear',
68+
display: true,
69+
position: 'right',
70+
id: 'y-axis-2',
71+
gridLines: {
72+
display: false
73+
},
74+
labels: {
75+
show: true
76+
}
77+
}
78+
]
79+
}
80+
};
81+
82+
export default React.createClass({
83+
displayName: 'MixExample',
84+
85+
render() {
86+
return (
87+
<div>
88+
<h2>Mixed data Example</h2>
89+
<Bar
90+
data={data}
91+
options={options}
92+
/>
93+
</div>
94+
);
95+
}
96+
});

example/src/example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import LineExample from './components/line';
77
import BarExample from './components/bar';
88
import RadarExample from './components/radar';
99
import PolarExample from './components/polar';
10+
import MixedDataExample from './components/mix';
1011

1112
class App extends React.Component {
1213
render() {
@@ -24,6 +25,8 @@ class App extends React.Component {
2425
<RadarExample />
2526
<hr />
2627
<PolarExample />
28+
<hr />
29+
<MixedDataExample />
2730
</div>
2831
);
2932
}

0 commit comments

Comments
 (0)