I try to create a random plot in js.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plot Example</title>
<!-- Include Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<!-- Your plot will be displayed here -->
<div id="plot"></div>
<script>
// Generate some random data
const numPoints = 100;
const xData = Array.from({length: numPoints}, () => Math.random() * 10);
const yData = Array.from({length: numPoints}, () => Math.random() * 10);
// Create a trace for the scatter plot
const trace = {
x: xData,
y: yData,
mode: 'markers',
type: 'scatter',
marker: {
color: 'blue',
size: 8
}
};
// Define layout options
const layout = {
title: 'Random Scatter Plot',
xaxis: {
title: 'X-axis'
},
yaxis: {
title: 'Y-axis'
}
};
// Combine data and layout, then plot
Plotly.newPlot('plot', [trace], layout);
</script>
</body>
</html>
Here is the final result
0 Comments