<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>Graph Plotter</
title
>
<
script
src
=
</
script
>
<
script
src
=
</
script
>
<
style
>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
.container {
text-align: center;
width: 80%;
max-width: 800px;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin-top: 50px;
}
header {
background-color: #3498db;
color: white;
padding: 20px 0;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
h1 {
margin: 0;
}
.input-container {
display: flex;
justify-content: center;
align-items: center;
margin-top: 20px;
}
input {
padding: 10px;
margin: 0 10px;
width: 60%;
border: 1px solid #ccc;
border-radius: 5px;
}
button {
padding: 10px 20px;
background-color: #e74c3c;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s;
}
button:hover {
background-color: #c0392b;
}
.main-content {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
padding-top: 50px;
}
.graph {
width: 100%;
height: 400px;
margin: 20px 0;
/* Adjust margin if needed */
border: 1px solid #ccc;
border-radius: 10px;
}
</
style
>
</
head
>
<
body
>
<
div
class
=
"container"
>
<
header
>
<
h1
>Graph Plotter</
h1
>
<
div
class
=
"input-container"
>
<
input
type
=
"text"
id
=
"functionInput"
placeholder
=
"Enter a function, e.g. y = x^2"
>
<
button
onclick
=
"plotGraph()"
>
Plot
</
button
>
</
div
>
</
header
>
<
div
class
=
"main-content"
>
<
div
class
=
"graph"
id
=
"graph"
></
div
>
</
div
>
</
div
>
<
script
>
function plotGraph() {
const graph = document.getElementById('graph');
graph.innerHTML = '';
const functionInput =
document.getElementById('functionInput').value;
const expr = math.parse(functionInput).compile();
const xValues = math.range(-10, 10, 0.1)._data;
const yValues = xValues.map(x => expr.evaluate({ x }));
const trace = {
x: xValues,
y: yValues,
type: 'scatter',
mode: 'lines',
};
const layout = {
xaxis: { title: 'X-axis' },
yaxis: { title: 'Y-axis' },
};
Plotly.newPlot(graph, [trace], layout);
}
</
script
>
</
body
>
</
html
>