Machine Learning

Create Data Dashboard using HTML, CSS, and JavaScript

Your customer dashboard, clients, or their fellow workers are part of the skills set up by software developers, data scientists, ml, and data engineers. Or you work primarily on the process of base back, details you use frequently requires “surfaced” to users at a particular time. If you are lucky, your organization may have a previously dedicated team to take care of that, but often it will be down to you.

Being a straight Python Engineer without Experience in HTML, JavaScript, etc.

This text is not for them, however, because I am One of those people are straightforward, and I have already done a broadcast and gradio. So it was time to fold my sleeves and see if I could learn new skills and to create a Dashiboard and the old advanced development: HTML, Javascript, and CSS.

Our Dashboard details will appear in the SQLILE location database. I build a Sales_data Table in SQLITE containing dummy sales data. Here are the data in the form of tabar.

Photo by the writer

Below one code you can use to follow and create your SQLITE and table database and data as shown.

In case you wonder why I only add a few records to my database, it is not because I don't think the code can handle small data volumes. It is just that I wanted to focus on the dashboard performance rather than the data. Feel free to use the text I offer below to enter additional records input data if you like.

Therefore, we live in the Python of Nthon only long when we set a SQLITINE DB program in order.

import sqlite3

# Define the database name
DATABASE_NAME = "C:\Users\thoma\projects\my-dashboard\sales_data.db"

# Connect to SQLite database
conn = sqlite3.connect(DATABASE_NAME)

# Create a cursor object
cursor = conn.cursor()

# SQL to create the 'sales' table
create_table_query = '''
CREATE TABLE IF NOT EXISTS sales (
    order_id INTEGER PRIMARY KEY,
    order_date TEXT,
    customer_id INTEGER,
    customer_name TEXT,
    product_id INTEGER,
    product_names TEXT,
    categories TEXT,
    quantity INTEGER,
    price REAL,
    total REAL
);
'''

# Execute the query to create the table
cursor.execute(create_table_query)

# Sample data to insert into the 'sales' table
sample_data = [
    (1, "2022-08-01", 245, "Customer_884", 201, "Smartphone", "Electronics", 3, 90.02, 270.06),
    (2, "2022-02-19", 701, "Customer_1672", 205, "Printer", "Electronics", 6, 12.74, 76.44),
    (3, "2017-01-01", 184, "Customer_21720", 208, "Notebook", "Stationery", 8, 48.35, 386.80),
    (4, "2013-03-09", 275, "Customer_23770", 200, "Laptop", "Electronics", 3, 74.85, 224.55),
    (5, "2022-04-23", 960, "Customer_23790", 210, "Cabinet", "Office", 6, 53.77, 322.62),
    (6, "2019-07-10", 197, "Customer_25587", 202, "Desk", "Office", 3, 47.17, 141.51),
    (7, "2014-11-12", 510, "Customer_6912", 204, "Monitor", "Electronics", 5, 22.5, 112.5),
    (8, "2016-07-12", 150, "Customer_17761", 200, "Laptop", "Electronics", 9, 49.33, 443.97)
]

# SQL to insert data into the 'sales' table
insert_data_query = '''
INSERT INTO sales (order_id, order_date, customer_id, customer_name, product_id, product_names, categories, quantity, price, total)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
'''

# Insert the sample data
cursor.executemany(insert_data_query, sample_data)

# Commit the transaction
conn.commit()

# Close the connection
conn.close()

print(f"Database '{DATABASE_NAME}' has been created and populated successfully.")

Dashboard performance

Our dashboard will have the next function.

  • The main metrics. Currency, total orders, average order value, maximum class
  • Different types of chart. Time income (line chart), income in section (a bar chart), high products for income (horizontal of the Baries)
  • Sorting. Day and category
  • Data table. Demonstrate our data records in the paved and continuous grid.

To set our environment

Next, we have a series of steps that should be followed to set up our environment.

1 / Enter Node.js.

Node.js is a javaScript without browser, which allows you to use javascript to create a server's instant and server applications.

Therefore, make sure Node.js is included in your system so that it can use a local server and manage packages. You can pick up from the Node.JS official website.

2 / Create a main project folder and subfolders

Open your command terminal and run the following instructions. I use the personality in my Windows box in this, but you can change it to suit your preferred instruction system and program.

$ mkdir my-dashboard
$ cd my-dashboard
$ mkdir client
% mkdir server

3 / Start Node project

$ npm init -y

This command creates automatically automatic packet.json File to your project Directory without requiring user input.

This page Flag responses “Yes” In all motions, you use Default prices For fields such as:

  • name
  • version
  • description
  • potent
  • scripture
  • writer
  • license

Here's what my package file looked like.

{
  "name": "my-dashboard",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "express": "^4.21.2",
    "sqlite3": "^5.1.7"
  }
}

4 / Enter Express and SQLITE

Sqlite Is the engine of a lack of lightness, based on files that keep your information from one, portable file, which ends the need for a different server.

Squeeze A small framework, the node.js variable enhances the construction of the APIs and web servers through the route and the MiddleWare.

We can include both using the command below.

$ npm install express sqlite3

Now, we can begin to improve our code. For this project, we will need four code files: Index Index.html File, the server.js file, the client file.js, and script.js file.

Let's exceed each of them by step by step.

1) Client / index.html




    
    
    
    
    
    Sales Performance Dashboard


    

Key Metrics

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button