AntV/G2 柱状图+折线图双轴图表

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,height=device-height">
    <title>柱状图+折线图双轴图表</title>
    <style>::-webkit-scrollbar{display:none;}html,body{overflow:hidden;height:100%;margin:0;}</style>
</head>
<body>
<div id="chartcontainer"></div>
<script>/*Fixing iframe window.innerHeight 0 issue in Safari*/document.body.clientHeight;</script>
<script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.g2-3.5.1/dist/g2.min.js"></script>
<script>
  var data = [{
    date: '10:10',
    type: 4,
    value: 2,
    rate: 2
  }, {
    date: '10:15',
    type: 2,
    value: 6,
    rate: 3
  }, {
    date: '10:20',
    type: 13,
    value: 2,
    rate: 5
  }, {
    date: '10:25',
    type: 9,
    value: 9,
    rate: 1
  }, {
    date: '10:30',
    type: 5,
    value: 2,
    rate: 3
  }, {
    date: '10:35',
    type: 8,
    value: 2,
    rate: 1
  }, {
    date: '10:40',
    type: 13,
    value: 1,
    rate: 2
  }];

  var chart = new G2.Chart({
    container: 'chartcontainer',
    forceFit: true,
    height: window.innerHeight
  });
  chart.source(data, {
    type: {
      min: 0
    },
    rate: {
      min: 0
    },
    value: {
      min: 0
    }
  });
  chart.legend({
    custom: true,
    allowAllCanceled: true,
    items: [{
      value: 'value',
      marker: {
        symbol: 'square',
        fill: '#FF6347',
        radius: 5
      }
    }, {
      value: 'rate',
      marker: {
        symbol: 'hyphen',
        stroke: '#6495ED',
        radius: 5,
        lineWidth: 3
      }
    }]
  });
  chart.axis('rate', {
    grid: null,
    label: {
      textStyle: {
        fill: '#6495ED'
      }
    }
  });
  chart.interval().position('date*value').color('#FF6347');
  chart.line().position('date*rate').color('#6495ED').size(3).shape('smooth');
  chart.point().position('date*rate').color('#6495ED').size(3).shape('circle');
  chart.render();
</script>
</body>
</html>

页面效果:

相关推荐
是你的小橘呀28 分钟前
JavaScript 原型链解密:原来 proto 和 prototype 这么好懂
前端·javascript·前端框架
ohyeah31 分钟前
使用 LocalStorage 实现本地待办事项(To-Do)列表
前端·javascript
Jing_Rainbow31 分钟前
【前端三剑客-6/Lesson11(2025-10-28)构建现代响应式网页:从 HTML 到 CSS 弹性布局再到 JavaScript 交互的完整指南 🌈
前端·javascript
非专业程序员33 分钟前
精读 GitHub - servo 浏览器(一)
前端·ios·rust
Yanni4Night34 分钟前
掌握 JS 中迭代器的未来用法
前端·javascript
Irene199135 分钟前
Element UI 及其 Vue 3 版本 Element Plus 发展现状
前端·vue.js·ui
Account_Ray36 分钟前
vue3 的专属二维码组件 vue3-next-qrcode 迎来 4.0.0 版本
前端·vue.js·nuxt.js
BBB努力学习程序设计40 分钟前
Web App开发入门:页面分析与环境准备全攻略
前端·html
BBB努力学习程序设计44 分钟前
超好用的轮播图神器:Swiper插件入门指南
前端·html
帧栈1 小时前
开发避坑指南(70):Vue3 Http请求头携带token下载pdf文件解决方案
前端·vue.js