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>

页面效果:

相关推荐
KIKIiiiiiiii4 分钟前
微信个人号开发中如何高效实现API二次开发
java·前端·python·微信
日月之行_10 分钟前
Vite+:企业级前端构建的新选择
前端
山顶听风21 分钟前
Flask应用改用Waitress运行
前端·笔记·python·flask
Tom Ma.23 分钟前
使用腾讯云云开发(CloudBase)的云函数,删除云存储中指定目录下的过期文件
前端·javascript·腾讯云
Hilaku37 分钟前
技术、业务、管理:一个30岁前端的十字路口
前端·javascript·面试
Knight_AL1 小时前
大文件分片上传:简单案例(前端切割与后端合并)
前端·状态模式
雨过天晴而后无语1 小时前
HTML纯JS添加删除行示例一
前端·javascript·html
IT_陈寒1 小时前
Vue3性能翻倍秘籍:5个被低估的Composition API技巧让你开发效率飙升🚀
前端·人工智能·后端
袁煦丞1 小时前
N1+iStoreOS+cpolarN1盒子变身2048服务器:cpolar内网穿透实验室第653个成功挑战
前端·程序员·远程工作
哀木1 小时前
聊聊 vue2 与 vue3 的 v-model
前端