Thursday, March 21, 2024

 <!DOCTYPE html>

<html>
  <head>
    <title>Line Graph Maker</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        * {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

.graph-container {
  margin-bottom: 20px;
}

.form-container {
  display: flex;
  flex-direction: column;
}

label {
  font-weight: bold;
  margin-bottom: 5px;
}

input[type="text"] {
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 5px;
  border: 1px solid #ccc;
}

button {
  padding: 10px;
  border-radius: 5px;
  border: none;
  background-color: #4CAF50;
  color: #fff;
  cursor: pointer;
}

button:hover {
  background-color: #3e8e41;
}

    </style>
  </head>
  <body>
    <div class="container">
      <h1>Line Graph Maker</h1>
      <div class="graph-container">
        <canvas id="myChart"></canvas>
      </div>
      <div class="form-container">
        <form>
          <label for="dataset">Enter Dataset:</label>
          <input type="text" id="dataset" placeholder="Enter comma separated values" required>
          <label for="labels">Enter Labels:</label>
          <input type="text" id="labels" placeholder="Enter comma separated labels" required>
          <button type="button" onclick="createChart()">Create Chart</button>
        </form>
      </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script>
        function createChart() {
  // Get data from form
  var dataset = document.getElementById("dataset").value;
  var labels = document.getElementById("labels").value;

  // Split data into arrays
  var datasetArray = dataset.split(",");
  var labelsArray = labels.split(",");

  // Create chart
  var ctx = document.getElementById("myChart").getContext("2d");
  var myChart = new Chart(ctx, {
    type: "line",
    data: {
      labels: labelsArray,
      datasets: [
        {
          label: "My Dataset",
          data: datasetArray,
          borderColor: "rgba(75, 192, 192, 1)",
          backgroundColor: "rgba(75, 192, 192, 0.2)",
          borderWidth: 1
        }
      ]
    },
    options: {
      responsive: true,
      maintainAspectRatio: false,
      scales: {
        yAxes: [
          {
            ticks: {
              beginAtZero: true
            }
          }
        ]
      }
    }
  });
}

    </script>
  </body>
</html>

No comments:

Post a Comment

AI Story Writing Tool AI Story Writing Tool Moral Educational Historical ...