gpt4 book ai didi

ios-charts 缺少 PieChart 的标签(图例)

转载 作者:可可西里 更新时间:2023-11-01 05:20:03 26 4
gpt4 key购买 nike

我正在尝试从 ios-charts 库中实现饼图一切正常,但是我缺少图表中的图例 -

enter image description here

这是我的代码 -

// This is the delegate method for creating data for chart
func offDaysDidLoaded(controller: DataModel,chartArray:[PFObject]) {


let formatter = NSDateFormatter()
formatter.dateFormat = "MMM"
dataDict = [:]
for od in chartArray {
let date = od["Date"] as! NSDate
let month = formatter.stringFromDate(date)
if self.dateDict.indexForKey(month) != nil {
self.dateDict[month]! += 1.0
}else{
self.dateDict.updateValue(1.0, forKey: month)
}
}
let dataPointArray = Array(dateDict.keys)
let valuesArray = Array(dateDict.values)
pieChartView.data = nil
pieChartView.backgroundColor = UIColor.grayColor()
setChart(dataPointArray, values: valuesArray)
}


func setChart(dataPoints: [String], values: [Double]) {
var dataEntries: [ChartDataEntry] = []
for i in 0..<dataPoints.count {

let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
dataEntries.append(dataEntry)
}

let pieChartDataSet = PieChartDataSet(yVals: dataEntries, label: "Months")

let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
pieChartData.setDrawValues(false)
pieChartView.data = pieChartData
pieChartView.animate(xAxisDuration: NSTimeInterval(5))

var colors: [UIColor] = []

for _ 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)
}

pieChartDataSet.colors = colors

}

我在 here 中看到过类似的问题并构建并运行,问题中使用的饼图也没有在图表下方显示任何图例。任何帮助或指针将不胜感激。

谢谢

最佳答案

这个问题终于解决了,不是bug。详细解决办法请找here .

关于ios-charts 缺少 PieChart 的标签(图例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33190074/

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