html原生echart柱状图

html原生echart柱状图

html原生echart柱状图_第1张图片

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Bar Chart Example</title>
  <!-- Include Chart.js library -->
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  <style>
    canvas {
      max-width: 600px;
      margin: 20px;
    }
  </style>
</head>
<body>
  <!-- Create a canvas element to render the chart -->
  <canvas id="myChart"></canvas>

  <script>
    // Data for the bar chart
    var data = {
      labels: ['January', 'February', 'March', 'April', 'May'],
      datasets: [{
        label: 'Sample Bar Chart',
        backgroundColor: 'rgba(54, 162, 235, 0.5)',
        borderColor: 'rgba(54, 162, 235, 1)',
        borderWidth: 1,
        data: [12, 19, 15, 10, 7],
      }]
    };

    // Configuration options
    var options = {
      scales: {
        y: {
          beginAtZero: true
        }
      }
    };

    // Get the canvas element
    var ctx = document.getElementById('myChart').getContext('2d');

    // Create the bar chart
    var myChart = new Chart(ctx, {
      type: 'bar',
      data: data,
      options: options
    });
  </script>
</body>
</html>

你可能感兴趣的:(快速开发助手,html,javascript,前端)