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>

页面效果:

相关推荐
yinuo1 小时前
前端跨页面通讯终极指南⑥:SharedWorker 用法全解析
前端
PineappleCoder6 小时前
还在重复下载资源?HTTP 缓存让二次访问 “零请求”,用户体验翻倍
前端·性能优化
拉不动的猪6 小时前
webpack编译中为什么不建议load替换ast中节点删除consolg.log
前端·javascript·webpack
李姆斯6 小时前
Agent时代下,ToB前端的UI和交互会往哪走?
前端·agent·交互设计
源码获取_wx:Fegn08957 小时前
基于springboot + vue健身房管理系统
java·开发语言·前端·vue.js·spring boot·后端·spring
闲谈共视7 小时前
基于去中心化社交与AI智能服务的Web钱包商业开发的可行性
前端·人工智能·去中心化·区块链
CreasyChan7 小时前
C# 反射详解
开发语言·前端·windows·unity·c#·游戏开发
JIngJaneIL7 小时前
基于Java+ vue智慧医药系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
hashiqimiya9 小时前
两个步骤,打包war,tomcat使用war包
java·服务器·前端
零度@9 小时前
Java中Map的多种用法
java·前端·python