Code
Code
HTML Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Chart Generator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Chart Generator</h1>
<div class="form">
<label for="chartType">Select Chart Type:</label>
<select id="chartType">
<option value="bar">Bar Chart</option>
<option value="line">Line Chart</option>
<option value="pie">Pie Chart</option>
</select>
<label for="dataInput">Enter Data (comma-separated):</label>
<input type="text" id="dataInput" placeholder="e.g., 10, 20, 30">
<button onclick="generateChart()">Generate Chart</button>
</div>
<div class="chart-container">
<canvas id="myChart"></canvas>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="script.js"></script>
</body>
</html>
CSS Code:-
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 50px auto;
text-align: center;
}
.form {
margin-bottom: 20px;
}body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
.container {
max-width: 800px;
margin: 50px auto;
text-align: center;
padding: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
transition: box-shadow 0.3s ease;
}
.container:hover {
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}
h1 {
color: #333;
}
.form {
margin-bottom: 20px;
}
label {
margin-right: 10px;
color: #555;
}
input[type="text"] {
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
transition: border-color 0.3s ease;
}
input[type="text"]:focus {
border-color: #66afe9;
}
select, button {
padding: 8px;
border: none;
border-radius: 4px;
background-color: #007bff;
color: #fff;
cursor: pointer;
transition: background-color 0.3s ease;
}
select:hover, button:hover {
background-color: #0056b3;
}
.chart-container {
margin-top: 20px;
}
label {
margin-right: 10px;
}
input, select, button {
margin-bottom: 10px;
}
.chart-container {
margin-top: 20px;
}
Javascript code:-
function generateChart() {
// Fetching user input
const chartType = document.getElementById('chartType').value;
const dataInput = document.getElementById('dataInput').value;