html原生echart柱状图

html原生echart柱状图

bash 复制代码
<!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>
相关推荐
摘星编程3 小时前
OpenHarmony + RN:Placeholder文本占位
javascript·react native·react.js
a1117764 小时前
医院挂号预约系统(开源 Fastapi+vue2)
前端·vue.js·python·html5·fastapi
0思必得04 小时前
[Web自动化] Selenium处理iframe和frame
前端·爬虫·python·selenium·自动化·web自动化
行走的陀螺仪6 小时前
uni-app + Vue3编辑页/新增页面给列表页传参
前端·vue.js·uni-app
摘星编程7 小时前
React Native + OpenHarmony:Spinner旋转加载器
javascript·react native·react.js
We་ct7 小时前
LeetCode 205. 同构字符串:解题思路+代码优化全解析
前端·算法·leetcode·typescript
2301_812731417 小时前
CSS3笔记
前端·笔记·css3
ziblog7 小时前
CSS3白云飘动动画特效
前端·css·css3
越努力越幸运5087 小时前
CSS3学习之网格布局grid
前端·学习·css3
半斤鸡胗7 小时前
css3基础
前端·css