G2
G2
G6
F2
L7
墨者学院
关于 G2
图表示例
API 文档
使用教程
English
折线图
基础折线图
双折线图
多折线图
其他折线图
条形图
分组条形图
堆叠条形图
基础条形图
柱状图
基础柱状图
分组柱状图
堆叠柱状图
直方图
饼图
环图
玫瑰图
基础饼图
嵌套饼图
点图
散点图
面积图
基础面积图
堆叠面积图
区间面积图
箱形图
箱型图
烛形图
烛形图
热力图
热力图
仪表盘
仪表盘
漏斗图
漏斗图
地图
地图
雷达图
雷达图
分面
分面
关系图
关系图
其他图表
其他
迷你图
组件使用
组件
基础折线图
某网站访问趋势
该网站每逢周末和小长假访问量立降,工作日访问量维持在1.4万左右,DAU (Daily Active User) 指日活跃用户数量。
源码
复制成功
复制失败
全屏
复制
运行
<!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> <script> $.getJSON('https://gw.alipayobjects.com/os/antvdemo/assets/data/basement.json', function(data) { var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight, padding: [20, 50, 50, 50] }); chart.axis('time', { label: { textStyle: { fill: '#aaaaaa' } } }); chart.axis('UV', { label: { textStyle: { fill: '#aaaaaa' } } }); chart.tooltip({ crosshairs: false }); chart.source(data, { time: { tickCount: 5 }, UV: { tickCount: 5 } }); chart.line().position('time*UV'); //guide var max_min = findMaxMin(); var max = max_min.max; var min = max_min.min; chart.guide().dataMarker({ top: true, content: '峰值:' + max.UV, position: [max.time, max.UV], style: { text: { fontSize: 13, stroke: 'white', lineWidth: 2 } }, lineLength: 30 }); chart.guide().dataMarker({ top: true, content: '谷值:' + min.UV, position: [min.time, min.UV], style: { text: { fontSize: 13, stroke: 'white', lineWidth: 2 } }, lineLength: 50 }); chart.guide().region({ start: ['2018-09-01', 'min'], end: ['2018-09-02', 'max'] }); chart.guide().region({ start: ['2018-09-08', 'min'], end: ['2018-09-09', 'max'] }); chart.guide().region({ start: ['2018-09-15', 'min'], end: ['2018-09-16', 'max'] }); chart.guide().region({ start: ['2018-09-22', 'min'], end: ['2018-09-24', 'max'] }); chart.render(); function findMaxMin() { var maxValue = 0; var minValue = 50000; var maxObj = null; var minObj = null; for (var i = 0; i < data.length; i++) { var d = data[i]; if (d.UV > maxValue) { maxValue = d.UV; maxObj = d; } if (d.UV < minValue) { minValue = d.UV; minObj = d; } } return { max: maxObj, min: minObj }; } }); </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> <script> $.getJSON('https://gw.alipayobjects.com/os/antvdemo/assets/data/basement.json', function(data) { var chart = new G2.Chart({ container: 'mountNode', forceFit: true, height: window.innerHeight, padding: [20, 50, 50, 50] }); chart.axis('time', { label: { textStyle: { fill: '#aaaaaa' } } }); chart.axis('UV', { label: { textStyle: { fill: '#aaaaaa' } } }); chart.tooltip({ crosshairs: false }); chart.source(data, { time: { tickCount: 5 }, UV: { tickCount: 5 } }); chart.line().position('time*UV'); //guide var max_min = findMaxMin(); var max = max_min.max; var min = max_min.min; chart.guide().dataMarker({ top: true, content: '峰值:' + max.UV, position: [max.time, max.UV], style: { text: { fontSize: 13, stroke: 'white', lineWidth: 2 } }, lineLength: 30 }); chart.guide().dataMarker({ top: true, content: '谷值:' + min.UV, position: [min.time, min.UV], style: { text: { fontSize: 13, stroke: 'white', lineWidth: 2 } }, lineLength: 50 }); chart.guide().region({ start: ['2018-09-01', 'min'], end: ['2018-09-02', 'max'] }); chart.guide().region({ start: ['2018-09-08', 'min'], end: ['2018-09-09', 'max'] }); chart.guide().region({ start: ['2018-09-15', 'min'], end: ['2018-09-16', 'max'] }); chart.guide().region({ start: ['2018-09-22', 'min'], end: ['2018-09-24', 'max'] }); chart.render(); function findMaxMin() { var maxValue = 0; var minValue = 50000; var maxObj = null; var minObj = null; for (var i = 0; i < data.length; i++) { var d = data[i]; if (d.UV > maxValue) { maxValue = d.UV; maxObj = d; } if (d.UV < minValue) { minValue = d.UV; minObj = d; } } return { max: maxObj, min: minObj }; } }); </script> </body> </html>
图表简介
该网站每逢周末和小长假访问量立降,工作日访问量维持在1.4万左右,DAU (Daily Active User) 指日活跃用户数量。
了解更多
图表用法
数据来源:Demo数据
相关链接
BizCharts
Viser