The document defines a SalesDashboard class that inherits from the Dashboard class. The SalesDashboard contains two charts - a sales_by_channel chart that displays sales by channel using a funnel chart, and a profit_per_year chart that displays profit by year using a horizontal bar chart. Both charts retrieve and visualize data from a Sale model using ChartSerializer classes.
The document defines a SalesDashboard class that inherits from the Dashboard class. The SalesDashboard contains two charts - a sales_by_channel chart that displays sales by channel using a funnel chart, and a profit_per_year chart that displays profit by year using a horizontal bar chart. Both charts retrieve and visualize data from a Sale model using ChartSerializer classes.
The document defines a SalesDashboard class that inherits from the Dashboard class. The SalesDashboard contains two charts - a sales_by_channel chart that displays sales by channel using a funnel chart, and a profit_per_year chart that displays profit by year using a horizontal bar chart. Both charts retrieve and visualize data from a Sale model using ChartSerializer classes.
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