Formatting Custom Legend Entries in Chart's PieChartView?

时间:2019-01-15 18:24:03

标签: ios swift charts ios-charts

I'm having difficulty formatting my custom legend entries for my pieChartView. I need the legend entries to be different than those on the pie chart (why I need to customize). The below works but anything larger than size 6 text (which is too small) results in overlapping. How can I resize the legend to fit small text?

(Screenshot is with size 10 text)enter image description here

let l = self.pieChartView.legend

let formSize =  CGFloat.nan

let legendEntry1 = LegendEntry(label: zonesArrayOfString[0], form: .default, formSize: formSize, formLineWidth: .nan, formLineDashPhase: .nan, formLineDashLengths: .none, formColor: zone1Color)  //set formSize, formLizeWidth, and formLineDashLengths to .nan to use default
let legendEntry2 = LegendEntry(label: zonesArrayOfString[1], form: .default, formSize: formSize, formLineWidth: .nan, formLineDashPhase: .nan, formLineDashLengths: .none, formColor: zone2Color)
let legendEntry3 = LegendEntry(label: zonesArrayOfString[2], form: .default, formSize: formSize, formLineWidth: .nan, formLineDashPhase: .nan, formLineDashLengths: .none, formColor: zone3Color)
let legendEntry4 = LegendEntry(label: zonesArrayOfString[3], form: .default, formSize: formSize, formLineWidth: .nan, formLineDashPhase: .nan, formLineDashLengths: .none, formColor: zone4Color)
let legendEntry5 = LegendEntry(label: zonesArrayOfString[4], form: .default, formSize: formSize, formLineWidth: .nan, formLineDashPhase: .nan, formLineDashLengths: .none, formColor: zone5Color)

let customLegendEntries = [legendEntry1, legendEntry2, legendEntry3, legendEntry4, legendEntry5]
l.setCustom(entries: customLegendEntries)
l.orientation = .horizontal
l.textColor = UIColor.white
l.font = myFonts.openSansRegular.of(size: 6)

1 个答案:

答案 0 :(得分:0)

通过使用图例的xEntrySpace属性,我可以使外观更好看,尽管您可以操纵字体大小和表单大小,但您可以自定义图例中给定条目分配的空间能够获取所有格式正确的图例条目。