File tree Expand file tree Collapse file tree 5 files changed +83
-4
lines changed
awesome_dashboard/static/src Expand file tree Collapse file tree 5 files changed +83
-4
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ import { registry } from "@web/core/registry";
33import { useService } from "@web/core/utils/hooks" ;
44import { Layout } from "@web/search/layout" ;
55import { DashboardItem } from "./dashboard_item/dashboard_item" ;
6+ import { PieChart } from './pie_chart/pie_chart' ;
67
78class AwesomeDashboard extends Component {
89 static template = "awesome_dashboard.AwesomeDashboard" ;
9- static components = { Layout, DashboardItem } ;
10+ static components = { Layout, DashboardItem, PieChart } ;
1011
1112 setup ( ) {
1213 this . action = useService ( "action" ) ;
Original file line number Diff line number Diff line change 1414 Leads
1515 </button >
1616 </t >
17- <div >
17+ <div class = " d-flex " >
1818 <DashboardItem >
1919 Average amount of t-shirt by order this month
2020 <t t-set-slot =" value" t-esc =" statistics.average_quantity" />
2828 <t t-set-slot =" value" t-esc =" statistics.nb_new_orders" />
2929 </DashboardItem >
3030 </div >
31- <div >
31+ <div class = " d-flex align-items-start " >
3232 <DashboardItem >
3333 Number of cancelled orders this month
3434 <t t-set-slot =" value" t-esc =" statistics.nb_cancelled_orders" />
3737 Total amount of new orders this month
3838 <t t-set-slot =" value" t-esc =" statistics.total_amount" />
3939 </DashboardItem >
40+ <DashboardItem size =" 2" >
41+ Shirt orders by size
42+ <t t-set-slot =" value" >
43+ <PieChart data =" statistics.orders_by_size" />
44+ </t >
45+ </DashboardItem >
4046 </div >
4147 </Layout >
4248 </t >
Original file line number Diff line number Diff line change 22<templates xml : space =" preserve" >
33
44 <t t-name =" awesome_dashboard.DashboardItem" >
5- <div class =" card d-inline-block m-2 " t-attf-style =" width: {{props.size*18}}rem;" >
5+ <div class =" card d-inline-block m-4 " t-attf-style =" width: {{props.size*18}}rem;" >
66 <div class =" card-body text-center" >
77 <div class =" card-title" >
88 <h5 >
Original file line number Diff line number Diff line change 1+ import {
2+ Component ,
3+ onWillStart ,
4+ onWillUnmount ,
5+ useRef ,
6+ useEffect ,
7+ } from "@odoo/owl" ;
8+ import { loadJS } from "@web/core/assets" ;
9+
10+ export class PieChart extends Component {
11+ static template = "awesome_dashboard.PieChart" ;
12+ static props = { data : { optional : true } }
13+
14+ setup ( ) {
15+ this . rootRef = useRef ( "root" ) ;
16+ this . canvasRef = useRef ( "canvas" ) ;
17+ this . containerRef = useRef ( "container" ) ;
18+
19+ this . chart = null ;
20+ this . tooltip = null ;
21+ this . legendTooltip = null ;
22+
23+ onWillStart ( async ( ) => {
24+ await loadJS ( "/web/static/lib/Chart/Chart.js" )
25+ } ) ;
26+
27+ useEffect ( ( ) => {
28+ this . renderChart ( ) ;
29+ } ) ;
30+
31+ onWillUnmount ( this . onWillUnmount ) ;
32+ }
33+
34+ onWillUnmount ( ) {
35+ if ( this . chart ) {
36+ this . chart . destroy ( ) ;
37+ }
38+ }
39+
40+ renderChart ( ) {
41+ if ( this . chart ) {
42+ this . chart . destroy ( ) ;
43+ }
44+
45+ const labels = Object . keys ( this . props . data ) ;
46+ const values = Object . values ( this . props . data ) ;
47+
48+ const config = {
49+ type : 'pie' ,
50+ data : {
51+ labels : labels ,
52+ datasets : [ {
53+ label : "Orders by size" ,
54+ data : values ,
55+ } ] ,
56+ } ,
57+ }
58+
59+ this . chart = new Chart ( this . canvasRef . el , config ) ;
60+ }
61+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <templates xml : space =" preserve" >
3+
4+ <t t-name =" awesome_dashboard.PieChart" >
5+ <div t-ref =" root" >
6+ <canvas t-ref =" canvas" />
7+ </div >
8+ </t >
9+
10+ </templates >
11+
You can’t perform that action at this time.
0 commit comments