Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Python

1 from dashboards.dashboard import Dashboard


2 from dashboards.component.text import Text
3
4
5 class SalesDashboard(Dashboard):
6 intro = Text(value=“Welcome to the Finance Dashboard”)
7
8 class Meta:
9 name = “Sales”
10
Python

1 from dashboards.dashboard import Dashboard


2 from dashboards.component.text import Text
3
4
5 class SalesDashboard(Dashboard):
6 intro = Text(value=“Welcome to the Finance Dashboard”)
7
8 class Meta:
9 name = “Sales”
10
Python

1 from dashboards.dashboard import Dashboard


2 from dashboards.component.text import Text
3
4
5 class SalesDashboard(Dashboard):
6 intro = Text(value=“<h1>Welcome to the Finance
Dashboard</h1><p>The Group’s Financial Analysis.</p>”,
mark_safe=True, grid_css_classes=“span-12”)
7
8 class Meta:
9 name = “Sales”
10
Python
1 from dashboards.dashboard import Dashboard
2 from dashboards.component.text import Text
3 from dashboards.component import Chart
4 from dashboards.component.chart import ChartSerializer
5 import plotly.express as px
6 from django.db.models import Count
7 from sales.models import Sale
8
9
10 class SalesByChannelChart(ChartSerializer):
11 def get_queryset(self, *args, **kwargs):
12 return (
13 Sale.objects
14 .values(“channel”)
15 .annotate(qty=Count(“id”))
16 .values(“channel”, “qty”)
17 .order_by(“-qty”)
18 )
19
Python
20 def to_fig(self, df):
21 fig = px.funnel_area(
22 df,
23 names=“channel”,
24 values=“qty”,
25 )
26 return fig
27
28 class Meta:
29 title = “Sales by Channel”
30
31
32 class SalesDashboard(Dashboard):
33 intro = Text(value=“<h1>Welcome to the Finance
Dashboard</h1><p>The Group’s Financial Analysis.</p>”,
mark_safe=True, grid_css_classes=”span-12”)
Python
34 sales_by_channel = Chart(value=SalesByChannelChart)
35
36 class Meta:
37 name = “Sales”
38
Python
1 from dashboards.dashboard import Dashboard
2 from dashboards.component.text import Text
3 from dashboards.component import Chart
4 from dashboards.component.chart import ChartSerializer
5 import plotly.express as px
6 from django.db.models import Count
7 from sales.models import Sale
8
9
10 class SalesByChannelChart(ChartSerializer):
11 def get_queryset(self, *args, **kwargs):
12 return (
13 Sale.objects
14 .values(“channel”)
15 .annotate(qty=Count(“id”))
16 .values(“channel”, “qty”)
17 .order_by(“-qty”)
18 )
19
Python
1 from dashboards.dashboard import Dashboard
2 from dashboards.component.text import Text
3 from dashboards.component import Chart
4 from dashboards.component.chart import ChartSerializer
5 import plotly.express as px
6 from django.db.models import Count, Sum
7 from sales.models import Sale
8
9
10 class SalesByChannelChart(ChartSerializer):
11 def get_queryset(self, *args, **kwargs):
12 return (
13 Sale.objects
14 .values(“channel”)
15 .annotate(qty=Count(“id”))
16 .values(“channel”, “qty”)
17 .order_by(“-qty”)
18 )
19
Python

20 def to_fig(self, df):


21 fig = px.funnel_area(
22 df,
23 names=”channel”,
24 values=”qty”,
25 )
26 return fig
27
28 class Meta:
29 title = “Sales by Channel”
30
31
32 class ProfitPerYearChart(ChartSerializer):
33 def get_queryset(self, *args, **kwargs):
34 return (
35 Sale.objects
36 .annotate(total_profit=Sum(“profit_amount”))
37 .values(“year”, “channel”, “total_profit”)
38 .order_by(“year”)
39 )
40
41 def to_fig(self, df):
42 fig = px.bar(
43 df,
44 y=“year”,
45 x=“total_profit”,
46 color=“channel”,
47 orientation=“h”,
48 )
49 fig.update_layout(xaxis_title=“Year”,
yaxis_title=“Profit”)
50
51 return fig
52
53 class Meta:
54 title = “Profit per Year”
55
56
57 class SalesDashboard(Dashboard):
58 intro = Text(value=“<h1>Welcome to the Finance Dash-
board</h1><p>The Group’s Financial Analysis.</p>”, mark_
safe=True, grid_css_classes=“span-12”)
59 sales_by_channel = Chart(value=SalesByChannelChart)
60 profit_per_year = Chart(defer=ProfitPerYearChart)
61
62
63 class Meta:
64 name = “Sales”
65
|
Effort|
Effortlessly|
Effortlessly Build|
Effortlessly Build Dashboards
Effortlessly Build Dashboards|
Effortlessly Build Dashboards

You might also like