Build a web UI for your time series forecasting model with our step-by-step guide. Learn expert tips and practical examples!

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
// Example: A Flask endpoint that loads a pre-trained forecasting model
from flask import Flask, request, jsonify
import json
import numpy as np
app = Flask(**name**)
// Dummy forecasting function (replace with actual forecasting logic)
def forecast(time\_series, steps):
// Here, simply extend the last value as forecast
last_value = time_series[-1]
return [last_value for _ in range(steps)]
@app.route('/forecast', methods=['POST'])
def get\_forecast():
data = request.get\_json() // Parse JSON data from request body
time_series = data.get('time_series', [])
steps = data.get('steps', 5)
if not time\_series:
return jsonify({'error': 'No time series provided'}), 400
predictions = forecast(time\_series, steps)
return jsonify({'predictions': predictions})
if **name** == '**main**':
app.run(debug=True)
/forecast endpoint listens for POST requests, performs a simple forecast, and returns the result.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Time Series Forecasting UI</title>
<!-- Include Chart.js library from CDN -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div>
<label for="ts\_data">Enter time series data (comma separated):</label>
<input type="text" id="ts\_data" placeholder="e.g., 10,20,30,40"/>
</div>
<div>
<label for="steps">Forecast Steps:</label>
<input type="number" id="steps" value="5"/>
</div>
<div>
<button id="forecastBtn">Generate Forecast</button>
</div>
<canvas id="forecastChart" width="600" height="400"></canvas>
<script src="app.js"></script>
</body>
</html>
<canvas> element is used by Chart.js to render the forecast visualization.
// app.js
document.getElementById('forecastBtn').addEventListener('click', function() {
// Parse time series data from input
var tsInput = document.getElementById('ts\_data').value;
var timeSeries = tsInput.split(',').map(Number); // Convert comma-separated values into numbers
// Get the number of forecast steps from the input
var steps = parseInt(document.getElementById('steps').value, 10);
// Create JSON payload for POST request
var payload = {
time\_series: timeSeries,
steps: steps
};
// Send a POST request to the backend forecast endpoint
fetch('/forecast', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(function(response) {
return response.json();
})
.then(function(data) {
if (data.error) {
alert(data.error);
return;
}
// Combine original series with forecast for visualization
var combinedData = timeSeries.concat(data.predictions);
// Create an array for the x-axis labels representing time steps
// For demonstration, simply use sequential numbers
var labels = Array.from({ length: combinedData.length }, (v, k) => k + 1);
// Render the chart using Chart.js
var ctx = document.getElementById('forecastChart').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Time Series & Forecast',
data: combinedData,
borderColor: 'rgba(75, 192, 192, 1)',
fill: false
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Time Series Forecasting'
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Time Steps'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
}]
}
}
});
})
.catch(function(error) {
console.error('Error:', error);
});
});
From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.Â