function Graph2DPlotter() { const [equation, setEquation] = useState('x**2'); const [xMin, setXMin] = useState('-10'); const [xMax, setXMax] = useState('10'); const plotGraph = () => { try { const xValues = []; const yValues = []; const min = parseFloat(xMin); const max = parseFloat(xMax); const step = (max - min) / 200; for (let x = min; x <= max; x += step) { try { const y = eval(equation.replace(/x/g, `(${x})`)); if (isFinite(y)) { xValues.push(x); yValues.push(y); } } catch (e) { // Skip invalid points } } const trace = { x: xValues, y: yValues, type: 'scatter', mode: 'lines', line: { color: '#2563eb', width: 2 } }; const layout = { title: `y = ${equation}`, xaxis: { title: 'x', gridcolor: '#e2e8f0' }, yaxis: { title: 'y', gridcolor: '#e2e8f0' }, plot_bgcolor: '#f8fafc', paper_bgcolor: '#ffffff', }; Plotly.newPlot('graph2d-plot', [trace], layout, { responsive: true }); } catch (error) { alert('Error plotting graph. Please check your equation.'); } }; return (

📈 2D Graph Plotter

Enter a mathematical expression using 'x' as variable. Examples: x**2, Math.sin(x), x**3 - 2*x

setEquation(e.target.value)} placeholder="x**2" />
setXMin(e.target.value)} />
setXMax(e.target.value)} />
); } // Export to global registry window.Graph2DPlotter = Graph2DPlotter;