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-table { width: 100%; border-collapse: collapse; text-align: left; border-radius: 4px 4px 0 0; table-layout: fixed; } .g2-thead { display: table-header-group; vertical-align: middle; border-bottom-color: #e8e8e8; border-bottom-style: solid; border-bottom-width: 1px; background-color: #fafafa; } .th-index { width: 30px; } .g2-thead th { text-align: center; height: 50px; font-size: 12px; } .th-index { width: 50px; } .th-id { width: 20%; } .g2-table-row { height: 60px; vertical-align: middle; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #e8e8e8; } .g2-table-column { font-size: 12px; color: #8c8c8c; text-align: center; } canvas { position: relative; float: left; } .top-class { width: 20px; height: 20px; border-radius: 100px; background-color: #314659; text-align: center; vertical-align: middle; margin-left: 15px; color: white; font-weight: bold; } .top-class:after { display: inline-block; width: 0; height: 100%; vertical-align: middle; content: ''; } .normal-class { width: 20px; height: 20px; border-radius: 100px; background-color: #f0f2f5; text-align: center; vertical-align: middle; margin-left: 15px; color: #717274; font-weight: bold; } .normal-class:after { display: inline-block; width: 0; height: 100%; vertical-align: middle; content: ''; } </style> <!-- table --> <table class="g2-table"> <!--head--> <thead class="g2-thead"> <tr> <th class="th-index">排序</th> <th class="th-id">来源</th> <th>用户数(万)</th> </tr> </thead> <!--body--> <tbody> </tbody> </table> <script> var data = [{ index: 1, source: 'Iphone', data: [{ 'value': 25 }] }, { index: 2, source: 'Galxy S5', data: [{ 'value': 18 }] }, { index: 3, source: 'Sony', data: [{ 'value': 6 }] }, { index: 4, source: 'Mac OS', data: [{ 'value': 3 }] }, { index: 5, source: 'HUAWEI', data: [{ 'value': 2 }] }]; //append data var $tbody = $('.g2-table').children('tbody'); data.forEach(function(d, index) { //create container var $tr = $('<tr class="g2-table-row"></tr>'); $tbody.append($tr); //index var indexClass = index < 3 ? 'top-class' : 'normal-class'; var $index = $('<td class="g2-table-column g2-table-column-index"><div class="' + indexClass + '">' + d.index + '</div></td>'); $tr.append($index); //source var $source = $('<td class="g2-table-column">' + d.source + '</td>'); $tr.append($source); //data var dataID = 'bar-chart-' + index; var $data = $('<td class="g2-table-column"><div class="chartContainer" id="' + dataID + '"></div></td>'); $tr.append($data); createSingleBarChart(dataID, d.data); }); function createSingleBarChart(containerId, data) { var chart = new G2.Chart({ container: containerId, forceFit: true, height: 60, padding: 0 }); chart.source(data, { value: { max: 30, min: 0 } }); chart.legend(false); chart.axis(false); chart.tooltip({ type: 'mini' }); chart.coord().transpose(); chart.interval().position('1*value').opacity(1).size(120).label('value', { offset: 10, textStyle: { fontSize: 12, color: '#595959' } }); 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-table { width: 100%; border-collapse: collapse; text-align: left; border-radius: 4px 4px 0 0; table-layout: fixed; } .g2-thead { display: table-header-group; vertical-align: middle; border-bottom-color: #e8e8e8; border-bottom-style: solid; border-bottom-width: 1px; background-color: #fafafa; } .th-index { width: 30px; } .g2-thead th { text-align: center; height: 50px; font-size: 12px; } .th-index { width: 50px; } .th-id { width: 20%; } .g2-table-row { height: 60px; vertical-align: middle; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #e8e8e8; } .g2-table-column { font-size: 12px; color: #8c8c8c; text-align: center; } canvas { position: relative; float: left; } .top-class { width: 20px; height: 20px; border-radius: 100px; background-color: #314659; text-align: center; vertical-align: middle; margin-left: 15px; color: white; font-weight: bold; } .top-class:after { display: inline-block; width: 0; height: 100%; vertical-align: middle; content: ''; } .normal-class { width: 20px; height: 20px; border-radius: 100px; background-color: #f0f2f5; text-align: center; vertical-align: middle; margin-left: 15px; color: #717274; font-weight: bold; } .normal-class:after { display: inline-block; width: 0; height: 100%; vertical-align: middle; content: ''; } </style> <!-- table --> <table class="g2-table"> <!--head--> <thead class="g2-thead"> <tr> <th class="th-index">排序</th> <th class="th-id">来源</th> <th>用户数(万)</th> </tr> </thead> <!--body--> <tbody> </tbody> </table> <script> var data = [{ index: 1, source: 'Iphone', data: [{ 'value': 25 }] }, { index: 2, source: 'Galxy S5', data: [{ 'value': 18 }] }, { index: 3, source: 'Sony', data: [{ 'value': 6 }] }, { index: 4, source: 'Mac OS', data: [{ 'value': 3 }] }, { index: 5, source: 'HUAWEI', data: [{ 'value': 2 }] }]; //append data var $tbody = $('.g2-table').children('tbody'); data.forEach(function(d, index) { //create container var $tr = $('<tr class="g2-table-row"></tr>'); $tbody.append($tr); //index var indexClass = index < 3 ? 'top-class' : 'normal-class'; var $index = $('<td class="g2-table-column g2-table-column-index"><div class="' + indexClass + '">' + d.index + '</div></td>'); $tr.append($index); //source var $source = $('<td class="g2-table-column">' + d.source + '</td>'); $tr.append($source); //data var dataID = 'bar-chart-' + index; var $data = $('<td class="g2-table-column"><div class="chartContainer" id="' + dataID + '"></div></td>'); $tr.append($data); createSingleBarChart(dataID, d.data); }); function createSingleBarChart(containerId, data) { var chart = new G2.Chart({ container: containerId, forceFit: true, height: 60, padding: 0 }); chart.source(data, { value: { max: 30, min: 0 } }); chart.legend(false); chart.axis(false); chart.tooltip({ type: 'mini' }); chart.coord().transpose(); chart.interval().position('1*value').opacity(1).size(120).label('value', { offset: 10, textStyle: { fontSize: 12, color: '#595959' } }); chart.render(); } </script></body> </html>
图表用法
数据来源:demo数据
相关链接
BizCharts
Viser