gpt4 book ai didi

swift - 将图例文本添加到饼图 Swift Charts

转载 作者:行者123 更新时间:2023-11-30 11:35:09 25 4
gpt4 key购买 nike

我正在尝试向我的图表添加图例,但它的颜色仅在没有文本的情况下出现。我不明白这是为什么?为了创建我的图表,我使用:

func configure (dataPoints: [String], values: [Double]) {
chartIMG.noDataText = "Please Insert Some Data!"

var dataEntries: [ChartDataEntry] = []

for i in 0..<dataPoints.count {
let dataEntry = ChartDataEntry(x: values[i], y: Double(i))
dataEntries.append(dataEntry)


}



let pieChartDataSet = PieChartDataSet(values: dataEntries, label: "Symptoms")
let pieChartData = PieChartData(dataSet: pieChartDataSet)
chartIMG.data = pieChartData

let noZeroFormatter = NumberFormatter()
noZeroFormatter.zeroSymbol = ""
pieChartDataSet.valueFormatter = DefaultValueFormatter(formatter: noZeroFormatter)

var colors: [UIColor] = []

for i in 0..<dataPoints.count {
let red = Double(arc4random_uniform(256))
let green = Double(arc4random_uniform(256))
let blue = Double(arc4random_uniform(256))

let color = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 1)
colors.append(color)
}


chartIMG.highlightPerTapEnabled = false
chartIMG.usePercentValuesEnabled = false
chartIMG.drawEntryLabelsEnabled = true
chartIMG.centerText = "%"


let legend = chartIMG.legend
legend.font = UIFont(name: "Arial", size: 11)!
legend.textColor = UIColor.black
legend.form = .circle

chartIMG.animate(xAxisDuration: 2, yAxisDuration: 2)

pieChartDataSet.colors = colors
pieChartDataSet.selectionShift = 0
pieChartDataSet.sliceSpace = 2.5


}

我正在尝试实现类似的目标:/image/eiSnN.png但似乎无法让图例与标签一起显示。知道这是为什么吗?我认为这可能是一行简单的代码,但我似乎找不到任何有用的东西。

最佳答案

如果有人寻求此帮助,请简单回答:

 let dataEntry1 = PieChartDataEntry(value: Double(i), label: dataPoints[i], data:  dataPoints[i] as AnyObject)

在这里回答:https://stackoverflow.com/a/42234117/9397533

关于swift - 将图例文本添加到饼图 Swift Charts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49844280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com