create a dashboard of function x = cos(y) in javascript

<!DOCTYPE html>
<html>
<head>
    <title>Cosine Function Dashboard</title>
    <!-- Load Plotly.js -->
    <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
    <!-- Dashboard Layout -->
    <div id="dashboard">
        <div id="cosine-plot"></div>
    </div>

    <!-- Script to generate the cosine plot -->
    <script>
        // Generate data for y
        const yValues = Array.from({length: 100}, (_, i) => i / 10);

        // Calculate corresponding x = cos(y) values
        const xValues = yValues.map(y => Math.cos(y));

        // Create a trace for the cosine function
        const trace = {
            x: yValues,
            y: xValues,
            mode: 'lines',
            type: 'scatter',
            name: 'cos(y)'
        };

        // Layout for the plot
        const layout = {
            title: 'Cosine Function',
            xaxis: {
                title: 'y'
            },
            yaxis: {
                title: 'cos(y)'
            }
        };

        // Plot the graph
        Plotly.newPlot('cosine-plot', [trace], layout);
    </script>
</body>
</html>
1127 chars
47 lines

This code snippet creates a simple dashboard in HTML using Plotly.js to visualize the function x = cos(y). It generates 100 data points for y ranging from 0 to 10, calculates x = cos(y), and then plots a line graph to visualize the cosine function.

gistlibby LogSnag