網站首頁 編程語言 正文
這里繪制的柱形圖是由雙折線圖的差值獲得的,下面的代碼可直接復制。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>柱狀-折線(柱形的數據由折線差值得到)</title>
</head>
<body>
<div id="container"></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>
const data1 = [
{
month: '12/07',
type: '貨幣需求',
value: 45
},
{
month: '13/07',
type: '貨幣需求',
value: 39
},
{
month: '14/07',
type: '貨幣需求',
value: 40
}
]
const data2 = [
{
month: '12/07',
type: '貨幣供給',
value: 33
},
{
month: '13/07',
type: '貨幣供給',
value: 53
},
{
month: '14/07',
type: '貨幣供給',
value: 32
}
]
//折線差的數組
const gaps = []
//當前所有數字的數組
const nums = []
const data3 = data1.map((item, index) => {
const gap = item.value - data2[index].value
gaps.push(gap)
nums.push(item.value)
nums.push(data2[index].value)
return {
month: item.month,
value: gap,
type: '貨幣缺口'
}
})
const data4 = [...data1, ...data2]
console.log(data4, data3)
const chart = new G2.Chart({
container: 'container',
width: 300,
height: 180,
padding: 'auto'
})
chart.scale('value', {
min: Math.min(...gaps) - 1,
max: Math.max(...nums) + 1
})
const view3 = chart.view()
view3.source(data3)
view3
.interval()
.position('month*value')
.color('month', ['l(270) 0:#007bc7 1:#00dffd']) //柱形圖漸變
const view4 = chart.view()
view4.source(data4)
view4
.line()
.position('month*value')
.color('type', ['#FFA900', '#FE5264'])
.shape('smooth')
view4.axis('month', false)
view4.axis('value', false)
//自定義legend
chart.legend({
custom: true,
clickable: false,
textStyle: {
fill: '#9bb7ef'
},
items: [
{
value: '貨幣缺口',
marker: {
symbol: 'square',
fill: '#3bf',
radius: 5,
lineWidth: 5
}
},
{
value: '貨幣需求',
marker: {
symbol: 'hyphen',
fill: '#FFA900',
stroke: '#FFA900',
radius: 5
}
},
{
value: '貨幣供給',
marker: {
symbol: 'hyphen',
fill: '#FE5264',
stroke: '#FE5264',
radius: 5
}
}
]
})
chart.tooltip(false)
chart.render()
</script>
</body>
</html>
原文鏈接:https://blog.csdn.net/weixin_44471622/article/details/105429047
相關推薦
- 2023-01-27 Python異常與錯誤處理詳細講解_python
- 2022-05-15 jQuery中的常用事件介紹_jquery
- 2022-10-28 Go語言開發保證并發安全實例詳解_Golang
- 2022-04-01 k8s使用docker作為運行時卡死解決辦法
- 2022-07-02 Python?matplotlib繪圖時使用鼠標滾輪放大/縮小圖像_python
- 2022-12-07 C++?兩個vector對象拼接方式_C 語言
- 2021-12-10 Android實現socket通信統一接口的方法_Android
- 2022-04-09 MFC模擬實現自定義消息發送_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支