修改bug
This commit is contained in:
@@ -86,10 +86,49 @@ export default {
|
||||
normal: {
|
||||
align: 'left',
|
||||
distanceToLabelLine: 2,
|
||||
formatter: (params) => [
|
||||
`{b|${params.value.toLocaleString()}}`, // 数值(格式化千分位)
|
||||
`{hr|■}{c|${params.name}}` // 名称 + 颜色标识
|
||||
].join('\n'),
|
||||
formatter: (params) => {
|
||||
const wrapMixedText = (text, maxUnits = 9, maxLines = 2) => {
|
||||
if (!text) return ''
|
||||
let line = ''
|
||||
let units = 0
|
||||
const lines = []
|
||||
const charUnit = (ch) => {
|
||||
// 简单权重:中文/全角更“宽”
|
||||
if (/[\u4e00-\u9fa5]/.test(ch)) return 1
|
||||
if (/[A-Z]/.test(ch)) return 0.85
|
||||
if (/[a-z0-9]/.test(ch)) return 0.65
|
||||
if (/\s/.test(ch)) return 0.3
|
||||
return 0.8
|
||||
}
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const ch = text[i]
|
||||
const u = charUnit(ch)
|
||||
// 超过阈值就换行
|
||||
if (units + u > maxUnits && line) {
|
||||
lines.push(line)
|
||||
line = ch
|
||||
units = u
|
||||
if (lines.length >= maxLines) {
|
||||
// 还有剩余就省略
|
||||
const rest = text.slice(i + 1)
|
||||
if (rest) lines[maxLines - 1] = (lines[maxLines - 1] + '...').replace(/\.\.\.\.+$/, '...')
|
||||
return lines.join('\n')
|
||||
}
|
||||
} else {
|
||||
line += ch
|
||||
units += u
|
||||
}
|
||||
}
|
||||
if (line) lines.push(line)
|
||||
return lines.slice(0, maxLines).join('\n')
|
||||
}
|
||||
const nameWrapped = wrapMixedText(params.name, 6, 1)
|
||||
return [
|
||||
`{b|${Number(params.value || 0).toLocaleString()}}`,
|
||||
// 第2行放色块 + 名称第1行;如果名称有第2行,会自然变成第3行
|
||||
`{hr|■}{c|${nameWrapped}}`
|
||||
].join('\n')
|
||||
},
|
||||
rich: {
|
||||
hr: {
|
||||
color: color,
|
||||
@@ -112,8 +151,8 @@ export default {
|
||||
// 标签线样式(动态匹配颜色)
|
||||
labelLine: {
|
||||
lineStyle: { color: color },
|
||||
length: 10,
|
||||
length2: 20,
|
||||
length: 5,
|
||||
length2: 5,
|
||||
},
|
||||
// 扇区样式(动态匹配颜色)
|
||||
itemStyle: { color: color }
|
||||
@@ -129,7 +168,7 @@ export default {
|
||||
left: 'center',
|
||||
top: '35%',
|
||||
textStyle: {
|
||||
fontSize: 18,
|
||||
fontSize: 15,
|
||||
letterSpacing: 5,
|
||||
color: 'rgba(0, 0, 0, 0.55)',
|
||||
fontFamily: 'PingFangSC, PingFang SC'
|
||||
@@ -140,7 +179,7 @@ export default {
|
||||
left: 'center',
|
||||
top: '50%',
|
||||
textStyle: {
|
||||
fontSize: 16,
|
||||
fontSize: 14,
|
||||
color: 'rgba(0, 0, 0, 0.55)',
|
||||
fontFamily: 'PingFangSC, PingFang SC'
|
||||
}
|
||||
@@ -150,7 +189,7 @@ export default {
|
||||
{
|
||||
name: '销量',
|
||||
type: 'pie',
|
||||
radius: ['60%', '80%'],
|
||||
radius: ['50%', '70%'],
|
||||
center: ['50%', '50%'],
|
||||
avoidLabelOverlap: false,
|
||||
label: {
|
||||
@@ -167,8 +206,6 @@ export default {
|
||||
},
|
||||
labelLine: {
|
||||
show: true,
|
||||
length: 0,
|
||||
length2: 10,
|
||||
lineStyle: {
|
||||
// 若未单独配置标签线颜色,默认取对应数据项的颜色
|
||||
color: (params) => this.customColors[params.dataIndex % this.customColors.length]
|
||||
|
||||
Reference in New Issue
Block a user