Industrial Dashboards using HTML, CSS and JavaScript

Industrial dashboards are interfaces used to monitor and control processes in settings like manufacturing plants or power stations. They display real-time data, charts, alerts, and controls, and they need to be functional, user-friendly, and responsive—meaning they adapt seamlessly to various screen sizes (desktops, tablets, mobiles). Let’s dive into the process.

Planning and Project Setup

a. Define Requirements:

  • Identify the key components of your industrial dashboard (e.g., header, sidebar, main content panels, charts, tables, and control widgets).
  • Consider what data needs to be visualized (machine status, production stats, alerts, etc.).

b. Set Up Your Folder Structure:

Create a project folder with a structure similar to this:

/dashboard-project
├── index.html
├── css
│ └── style.css
├── js
│ ├── main.js
│ └── charts.js
└── assets
└── images

This helps in keeping your HTML, CSS, and JavaScript files organized.

Step 1: HTML Structure

Start with a semantic HTML5 template. Industrial dashboards often use a grid layout with cards, charts, and tables.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Industrial Dashboard</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="dashboard-container">
        <!-- Header -->
        <header class="dashboard-header">
            <h1>Factory Monitoring System</h1>
            <div class="status-indicator" id="connectionStatus"></div>
        </header>

        <!-- Main Content Grid -->
        <div class="dashboard-grid">
            <!-- Card 1: Temperature Gauge -->
            <div class="dashboard-card">
                <h2>Temperature</h2>
                <canvas id="tempChart"></canvas>
                <div class="metric-value" id="tempValue">--°C</div>
            </div>

            <!-- Card 2: Pressure -->
            <div class="dashboard-card">
                <h2>Pressure</h2>
                <canvas id="pressureChart"></canvas>
                <div class="metric-value" id="pressureValue">-- kPa</div>
            </div>

            <!-- Card 3: Alerts -->
            <div class="dashboard-card alert-log">
                <h2>Alerts</h2>
                <ul id="alertList"></ul>
            </div>
        </div>
    </div>

    <!-- JavaScript -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="app.js"></script>
</body>
</html>

Step 2: CSS Styling

Use CSS Grid/Flexbox for responsiveness and CSS variables for theme consistency. Industrial dashboards often use dark themes for readability.

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --alert-color: #e74c3c;
    --text-color: #ecf0f1;
}

body {
    margin: 0;
    font-family: 'Arial', sans-serif;
    background-color: var(--primary-color);
    color: var(--text-color);
}

.dashboard-container {
    padding: 1rem;
}

.dashboard-header {
    text-align: center;
    margin-bottom: 2rem;
}

.status-indicator {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin: 0 auto;
    background: #7f8c8d; /* Default offline color */
}

.status-indicator.connected {
    background: #2ecc71; /* Online color */
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.dashboard-card {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.metric-value {
    font-size: 2.5rem;
    text-align: center;
    margin: 1rem 0;
}

.alert-log {
    background: rgba(231, 76, 60, 0.1);
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

Step 3: JavaScript for Dynamic Updates

Add real-time data updates and charts using Chart.js.

// app.js
// Initialize charts
const tempCtx = document.getElementById('tempChart').getContext('2d');
const tempChart = new Chart(tempCtx, {
    type: 'line',
    data: {
        labels: Array(10).fill(''),
        datasets: [{
            label: 'Temperature (°C)',
            data: [],
            borderColor: '#e74c3c',
            tension: 0.1
        }]
    }
});

// Simulate real-time data (replace with WebSocket/API calls)
function updateMetrics() {
    const temp = Math.random() * 100;
    document.getElementById('tempValue').textContent = `${temp.toFixed(1)}°C`;
    
    // Update chart
    if (tempChart.data.datasets[0].data.length > 10) {
        tempChart.data.labels.shift();
        tempChart.data.datasets[0].data.shift();
    }
    tempChart.data.labels.push(new Date().toLocaleTimeString());
    tempChart.data.datasets[0].data.push(temp);
    tempChart.update();
}

// Update every 2 seconds
setInterval(updateMetrics, 2000);

// Connection status simulation
const statusIndicator = document.getElementById('connectionStatus');
setInterval(() => {
    statusIndicator.classList.toggle('connected');
}, 5000);

Step 4: Java Integration (Backend)

While Java isn’t used in the frontend, it can power the backend API. Use a framework like Spring Boot to serve data:

// Example Spring Boot Controller
@RestController
@RequestMapping("/api")
public class DashboardController {

    @GetMapping("/temperature")
    public ResponseEntity<Double> getTemperature() {
        double temp = // ... fetch from sensor or database
        return ResponseEntity.ok(temp);
    }

    @GetMapping("/alerts")
    public ResponseEntity<List<String>> getAlerts() {
        List<String> alerts = // ... fetch alerts
        return ResponseEntity.ok(alerts);
    }
}

Fetch data in JavaScript using fetch:

// Replace the mock updateMetrics() with real data
async function fetchData() {
    const response = await fetch('http://your-java-backend/api/temperature');
    const temp = await response.json();
    // Update UI
}

Key Responsive Design Principles

  1. Fluid Grids: Use grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) for dynamic column counts.
  2. Media Queries: Adjust layouts for mobile (e.g., single-column grids).
  3. Relative Units: Use %rem, or vw/vh instead of fixed pixels.
  4. Flexible Charts: Configure Chart.js to resize with containers:javascriptCopyChart.defaults.responsive = true; Chart.defaults.maintainAspectRatio = false;

Final Tips

  • Use WebSockets (e.g., STOMP over WebSocket) for live data instead of polling.
  • Optimize for performance: Lazy-load non-critical components.
  • Test on multiple screen sizes using browser dev tools (Ctrl+Shift+M in Firefox/Chrome).