1+ import React from 'react' ;
2+ import { Grid } from '@material-ui/core' ;
3+
4+ import Widget from '../../components/Widget' ;
5+ import ApexLineChart from './components/ApexLineChart' ;
6+ import ApexHeatmap from './components/ApexHeatmap'
7+ import {
8+ CartesianGrid ,
9+ Legend ,
10+ Line ,
11+ LineChart ,
12+ Pie ,
13+ PieChart ,
14+ ResponsiveContainer , Sector ,
15+ Tooltip ,
16+ XAxis ,
17+ YAxis
18+ } from "recharts" ;
19+ import { withTheme } from "@material-ui/core" ;
20+ import PageTitle from "../../components/PageTitle" ;
21+
22+ const lineChartData = [
23+ {
24+ name : 'Page A' , uv : 4000 , pv : 2400 , amt : 2400 ,
25+ } ,
26+ {
27+ name : 'Page B' , uv : 3000 , pv : 1398 , amt : 2210 ,
28+ } ,
29+ {
30+ name : 'Page C' , uv : 2000 , pv : 9800 , amt : 2290 ,
31+ } ,
32+ {
33+ name : 'Page D' , uv : 2780 , pv : 3908 , amt : 2000 ,
34+ } ,
35+ {
36+ name : 'Page E' , uv : 1890 , pv : 4800 , amt : 2181 ,
37+ } ,
38+ {
39+ name : 'Page F' , uv : 2390 , pv : 3800 , amt : 2500 ,
40+ } ,
41+ {
42+ name : 'Page G' , uv : 3490 , pv : 4300 , amt : 2100 ,
43+ } ,
44+ ] ;
45+
46+ const pieChartData = [
47+ { name : 'Group A' , value : 400 } ,
48+ { name : 'Group B' , value : 300 } ,
49+ { name : 'Group C' , value : 300 } ,
50+ { name : 'Group D' , value : 200 } ,
51+ ] ;
52+
53+ const renderActiveShape = ( props ) => {
54+ const RADIAN = Math . PI / 180 ;
55+ const {
56+ cx, cy, midAngle, innerRadius, outerRadius, startAngle, endAngle,
57+ fill, payload, percent, value,
58+ } = props ;
59+ const sin = Math . sin ( - RADIAN * midAngle ) ;
60+ const cos = Math . cos ( - RADIAN * midAngle ) ;
61+ const sx = cx + ( outerRadius + 10 ) * cos ;
62+ const sy = cy + ( outerRadius + 10 ) * sin ;
63+ const mx = cx + ( outerRadius + 30 ) * cos ;
64+ const my = cy + ( outerRadius + 30 ) * sin ;
65+ const ex = mx + ( cos >= 0 ? 1 : - 1 ) * 22 ;
66+ const ey = my ;
67+ const textAnchor = cos >= 0 ? 'start' : 'end' ;
68+
69+ return (
70+ < g >
71+ < text x = { cx } y = { cy } dy = { 8 } textAnchor = "middle" fill = { fill } > { payload . name } </ text >
72+ < Sector
73+ cx = { cx }
74+ cy = { cy }
75+ innerRadius = { innerRadius }
76+ outerRadius = { outerRadius }
77+ startAngle = { startAngle }
78+ endAngle = { endAngle }
79+ fill = { fill }
80+ />
81+ < Sector
82+ cx = { cx }
83+ cy = { cy }
84+ startAngle = { startAngle }
85+ endAngle = { endAngle }
86+ innerRadius = { outerRadius + 6 }
87+ outerRadius = { outerRadius + 10 }
88+ fill = { fill }
89+ />
90+ < path d = { `M${ sx } ,${ sy } L${ mx } ,${ my } L${ ex } ,${ ey } ` } stroke = { fill } fill = "none" />
91+ < circle cx = { ex } cy = { ey } r = { 2 } fill = { fill } stroke = "none" />
92+ < text x = { ex + ( cos >= 0 ? 1 : - 1 ) * 12 } y = { ey } textAnchor = { textAnchor } fill = "#333" > { `PV ${ value } ` } </ text >
93+ < text x = { ex + ( cos >= 0 ? 1 : - 1 ) * 12 } y = { ey } dy = { 18 } textAnchor = { textAnchor } fill = "#999" >
94+ { `(Rate ${ ( percent * 100 ) . toFixed ( 2 ) } %)` }
95+ </ text >
96+ </ g >
97+ ) ;
98+ } ;
99+
100+ const ChartsView = ( props ) => (
101+ < React . Fragment >
102+ < PageTitle title = "Charts Page - Data Display" button = "Latest Reports" />
103+ < Grid container spacing = { 32 } >
104+ < Grid item xs = { 12 } md = { 6 } >
105+ < Widget title = "Apex Line Chart" upperTitle noBodyPadding >
106+ < ApexLineChart />
107+ </ Widget >
108+ </ Grid >
109+ < Grid item xs = { 12 } md = { 6 } >
110+ < Widget title = "Apex Heatmap" upperTitle noBodyPadding >
111+ < ApexHeatmap />
112+ </ Widget >
113+ </ Grid >
114+ < Grid item xs = { 12 } md = { 8 } >
115+ < Widget title = "Simple Line Chart" noBodyPadding upperTitle >
116+ < ResponsiveContainer width = "100%" height = { 350 } >
117+ < LineChart
118+ width = { 500 }
119+ height = { 300 }
120+ data = { lineChartData }
121+ margin = { {
122+ top : 5 , right : 30 , left : 20 , bottom : 5 ,
123+ } }
124+ >
125+ < CartesianGrid strokeDasharray = "3 3" />
126+ < XAxis dataKey = "name" />
127+ < YAxis />
128+ < Tooltip />
129+ < Legend />
130+ < Line type = "monotone" dataKey = "pv" stroke = { props . theme . palette . primary . main } activeDot = { { r : 8 } } />
131+ < Line type = "monotone" dataKey = "uv" stroke = { props . theme . palette . secondary . main } />
132+ </ LineChart >
133+ </ ResponsiveContainer >
134+ </ Widget >
135+ </ Grid >
136+ < Grid item xs = { 12 } md = { 4 } >
137+ < Widget title = "Pie Chart with Tooltips" noBodyPadding upperTitle >
138+ < ResponsiveContainer width = "100%" height = { 300 } >
139+ < PieChart width = { 200 } height = { 300 } >
140+ < Pie
141+ activeIndex = { props . activeIndex }
142+ activeShape = { renderActiveShape }
143+ data = { pieChartData }
144+ cx = { 200 }
145+ cy = { 150 }
146+ innerRadius = { 60 }
147+ outerRadius = { 80 }
148+ fill = { props . theme . palette . primary . main }
149+ dataKey = "value"
150+ onMouseEnter = { props . changeActiveIndexId }
151+ />
152+ </ PieChart >
153+ </ ResponsiveContainer >
154+ </ Widget >
155+ </ Grid >
156+ </ Grid >
157+ </ React . Fragment >
158+ ) ;
159+
160+ export default withTheme ( ) ( ChartsView ) ;
0 commit comments