G2
G2
G6
F2
L7
墨者学院
关于 G2
图表示例
API 文档
使用教程
English
折线图
基础折线图
双折线图
多折线图
其他折线图
条形图
分组条形图
堆叠条形图
基础条形图
柱状图
基础柱状图
分组柱状图
堆叠柱状图
直方图
饼图
环图
玫瑰图
基础饼图
嵌套饼图
点图
散点图
面积图
基础面积图
堆叠面积图
区间面积图
箱形图
箱型图
烛形图
烛形图
热力图
热力图
仪表盘
仪表盘
漏斗图
漏斗图
地图
地图
雷达图
雷达图
分面
分面
关系图
关系图
其他图表
其他
迷你图
组件使用
组件
分组条形图
条形图-diverging
柱状图,对称层叠
源码
复制成功
复制失败
全屏
复制
运行
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,height=device-height"> <title>条形图-diverging</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> var _DataSet = DataSet, DataView = _DataSet.DataView; var data = [{ "group": "All Survey Responses", "type": "All Survey Responses", "total": 565, "Strongly Agree": 50.1, "Agree": 40.7, "No Opinion": 4.8, "Disagree": 3.7, "Strongly Disagree": 0.7 }, { "group": "Employment sector", "type": "Academic(nonstudent)", "total": 253, "Strongly Agree": 64.0, "Agree": 30.8, "No Opinion": 3.2, "Disagree": 2.0, "Strongly Disagree": 0.0 }, { "group": "Employment sector", "type": "Business and industry", "total": 176, "Strongly Agree": 40.6, "Agree": 50.0, "No Opinion": 2.8, "Disagree": 6.3, "Strongly Disagree": 0.0 }, { "group": "Employment sector", "type": "Federal, state, and local government", "total": 71, "Strongly Agree": 38.0, "Agree": 47.9, "No Opinion": 7.0, "Disagree": 4.2, "Strongly Disagree": 2.8 }, { "group": "Employment sector", "type": "Private consultant/self-employed", "total": 28, "Strongly Agree": 39.3, "Agree": 53.6, "No Opinion": 7.1, "Disagree": 0.0, "Strongly Disagree": 0.0 }, { "group": "Employment sector", "type": "Other", "total": 34, "Strongly Agree": 29.4, "Agree": 44.1, "No Opinion": 14.7, "Disagree": 5.9, "Strongly Disagree": 5.9 }, { "group": "Race", "type": "White", "total": 400, "Strongly Agree": 50.0, "Agree": 41.8, "No Opinion": 4.5, "Disagree": 2.8, "Strongly Disagree": 1.0 }, { "group": "Race", "type": "Asian", "total": 122, "Strongly Agree": 53.3, "Agree": 40.2, "No Opinion": 3.3, "Disagree": 3.3, "Strongly Disagree": 0.0 }, { "group": "Race", "type": "Black or African American", "total": 10, "Strongly Agree": 40.0, "Agree": 30.0, "No Opinion": 20.0, "Disagree": 10.0, "Strongly Disagree": 0.0 }, { "group": "Race", "type": "Other", "total": 17, "Strongly Agree": 47.1, "Agree": 35.3, "No Opinion": 5.9, "Disagree": 11.8, "Strongly Disagree": 0.7 }, { "group": "Education", "type": "Associate's and Bachelor's", "total": 175, "Strongly Agree": 37.1, "Agree": 49.1, "No Opinion": 5.7, "Disagree": 6.9, "Strongly Disagree": 1.1 }, { "group": "Education", "type": "Master's and Above", "total": 388, "Strongly Agree": 55.9, "Agree": 36.9, "No Opinion": 4.4, "Disagree": 2.3, "Strongly Disagree": 0.5 }, { "group": "Gender", "type": "Male", "total": 356, "Strongly Agree": 50.6, "Agree": 41, "No Opinion": 4.2, "Disagree": 3.4, "Strongly Disagree": 0.8 }, { "group": "Gender", "type": "Female", "total": 200, "Strongly Agree": 51.0, "Agree": 39.0, "No Opinion": 6.0, "Disagree": 3.5, "Strongly Disagree": 0.5 }]; var dv = new DataView(); dv.source(data).transform({ type: 'map', callback: function callback(row) { row['Strongly Disagree'] *= -1; row['Disagree'] *= -1; return row; } }).transform({ type: 'fold', fields: ['Disagree', 'Strongly Disagree', 'No Opinion', 'Agree', 'Strongly Agree'], key: 'opinion', value: 'value', retains: ['group', 'type'] }); var colorMap = { "Strongly Agree": '#3561A7', "Agree": '#80B2D3', "No Opinion": '#D9F0F6', "Disagree": '#EC7743', "Strongly Disagree": '#CB2920' }; var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight, padding: 'auto' }); chart.source(dv); chart.axis('type', { title: null, labelOffset: 10 }); chart.axis('value', { position: 'right', title: null, tickLine: null, formatter: function formatter(val) { return val + '%'; } }); chart.coord().transpose(); chart.intervalStack().position('type*value').color('opinion', function(opinion) { return colorMap[opinion]; }); 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>条形图-diverging</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>G2.Global.setTheme('dark');</script> <script> var _DataSet = DataSet, DataView = _DataSet.DataView; var data = [{ "group": "All Survey Responses", "type": "All Survey Responses", "total": 565, "Strongly Agree": 50.1, "Agree": 40.7, "No Opinion": 4.8, "Disagree": 3.7, "Strongly Disagree": 0.7 }, { "group": "Employment sector", "type": "Academic(nonstudent)", "total": 253, "Strongly Agree": 64.0, "Agree": 30.8, "No Opinion": 3.2, "Disagree": 2.0, "Strongly Disagree": 0.0 }, { "group": "Employment sector", "type": "Business and industry", "total": 176, "Strongly Agree": 40.6, "Agree": 50.0, "No Opinion": 2.8, "Disagree": 6.3, "Strongly Disagree": 0.0 }, { "group": "Employment sector", "type": "Federal, state, and local government", "total": 71, "Strongly Agree": 38.0, "Agree": 47.9, "No Opinion": 7.0, "Disagree": 4.2, "Strongly Disagree": 2.8 }, { "group": "Employment sector", "type": "Private consultant/self-employed", "total": 28, "Strongly Agree": 39.3, "Agree": 53.6, "No Opinion": 7.1, "Disagree": 0.0, "Strongly Disagree": 0.0 }, { "group": "Employment sector", "type": "Other", "total": 34, "Strongly Agree": 29.4, "Agree": 44.1, "No Opinion": 14.7, "Disagree": 5.9, "Strongly Disagree": 5.9 }, { "group": "Race", "type": "White", "total": 400, "Strongly Agree": 50.0, "Agree": 41.8, "No Opinion": 4.5, "Disagree": 2.8, "Strongly Disagree": 1.0 }, { "group": "Race", "type": "Asian", "total": 122, "Strongly Agree": 53.3, "Agree": 40.2, "No Opinion": 3.3, "Disagree": 3.3, "Strongly Disagree": 0.0 }, { "group": "Race", "type": "Black or African American", "total": 10, "Strongly Agree": 40.0, "Agree": 30.0, "No Opinion": 20.0, "Disagree": 10.0, "Strongly Disagree": 0.0 }, { "group": "Race", "type": "Other", "total": 17, "Strongly Agree": 47.1, "Agree": 35.3, "No Opinion": 5.9, "Disagree": 11.8, "Strongly Disagree": 0.7 }, { "group": "Education", "type": "Associate's and Bachelor's", "total": 175, "Strongly Agree": 37.1, "Agree": 49.1, "No Opinion": 5.7, "Disagree": 6.9, "Strongly Disagree": 1.1 }, { "group": "Education", "type": "Master's and Above", "total": 388, "Strongly Agree": 55.9, "Agree": 36.9, "No Opinion": 4.4, "Disagree": 2.3, "Strongly Disagree": 0.5 }, { "group": "Gender", "type": "Male", "total": 356, "Strongly Agree": 50.6, "Agree": 41, "No Opinion": 4.2, "Disagree": 3.4, "Strongly Disagree": 0.8 }, { "group": "Gender", "type": "Female", "total": 200, "Strongly Agree": 51.0, "Agree": 39.0, "No Opinion": 6.0, "Disagree": 3.5, "Strongly Disagree": 0.5 }]; var dv = new DataView(); dv.source(data).transform({ type: 'map', callback: function callback(row) { row['Strongly Disagree'] *= -1; row['Disagree'] *= -1; return row; } }).transform({ type: 'fold', fields: ['Disagree', 'Strongly Disagree', 'No Opinion', 'Agree', 'Strongly Agree'], key: 'opinion', value: 'value', retains: ['group', 'type'] }); var colorMap = { "Strongly Agree": '#3561A7', "Agree": '#80B2D3', "No Opinion": '#D9F0F6', "Disagree": '#EC7743', "Strongly Disagree": '#CB2920' }; var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight, padding: 'auto' }); chart.source(dv); chart.axis('type', { title: null, labelOffset: 10 }); chart.axis('value', { position: 'right', title: null, tickLine: null, formatter: function formatter(val) { return val + '%'; } }); chart.coord().transpose(); chart.intervalStack().position('type*value').color('opinion', function(opinion) { return colorMap[opinion]; }); chart.render(); </script> </body> </html>
图表简介
柱状图,对称层叠
了解更多
图表用法
两个方向上对柱状图进行层叠
相关链接
BizCharts
Viser