fix(图表): 修复部分图表图例无法修改文字大小的问题

This commit is contained in:
ulleo
2024-12-03 14:27:01 +08:00
parent c8d829dcd9
commit 7703d3b92e
3 changed files with 24 additions and 22 deletions

View File

@@ -318,15 +318,13 @@ export class BidirectionalHorizontalBar extends G2PlotChartView<
protected configLegend(chart: Chart, options: BidirectionalBarOptions): BidirectionalBarOptions {
const o = super.configLegend(chart, options)
if (o.legend) {
o.legend.itemName = {
formatter: (_text: string, _item: any, index: number) => {
const yaxis = chart.yAxis[0]
const yaxisExt = chart.yAxisExt[0]
if (index === 0) {
return yaxis.chartShowName ? yaxis.chartShowName : yaxis.name
}
return yaxisExt.chartShowName ? yaxisExt.chartShowName : yaxisExt.name
o.legend.itemName.formatter = (_text: string, _item: any, index: number) => {
const yaxis = chart.yAxis[0]
const yaxisExt = chart.yAxisExt[0]
if (index === 0) {
return yaxis.chartShowName ? yaxis.chartShowName : yaxis.name
}
return yaxisExt.chartShowName ? yaxisExt.chartShowName : yaxisExt.name
}
}
return o

View File

@@ -573,20 +573,18 @@ export class ColumnLineMix extends G2PlotChartView<DualAxesOptions, DualAxes> {
const left = cloneDeep(chart.data?.left?.data)
const right = cloneDeep(chart.data?.right?.data)
o.legend.itemName = {
formatter: (text: string, item: any, index: number) => {
let name = undefined
if (item.viewId === 'left-axes-view' && text === 'value') {
name = left[0]?.categories[0]
} else if (item.viewId === 'right-axes-view' && text === 'valueExt') {
name = right[0]?.categories[0]
}
item.id = item.id + '__' + index //防止重复的图例出现问题,但是左右轴如果有相同的怎么办
if (name === undefined) {
return text
} else {
return name
}
o.legend.itemName.formatter = (text: string, item: any, index: number) => {
let name = undefined
if (item.viewId === 'left-axes-view' && text === 'value') {
name = left[0]?.categories[0]
} else if (item.viewId === 'right-axes-view' && text === 'valueExt') {
name = right[0]?.categories[0]
}
item.id = item.id + '__' + index //防止重复的图例出现问题,但是左右轴如果有相同的怎么办
if (name === undefined) {
return text
} else {
return name
}
}

View File

@@ -360,6 +360,12 @@ export function getLegend(chart: Chart) {
r: l.size
}
},
itemName: {
style: {
fill: l.color,
fontSize: l.fontSize
}
},
itemHeight: (l.fontSize > l.size * 2 ? l.fontSize : l.size * 2) + 4,
radio: false,
pageNavigator: {