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>
相关推荐
诸葛老刘1 天前
前端 css中的函数
前端·css
谢尔登1 天前
通用会话控制方案
前端·网络协议·tcp/ip·react.js·gitlab
惜茶1 天前
websocket操作入门
前端·javascript·websocket
摇滚侠1 天前
Vue 项目实战《尚医通》,获取当前账户就诊人信息并展示出来,笔记42
前端·javascript·vue.js·笔记·html5
han_1 天前
前端高频面试题之Vue-router篇
前端·vue.js·面试
用户47949283569151 天前
接手祖传代码后,我终于理解了"组合优于继承"
javascript
C.果栗子1 天前
Blob格式的PDF文件调用打印,浏览器文件打印(兼容)
前端·javascript·pdf
倚肆1 天前
CSS 选择器空格使用区别详解
前端·css
盼哥PyAI实验室1 天前
学会给网页穿衣服——学习 CSS 语言
前端·css·学习
我的xiaodoujiao1 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 25--数据驱动--参数化处理 Excel 文件 2
前端·python·学习·测试工具·ui·pytest