G2
G2
G6
F2
L7
墨者学院
关于 G2
图表示例
API 文档
使用教程
English
折线图
基础折线图
双折线图
多折线图
其他折线图
条形图
分组条形图
堆叠条形图
基础条形图
柱状图
基础柱状图
分组柱状图
堆叠柱状图
直方图
饼图
环图
玫瑰图
基础饼图
嵌套饼图
点图
散点图
面积图
基础面积图
堆叠面积图
区间面积图
箱形图
箱型图
烛形图
烛形图
热力图
热力图
仪表盘
仪表盘
漏斗图
漏斗图
地图
地图
雷达图
雷达图
分面
分面
关系图
关系图
其他图表
其他
迷你图
组件使用
组件
组件
guide - 分段颜色2
通过regionFilter legend的apply配置项,可以选择针对某一种/几种geom进行区域着色
源码
复制成功
复制失败
全屏
复制
运行
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,height=device-height"> <title>guide - 分段颜色2</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> <script> var data = [{ year: 1700, exports: 35, imports: 70 }, { year: 1710, exports: 59, imports: 81 }, { year: 1720, exports: 76, imports: 96 }, { year: 1730, exports: 65, imports: 97 }, { year: 1740, exports: 67, imports: 93 }, { year: 1750, exports: 79, imports: 90 }, { year: 1760, exports: 115, imports: 79 }, { year: 1770, exports: 163, imports: 85 }, { year: 1780, exports: 185, imports: 93 }]; var ds = new DataSet(); var dv = ds.createView().source(data); dv.transform({ type: 'map', callback: function callback(row) { row.range = [row.exports, row.imports]; return row; } }); dv.transform({ type: 'fold', fields: ['exports', 'imports'], // 展开字段集 key: 'type', // key字段 value: 'value' // value字段 }); var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight }); chart.source(dv, { value: { min: 0, max: 200 }, range: { min: 0, max: 200 } }); chart.axis('range', false); chart.legend({ attachLast: true }); chart.tooltip({ crosshairs: { type: 'line' } }); chart.line().position('year*value').color('type', ['#F5222D', '#FAAD14']).size(2.5).shape('smooth'); chart.area().position('year*range').color('#ffffff').shape('smooth').tooltip(false); chart.guide().regionFilter({ top: true, start: [1700, 'min'], end: [1753, 'max'], color: '#F5222D', apply: ['area'] }); chart.guide().regionFilter({ top: true, start: [1753, 'min'], end: [1780, 'max'], color: '#FAAD14', apply: ['area'] }); chart.guide().dataMarker({ position: [1753, 87], content: '1755 年在印度周边建立诸多殖民\n地与附属国,垄断出口贸易,导致\n出品总额激增。', lineLength: 50, style: { text: { textAlign: 'left', fontSize: 13 }, point: { stroke: '#FF4D4F' } }, direction: 'downward' }); chart.guide().text({ top: false, position: [1730, 80], content: '贸易赤字', style: { fontSize: 12, fontWeight: 'normal', fill: 'rgba(0,0,0,0.45)' } }); chart.guide().text({ top: false, position: [1765, 110], content: '贸易盈余', style: { fontSize: 12, fontWeight: 'normal', fill: 'rgba(0,0,0,0.45)' } }); 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>guide - 分段颜色2</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> <script> var data = [{ year: 1700, exports: 35, imports: 70 }, { year: 1710, exports: 59, imports: 81 }, { year: 1720, exports: 76, imports: 96 }, { year: 1730, exports: 65, imports: 97 }, { year: 1740, exports: 67, imports: 93 }, { year: 1750, exports: 79, imports: 90 }, { year: 1760, exports: 115, imports: 79 }, { year: 1770, exports: 163, imports: 85 }, { year: 1780, exports: 185, imports: 93 }]; var ds = new DataSet(); var dv = ds.createView().source(data); dv.transform({ type: 'map', callback: function callback(row) { row.range = [row.exports, row.imports]; return row; } }); dv.transform({ type: 'fold', fields: ['exports', 'imports'], // 展开字段集 key: 'type', // key字段 value: 'value' // value字段 }); var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight }); chart.source(dv, { value: { min: 0, max: 200 }, range: { min: 0, max: 200 } }); chart.axis('range', false); chart.legend({ attachLast: true }); chart.tooltip({ crosshairs: { type: 'line' } }); chart.line().position('year*value').color('type', ['#F5222D', '#FAAD14']).size(2.5).shape('smooth'); chart.area().position('year*range').color('#ffffff').shape('smooth').tooltip(false); chart.guide().regionFilter({ top: true, start: [1700, 'min'], end: [1753, 'max'], color: '#F5222D', apply: ['area'] }); chart.guide().regionFilter({ top: true, start: [1753, 'min'], end: [1780, 'max'], color: '#FAAD14', apply: ['area'] }); chart.guide().dataMarker({ position: [1753, 87], content: '1755 年在印度周边建立诸多殖民\n地与附属国,垄断出口贸易,导致\n出品总额激增。', lineLength: 50, style: { text: { textAlign: 'left', fontSize: 13 }, point: { stroke: '#FF4D4F' } }, direction: 'downward' }); chart.guide().text({ top: false, position: [1730, 80], content: '贸易赤字', style: { fontSize: 12, fontWeight: 'normal', fill: 'rgba(0,0,0,0.45)' } }); chart.guide().text({ top: false, position: [1765, 110], content: '贸易盈余', style: { fontSize: 12, fontWeight: 'normal', fill: 'rgba(0,0,0,0.45)' } }); chart.render(); </script> </body> </html>
图表简介
通过regionFilter legend的apply配置项,可以选择针对某一种/几种geom进行区域着色
图表用法
William Playfair经典案例重现,数据来源:The Commercial and Political Atlas《商业与政治图解集》(1786)
相关链接
BizCharts
Viser