Certainly! Below is a single HTML file that includes an animated Return on Investment (ROI) calculator with graphs. This example uses basic HTML, CSS, and JavaScript along with the Chart.js library for graph visualization.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Tools Academy ROI Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 800px;
margin: auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input {
width: calc(100% - 10px);
padding: 5px;
}
.btn {
display: block;
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
.btn:hover {
background-color: #45a049;
}
#roiChart {
width: 100%;
height: 400px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>AI Tools Academy ROI Calculator</h1>
<div class="form-group">
<label for="initialInvestment">Initial Investment ($):</label>
<input type="number" id="initialInvestment" placeholder="Enter initial investment">
</div>
<div class="form-group">
<label for="monthlySavings">Monthly Savings ($):</label>
<input type="number" id="monthlySavings" placeholder="Enter monthly savings">
</div>
<div class="form-group">
<label for="roiPeriod">ROI Period (months):</label>
<input type="number" id="roiPeriod" placeholder="Enter ROI period in months">
</div>
<button class="btn" onclick="calculateROI()">Calculate ROI</button>
<canvas id="roiChart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
let roiChart;
function calculateROI() {
const initialInvestment = parseFloat(document.getElementById('initialInvestment').value);
const monthlySavings = parseFloat(document.getElementById('monthlySavings').value);
const roiPeriod = parseInt(document.getElementById('roiPeriod').value);
if (isNaN(initialInvestment) || isNaN(monthlySavings) || isNaN(roiPeriod)) {
alert("Please enter valid numbers for all fields.");
return;
}
const roiData = [];
let totalSavings = 0;
for (let i = 0; i <= roiPeriod; i++) {
totalSavings += monthlySavings;
roiData.push(totalSavings - initialInvestment);
}
const labels = Array.from({ length: roiPeriod + 1 }, (_, i) => i);
if (roiChart) {
roiChart.destroy();
}
const ctx = document.getElementById('roiChart').getContext('2d');
roiChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'ROI ($)',
data: roiData,
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 2,
fill: false,
}]
},
options: {
scales: {
x: {
title: {
display: true,
text: 'Months'
}
},
y: {
title: {
display: true,
text: 'ROI ($)'
}
}
},
animation: {
duration: 2000,
easing: 'easeOutBounce'
}
}
});
}
</script>
</body>
</html>
Explanation:
-
HTML Structure:
- A form with inputs for initial investment, monthly savings, and ROI period.
- A button to trigger the ROI calculation.
- A canvas element to display the ROI chart.
-
CSS:
- Basic styling for the form and button.
- Styling for the container to center it and add some padding and borders.
-
JavaScript:
- Uses Chart.js to create a line chart.
- Calculates the ROI based on the inputs and updates the chart accordingly.
- The chart is animated with a bounce effect for a better user experience.
How to Use:
- Open this HTML file in a web browser.
- Enter the initial investment, monthly savings, and ROI period.
- Click the "Calculate ROI" button to see the animated ROI chart.