網站首頁 編程語言 正文
有時候我們會遇到x軸標簽過于長的情況,會導致顯示不全
示例代碼
option: {
xAxis: {
type: 'category',
data: ['長長的標簽', '長長長的標簽', '長長長長長的標簽', '長的標簽', '長長長長的標簽', '長長長的標簽', '長長長長長長的標簽']
},
yAxis: {
type: 'value'
},
series: [
{
type: 'bar',
data: [80, 67, 42, 58, 40, 30, 56]
}
]
}
方案1:文字旋轉45°
xAxis: {
type: 'category',
data: ['長長的標簽', '長長長的標簽', '長長長長長的標簽', '長的標簽', '長長長長的標簽', '長長長的標簽', '長長長長長長的標簽'],
axisLabel: {
// 旋轉角度
rotate: 45
}
}
方案2:文字換行
xAxis: {
type: 'category',
data: ['長長的標簽', '長長長的標簽', '長長長長長的標簽', '長的標簽', '長長長長的標簽', '長長長的標簽', '長長長長長長的標簽'],
axisLabel: {
formatter: val => {
// 一行字數
const max = 4
// 標簽長度
const valLength = val.length
// 換行數
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
- 上一篇:Scss 遍歷之批量設置樣式
- 下一篇:小程序自定義日期組件,不顯示今日之后的日期
相關推薦
- 2022-07-24 Android?Studio工程導入及坑的解決_Android
- 2023-01-09 python數據分析之如何刪除value=0的行_python
- 2022-06-11 MSSQL基本語法及實例操作語句_MsSql
- 2022-04-20 C語言數據結構與算法之時間空間復雜度入門_C 語言
- 2022-05-20 nginx刷新頁面出現404解決方案(親測有效)_nginx
- 2022-12-11 C語言執行時,程序控制臺輸出窗口?一閃而過問題及解決_C 語言
- 2022-12-06 靜態pod?創建使用示例詳解_docker
- 2023-11-20 python獲取當前路徑所有文件
- 最近更新
-
- 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同步修改后的遠程分支