├── README.md ├── dashboard.py └── data.py /README.md: -------------------------------------------------------------------------------- 1 | # tkinter-matplotlib-dashboard 2 | Source code for Youtube video: https://youtu.be/2JjQIh-sgHU 3 | -------------------------------------------------------------------------------- /dashboard.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg 3 | import matplotlib.pyplot as plt 4 | from data import sales_data, inventory_data, product_data, sales_year_data, inventory_month_data 5 | 6 | 7 | plt.rcParams["axes.prop_cycle"] = plt.cycler( 8 | color=["#4C2A85", "#BE96FF", "#957DAD", "#5E366E", "#A98CCC"]) 9 | 10 | # Chart 1: Bar chart of sales data 11 | fig1, ax1 = plt.subplots() 12 | ax1.bar(sales_data.keys(), sales_data.values()) 13 | ax1.set_title("Sales by Product") 14 | ax1.set_xlabel("Product") 15 | ax1.set_ylabel("Sales") 16 | # plt.show() 17 | 18 | # Chart 2: Horizontal bar chart of inventory data 19 | fig2, ax2 = plt.subplots() 20 | ax2.barh(list(inventory_data.keys()), inventory_data.values()) 21 | ax2.set_title("Inventory by Product") 22 | ax2.set_xlabel("Inventory") 23 | ax2.set_ylabel("Product") 24 | # plt.show() 25 | 26 | # Chart 3: Pie chart of product data 27 | fig3, ax3 = plt.subplots() 28 | ax3.pie(product_data.values(), labels=product_data.keys(), autopct='%1.1f%%') 29 | ax3.set_title("Product \nBreakdown") 30 | # plt.show() 31 | 32 | # Chart 4: Line chart of sales by year 33 | fig4, ax4 = plt.subplots() 34 | ax4.plot(list(sales_year_data.keys()), list(sales_year_data.values())) 35 | ax4.set_title("Sales by Year") 36 | ax4.set_xlabel("Year") 37 | ax4.set_ylabel("Sales") 38 | # plt.show() 39 | 40 | # Chart 5: Area chart of inventory by month 41 | fig5, ax5 = plt.subplots() 42 | ax5.fill_between(inventory_month_data.keys(), 43 | inventory_month_data.values()) 44 | ax5.set_title("Inventory by Month") 45 | ax5.set_xlabel("Month") 46 | ax5.set_ylabel("Inventory") 47 | # plt.show() 48 | 49 | # Create a window and add charts 50 | root = tk.Tk() 51 | root.title("Dashboard") 52 | root.state('zoomed') 53 | 54 | side_frame = tk.Frame(root, bg="#4C2A85") 55 | side_frame.pack(side="left", fill="y") 56 | 57 | label = tk.Label(side_frame, text="Dashboard", bg="#4C2A85", fg="#FFF", font=25) 58 | label.pack(pady=50, padx=20) 59 | 60 | charts_frame = tk.Frame(root) 61 | charts_frame.pack() 62 | 63 | upper_frame = tk.Frame(charts_frame) 64 | upper_frame.pack(fill="both", expand=True) 65 | 66 | canvas1 = FigureCanvasTkAgg(fig1, upper_frame) 67 | canvas1.draw() 68 | canvas1.get_tk_widget().pack(side="left", fill="both", expand=True) 69 | 70 | canvas2 = FigureCanvasTkAgg(fig2, upper_frame) 71 | canvas2.draw() 72 | canvas2.get_tk_widget().pack(side="left", fill="both", expand=True) 73 | 74 | canvas3 = FigureCanvasTkAgg(fig3, upper_frame) 75 | canvas3.draw() 76 | canvas3.get_tk_widget().pack(side="left", fill="both", expand=True) 77 | 78 | lower_frame = tk.Frame(charts_frame) 79 | lower_frame.pack(fill="both", expand=True) 80 | 81 | canvas4 = FigureCanvasTkAgg(fig4, lower_frame) 82 | canvas4.draw() 83 | canvas4.get_tk_widget().pack(side="left", fill="both", expand=True) 84 | 85 | canvas5 = FigureCanvasTkAgg(fig5, lower_frame) 86 | canvas5.draw() 87 | canvas5.get_tk_widget().pack(side="left", fill="both", expand=True) 88 | 89 | root.mainloop() 90 | -------------------------------------------------------------------------------- /data.py: -------------------------------------------------------------------------------- 1 | # Dummy data 2 | sales_data = { 3 | "Product A": 100, 4 | "Product B": 200, 5 | "Product C": 600, 6 | "Product D": 400, 7 | "Product E": 500 8 | } 9 | 10 | inventory_data = { 11 | "Product A": 150, 12 | "Product B": 75, 13 | "Product C": 100, 14 | "Product D": 125, 15 | "Product E": 150 16 | } 17 | 18 | product_data = { 19 | "A": 10, 20 | "B": 40, 21 | "C": 30, 22 | "D": 20, 23 | "E": 50 24 | } 25 | 26 | sales_year_data = { 27 | 2018: 5000, 28 | 2019: 17500, 29 | 2020: 10000, 30 | 2021: 7500, 31 | 2022: 15000 32 | } 33 | 34 | inventory_month_data = { 35 | "Jan": 200, 36 | "Feb": 300, 37 | "Mar": 800, 38 | "Apr": 1300, 39 | "May": 600, 40 | "Jun": 900, 41 | "Jul": 700, 42 | "Aug": 900, 43 | "Sep": 1000, 44 | "Oct": 300, 45 | "Nov": 450, 46 | "Dec": 1300 47 | } 48 | --------------------------------------------------------------------------------