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>

页面效果:

相关推荐
JustHappy1 小时前
古法编程秘籍(六):程序到底是怎么跑起来的?从 IO 到中断,一次讲明白
前端·后端·全栈
HYCS2 小时前
用pixi.js实现fabric.js(六):从线性代数的角度理解编辑器交互
前端·javascript·canvas
卷帘依旧2 小时前
useImperativeHandle的作用
前端
卷帘依旧2 小时前
Hooks在Fiber上的存储原理
前端
you45802 小时前
学成在线--day02 CMS前端开发(含Vue基础知识得回顾)
前端·javascript·vue.js
xiaofeichaichai2 小时前
虚拟 DOM
前端·javascript·vue.js
2401_878454532 小时前
前端高频得手写题
前端
初一初十3 小时前
vue3实现的纯前端护肤品商城网站
前端·javascript·vue.js·前端框架
卷帘依旧3 小时前
React状态管理方案怎么选
前端