Data Science Lesson 30 – Dashboard Basics| Dataplexa
Data Visualization · Lesson 30

Dashboard Basics

Build interactive dashboards using Chart.js to display business KPIs, track performance metrics, and present data insights that drive decision-making.

What Makes a Dashboard Work?

Think about the dashboard in your car. Three critical gauges — speed, fuel, engine temperature. You glance for 2 seconds and know exactly what's happening. Business dashboards work the same way.

The best dashboards answer three questions in under 30 seconds: What happened? Why did it happen? What should we do? Everything else is noise.

Good Dashboard

Revenue trend, top 3 problems, next action needed

Bad Dashboard

47 charts, rainbow colors, requires PhD to interpret

Chart.js handles the heavy lifting — rendering, responsiveness, interactions. But you still need to pick the right chart type. This is where 80% of dashboards fail. Wrong chart = confused stakeholders = bad decisions.

Chart Selection Strategy

Chart Type Best For Avoid When
Bar Comparing categories, rankings Time series data
Line Trends over time, forecasts < 5 data points
Pie/Doughnut Part-to-whole, percentages > 6 categories
Scatter Correlations, outliers Categorical data
Radar Multi-attribute comparison Single metric tracking

Common Mistake

Using histogram or heatmap in Chart.js — they render blank. Stick to the 8 supported types above.

Revenue Analysis Dashboard

The scenario: Flipkart's category manager needs to present Q3 performance to the board. Revenue by category, monthly trends, and customer satisfaction — all in one view.

# Import essential libraries for data analysis
import pandas as pd
import numpy as np

# Load the ecommerce dataset
df = pd.read_csv('dataplexa_ecommerce.csv')

# Quick peek at our data structure
print(df.head())

What just happened?

We loaded 11 columns of ecommerce data. Notice revenue ranges from ₹650 to ₹30,900, and rating is our satisfaction metric. Try this: Check data types with df.dtypes

# Calculate revenue by product category for bar chart
category_revenue = df.groupby('product_category')['revenue'].sum()

# Convert to lakhs for easier reading
category_revenue_lakhs = category_revenue / 100000

# Sort from highest to lowest revenue
category_revenue_lakhs = category_revenue_lakhs.sort_values(ascending=False)
print(category_revenue_lakhs)

What just happened?

Electronics dominates with ₹28.4L revenue, while Books trails at ₹4.3L. The sort_values(ascending=False) gives us the ranking. Try this: Check if this pattern holds across cities too.

Electronics and Clothing drive 66% of total platform revenue

The bar chart reveals a clear power law distribution — Electronics generates 40% of revenue, while the bottom two categories contribute just 18% combined. This isn't unusual for marketplace businesses.

For board presentation, this single chart justifies resource allocation. Why spend equal marketing budget on Books when Electronics brings 6x the revenue? The visual makes the decision obvious.

Monthly Revenue Trends

# Convert date column to datetime for time series analysis
df['date'] = pd.to_datetime(df['date'])

# Extract month from date for monthly grouping
df['month'] = df['date'].dt.strftime('%b')

# Calculate monthly revenue totals
monthly_revenue = df.groupby('month')['revenue'].sum() / 100000
print(monthly_revenue)

What just happened?

Monthly revenue stays fairly stable (₹5.7L to ₹7.1L), with December peak likely due to festive season. The dt.strftime('%b') gives us short month names. Try this: Compare this to your business's seasonal patterns.

Steady growth momentum with 24% festive season boost in Q4

The line chart with fill:true creates an area effect, perfect for showing cumulative impact. Notice the gentle upward trend from July onwards — exactly what you want investors to see.

The 24% Q4 spike (Nov-Dec) validates seasonal marketing spend. But more importantly, the baseline never drops below ₹5.7L — indicating solid underlying business health beyond promotions.

Customer Satisfaction by Category

# Calculate average rating by category
category_ratings = df.groupby('product_category')['rating'].mean()

# Round to 1 decimal place for cleaner display
category_ratings = category_ratings.round(1)

# Sort by rating to see top performers
category_ratings_sorted = category_ratings.sort_values(ascending=False)
print(category_ratings_sorted)

What just happened?

Books leads satisfaction (4.5/5) despite lowest revenue, while Food lags at 3.9/5. The round(1) makes ratings dashboard-friendly. Try this: Cross-reference with return rates to validate.

