G2
G2
G6
F2
L7
墨者学院
关于 G2
图表示例
API 文档
使用教程
English
折线图
基础折线图
双折线图
多折线图
其他折线图
条形图
分组条形图
堆叠条形图
基础条形图
柱状图
基础柱状图
分组柱状图
堆叠柱状图
直方图
饼图
环图
玫瑰图
基础饼图
嵌套饼图
点图
散点图
面积图
基础面积图
堆叠面积图
区间面积图
箱形图
箱型图
烛形图
烛形图
热力图
热力图
仪表盘
仪表盘
漏斗图
漏斗图
地图
地图
雷达图
雷达图
分面
分面
关系图
关系图
其他图表
其他
迷你图
组件使用
组件
仪表盘
某产品新老用户对比分析
源码
复制成功
复制失败
全屏
复制
运行
<!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="mountNode"></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 src="https://gw.alipayobjects.com/os/antv/pkg/_antv.data-set-0.10.1/dist/data-set.min.js"></script> <script src="https://gw.alipayobjects.com/os/antv/assets/lib/jquery-3.2.1.min.js"></script> <style> .g2-guide-html { width: 80px; height: 80px; vertical-align: middle; text-align: center; line-height: 0.4 } .g2-guide-html .title { font-size: 14px; color: #8c8c8c; font-weight: 300; } .g2-guide-html .value { font-size: 24px; color: #000; font-weight: bold; } </style> <script> var Shape = G2.Shape; Shape.registerShape('point', 'pointer', { drawShape: function drawShape(cfg, group) { var point = cfg.points[0]; var center = this.parsePoint({ x: 0, y: 0 }); var target = this.parsePoint({ x: point.x, y: 0.9 }); var dir_vec = { x: center.x - target.x, y: center.y - target.y }; //normalize var length = Math.sqrt(dir_vec.x * dir_vec.x + dir_vec.y * dir_vec.y); dir_vec.x *= 1 / length; dir_vec.y *= 1 / length; //rotate dir_vector by -90 and scale var angle1 = -Math.PI / 2; var x_1 = Math.cos(angle1) * dir_vec.x - Math.sin(angle1) * dir_vec.y; var y_1 = Math.sin(angle1) * dir_vec.x + Math.cos(angle1) * dir_vec.y; //rotate dir_vector by 90 and scale var angle2 = Math.PI / 2; var x_2 = Math.cos(angle2) * dir_vec.x - Math.sin(angle2) * dir_vec.y; var y_2 = Math.sin(angle2) * dir_vec.x + Math.cos(angle2) * dir_vec.y; //polygon vertex var path = [['M', target.x + x_1 * 1, target.y + y_1 * 1], ['L', center.x + x_1 * 3, center.y + y_1 * 3], ['L', center.x + x_2 * 3, center.y + y_2 * 3], ['L', target.x + x_2 * 1, target.y + y_2 * 1], ['Z']]; var tick = group.addShape('path', { attrs: { path: path, fill: cfg.color } }); return tick; } }); var data = [{ type: '新注册', value: 0.42 }, { type: '老用户', value: 0.68 }, { type: '新订单用户', value: 0.21 }]; var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight, padding: 'auto' }); chart.source(data); chart.coord('polar', { startAngle: -10 / 8 * Math.PI, endAngle: 2 / 8 * Math.PI, radius: 0.75 }); chart.scale('value', { min: 0, max: 1, tickInterval: 1, nice: false }); chart.axis(false); chart.facet('rect', { fields: ['type'], showTitle: false, eachView: function eachView(view, facet) { var data = facet.data[0]; //指针 view.point().position('value*1').shape('pointer').color('#d8d8d8').active(false); //仪表盘背景 view.guide().arc({ zIndex: 0, top: false, start: [0, 1], end: [1, 1], style: { stroke: '#ebedf0', lineWidth: 10 } }); //仪表盘前景 view.guide().arc({ zIndex: 1, start: [0, 1], end: [data.value, 1], style: { stroke: '#1890ff', lineWidth: 10 } }); //仪表盘信息 var percent = parseInt(data.value * 100); view.guide().html({ position: ['50%', '75%'], html: '<div class="g2-guide-html"><p class="title">' + data.type + '</p><p class="value">' + percent + '%</p></div>' }); } }); chart.render(); </script> </body> </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 style="background: #1f1f1f;"> <div id="mountNode"></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 src="https://gw.alipayobjects.com/os/antv/pkg/_antv.data-set-0.10.1/dist/data-set.min.js"></script> <script src="https://gw.alipayobjects.com/os/antv/assets/lib/jquery-3.2.1.min.js"></script> <script>G2.Global.setTheme('dark');</script> <style> .g2-guide-html { width: 80px; height: 80px; vertical-align: middle; text-align: center; line-height: 0.4 } .g2-guide-html .title { font-size: 14px; color: #8c8c8c; font-weight: 300; } .g2-guide-html .value { font-size: 24px; color: #000; font-weight: bold; } </style> <script> var Shape = G2.Shape; Shape.registerShape('point', 'pointer', { drawShape: function drawShape(cfg, group) { var point = cfg.points[0]; var center = this.parsePoint({ x: 0, y: 0 }); var target = this.parsePoint({ x: point.x, y: 0.9 }); var dir_vec = { x: center.x - target.x, y: center.y - target.y }; //normalize var length = Math.sqrt(dir_vec.x * dir_vec.x + dir_vec.y * dir_vec.y); dir_vec.x *= 1 / length; dir_vec.y *= 1 / length; //rotate dir_vector by -90 and scale var angle1 = -Math.PI / 2; var x_1 = Math.cos(angle1) * dir_vec.x - Math.sin(angle1) * dir_vec.y; var y_1 = Math.sin(angle1) * dir_vec.x + Math.cos(angle1) * dir_vec.y; //rotate dir_vector by 90 and scale var angle2 = Math.PI / 2; var x_2 = Math.cos(angle2) * dir_vec.x - Math.sin(angle2) * dir_vec.y; var y_2 = Math.sin(angle2) * dir_vec.x + Math.cos(angle2) * dir_vec.y; //polygon vertex var path = [['M', target.x + x_1 * 1, target.y + y_1 * 1], ['L', center.x + x_1 * 3, center.y + y_1 * 3], ['L', center.x + x_2 * 3, center.y + y_2 * 3], ['L', target.x + x_2 * 1, target.y + y_2 * 1], ['Z']]; var tick = group.addShape('path', { attrs: { path: path, fill: cfg.color } }); return tick; } }); var data = [{ type: '新注册', value: 0.42 }, { type: '老用户', value: 0.68 }, { type: '新订单用户', value: 0.21 }]; var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight, padding: 'auto' }); chart.source(data); chart.coord('polar', { startAngle: -10 / 8 * Math.PI, endAngle: 2 / 8 * Math.PI, radius: 0.75 }); chart.scale('value', { min: 0, max: 1, tickInterval: 1, nice: false }); chart.axis(false); chart.facet('rect', { fields: ['type'], showTitle: false, eachView: function eachView(view, facet) { var data = facet.data[0]; //指针 view.point().position('value*1').shape('pointer').color('#d8d8d8').active(false); //仪表盘背景 view.guide().arc({ zIndex: 0, top: false, start: [0, 1], end: [1, 1], style: { stroke: '#ebedf0', lineWidth: 10 } }); //仪表盘前景 view.guide().arc({ zIndex: 1, start: [0, 1], end: [data.value, 1], style: { stroke: '#1890ff', lineWidth: 10 } }); //仪表盘信息 var percent = parseInt(data.value * 100); view.guide().html({ position: ['50%', '75%'], html: '<div class="g2-guide-html"><p class="title">' + data.type + '</p><p class="value">' + percent + '%</p></div>' }); } }); chart.render(); </script> </body> </html>
图表用法
数据来源:demo数据
相关链接
BizCharts
Viser