網(wǎng)站首頁 編程語言 正文
有時候我們會遇到x軸標簽過于長的情況,會導(dǎo)致顯示不全
示例代碼
option: {
xAxis: {
type: 'category',
data: ['長長的標簽', '長長長的標簽', '長長長長長的標簽', '長的標簽', '長長長長的標簽', '長長長的標簽', '長長長長長長的標簽']
},
yAxis: {
type: 'value'
},
series: [
{
type: 'bar',
data: [80, 67, 42, 58, 40, 30, 56]
}
]
}
方案1:文字旋轉(zhuǎn)45°
xAxis: {
type: 'category',
data: ['長長的標簽', '長長長的標簽', '長長長長長的標簽', '長的標簽', '長長長長的標簽', '長長長的標簽', '長長長長長長的標簽'],
axisLabel: {
// 旋轉(zhuǎn)角度
rotate: 45
}
}
方案2:文字換行
xAxis: {
type: 'category',
data: ['長長的標簽', '長長長的標簽', '長長長長長的標簽', '長的標簽', '長長長長的標簽', '長長長的標簽', '長長長長長長的標簽'],
axisLabel: {
formatter: val => {
// 一行字數(shù)
const max = 4
// 標簽長度
const valLength = val.length
// 換行數(shù)
const rowNum = valLength / 4
if (valLength > 1) {
let target = ''
for (let i = 0; i < rowNum; i++) {
const start = i * max
const end = start + max
target += val.substring(start, end) + '\n'
}
return target
} else {
return val
}
}
}
}
方案3:在柱條中顯示
xAxis: {
show: false, // 隱藏x軸標簽
type: 'category',
data: ['長長的標簽', '長長長的標簽', '長長長長長的標簽', '長的標簽', '長長長長的標簽', '長長長的標簽', '長長長長長長的標簽']
}
series: [
{
type: 'bar',
data: [80, 67, 42, 58, 40, 10, 56],
label: {
// 顯示label代替x軸標簽
show: true,
position: 'insideBottom',
formatter: params => {
return params['name'].split('').join('\n')
}
}
}
]
原文鏈接:https://blog.csdn.net/z291493823/article/details/124609377
相關(guān)推薦
- 2022-10-28 ReactDOM?隱藏特性詳解_React
- 2022-02-09 linux下源碼包安裝的服務(wù)管理_Linux
- 2022-10-22 Go語言數(shù)據(jù)結(jié)構(gòu)之單鏈表的實例詳解_Golang
- 2022-02-27 uniapp swiper內(nèi)有點擊事件時會觸發(fā) swiper的animationfinish事件
- 2022-05-01 C語言實現(xiàn)學(xué)籍管理系統(tǒng)_C 語言
- 2022-06-21 C++超詳細講解友元的使用_C 語言
- 2022-04-05 python中時間轉(zhuǎn)換錯誤:時間戳轉(zhuǎn)換|帶有時區(qū)的轉(zhuǎn)換 如何解析ISO 8601格式的日期?
- 2022-05-17 EdgeX 設(shè)備服務(wù)與core-data、core-command的交互
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支