Books achieve highest satisfaction despite being smallest revenue category

The doughnut chart immediately reveals the satisfaction paradox — highest revenue (Electronics) doesn't equal highest ratings. Books dominate the green section despite being the smallest revenue slice.

This insight drives strategic decisions. Food's red section (3.9 rating) needs immediate attention — it's dragging overall platform perception. Meanwhile, Books proves small categories can punch above their weight in customer loyalty.

📊 Data Insight

Electronics drives 40% of revenue but ranks 2nd in satisfaction. Food needs urgent quality intervention with 3.9/5 rating dragging platform NPS.

Advanced Chart Configurations

Real dashboards need more than basic charts. Stacked bars for comparative analysis, scatter plots for correlations, radar charts for multi-dimensional performance — each serves specific business questions.

# Create stacked bar data: returned vs successful orders
category_returns = df.groupby(['product_category', 'returned']).size().unstack(fill_value=0)

# Calculate percentages for better comparison
category_return_pct = category_returns.div(category_returns.sum(axis=1), axis=0) * 100
print(category_return_pct.round(1))

What just happened?

Food has highest return rate (10.4%) while Books lowest (5.8%). The unstack(fill_value=0) pivots boolean returns into columns. Try this: Set stacked:true in Chart.js for comparative view.

# Scatter plot data: price vs rating correlation
scatter_data = df[['unit_price', 'rating', 'product_category']].copy()

# Sample 200 points for cleaner visualization
scatter_sample = scatter_data.sample(200, random_state=42)

# Check correlation strength
correlation = scatter_sample['unit_price'].corr(scatter_sample['rating'])
print(f"Price-Rating Correlation: {correlation:.3f}")

What just happened?

Weak correlation (0.089) between price and satisfaction — expensive doesn't mean better rated. The sample(200) prevents overcrowded scatter plots. Try this: Use bubble charts to add third dimension like quantity.

Dashboard Performance Tips

Chart.js dashboards can slow down with large datasets. Rule of thumb: 500+ points needs sampling. 10,000+ points crashes mobile browsers entirely.

Performance Optimization

Use animation: {duration: 0} for faster rendering. Set responsive: true but limit canvas size with CSS max-height.

Never create two Chart instances on the same canvas ID — Chart.js throws errors silently. Always destroy existing charts before creating new ones: chart.destroy().

Color consistency matters more than you think. Electronics should always be teal across all charts — users build mental associations. Random colors every time breaks cognitive flow.

Critical Error

Avoid histogram, violin, heatmap, or boxplot chart types — they render completely blank in Chart.js. Stick to the 8 supported types: bar, line, pie, doughnut, scatter, bubble, radar, polarArea.

Interactive Features

Static charts tell stories. Interactive charts let users explore their own questions. Chart.js handles tooltips, zoom, and click events automatically — but you control what information appears.

# Custom tooltip configuration for business context
tooltip_config = {
  'callbacks': {
    # Add currency symbol and formatting
    'label': 'function(context) { return "₹" + context.parsed.y + "L revenue"; }',
    # Add additional context in footer
    'footer': 'function(tooltipItems) { return "Click for detailed breakdown"; }'
  }
}

What just happened?

Custom tooltips add business context — ₹ symbol, "L" for lakhs, actionable hints. The callback functions transform raw numbers into meaningful information. Try this: Add percentage of total in tooltip footer.

The best dashboards anticipate questions. Revenue is down — why? Click the bar to drill into regional breakdown. Ratings dropped — which products specifically? Every chart should connect to deeper analysis.

Mobile-first design isn't optional anymore. 60% of executive dashboard views happen on phones during commutes. Test every chart on a 6-inch screen — if you can't read it clearly, redesign.

Quiz

1. You need to build a revenue dashboard showing category performance, monthly trends, and market share. Which Chart.js combination works best?


2. Your dashboard updates charts dynamically when users select different time periods. What's the correct way to update a Chart.js visualization?


3. Your ecommerce dashboard loads slowly on mobile devices with 50,000+ data points. What's the best optimization approach?


Up Next

Advanced Visualizations

Master complex chart types, custom animations, and interactive storytelling techniques that transform static dashboards into compelling data narratives.