Swift 图例是否限制了标题的数量?

Swift 图例是否限制了标题的数量?,swift,ios-charts,Swift,Ios Charts,我正在使用iso图表尝试在iOS应用程序中绘制饼图 无论我尝试什么,我似乎都无法在传奇中获得完整数量的头衔 我的数据设置为: ages = ["18-", "25-", "35-", "45-", "55-", "65-", "75+"] agePercentages = [10.0, 20.0, 30.0, 5.0, 10.0, 45.0, 120.0] 将pieChart设置为的我的代码: func setPieDefaults(myPieChart: PieChartView) ->

我正在使用iso图表尝试在iOS应用程序中绘制饼图

无论我尝试什么,我似乎都无法在传奇中获得完整数量的头衔

我的数据设置为:

ages = ["18-", "25-", "35-", "45-", "55-", "65-", "75+"]
agePercentages = [10.0, 20.0, 30.0, 5.0, 10.0, 45.0, 120.0]
将pieChart设置为的我的代码:

func setPieDefaults(myPieChart: PieChartView) -> PieChartView {

    myPieChart.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.width*0.5)
    myPieChart.usePercentValuesEnabled = true
    myPieChart.holeTransparent = true
    myPieChart.holeColor = UIColor.darkPurpleColor()
    myPieChart.backgroundColor = UIColor.darkPurpleColor()
    myPieChart.rotationAngle = 0.0
    myPieChart.rotationEnabled = true
    myPieChart.centerTextFont = UIFont(name: "HelveticaNeue-Bold", size:20)!
    myPieChart.descriptionText = ""
    myPieChart.centerText = "%"
    myPieChart.centerTextColor = UIColor.whiteColor()
    myPieChart.drawHoleEnabled = true
    myPieChart.noDataText = "Loading Data ..."
    let legend = myPieChart.legend
    legend.font = UIFont(name: "Arial", size: 11)!
    legend.textColor = UIColor.whiteColor()
    legend.position = .RightOfChart
    legend.form = .Circle

    return myPieChart
}

func setChart(dataPoints: [String], values: [Double], myPieView: PieChartView) {

    var dataEntries: [ChartDataEntry] = []

    for i in 0..<dataPoints.count {
        let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
        dataEntries.append(dataEntry)
    }

    var colors = [UIColor]()
    switch myPieView {
    case genderPieChartView:
        colors = [UIColor.blueColor(), UIColor.pinkColor()]
    default:
        colors = ChartColorTemplates.colorful()
    }

    let pieChartDataSet = PieChartDataSet(yVals: dataEntries, label: nil)
    pieChartDataSet.sliceSpace = 3.0
    pieChartDataSet.colors = colors

    let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
    myPieView.animate(xAxisDuration: 2, yAxisDuration: 2)

    let pFormatter = NSNumberFormatter()
    pFormatter.numberStyle = .PercentStyle
    pFormatter.maximumFractionDigits = 0
    pFormatter.percentSymbol = ""
    pFormatter.multiplier = 1
    pieChartData.setValueFormatter(pFormatter)
    pieChartData.setValueFont(UIFont(name: "HelveticaNeue-Bold", size: 11)!)
    pieChartData.setValueTextColor(UIColor.whiteColor())

    myPieView.data = pieChartData
    myPieView.drawSliceTextEnabled = false

}
func集合图表(数据点:[字符串],值:[双精度],myPieView:PieChartView){
变量数据项:[ChartDataEntry]=[]
对于0..中的i,已解决

在阅读Android版本的详细信息时:

自动生成的图例包含的条目数 取决于不同颜色的数量(跨所有数据集对象) 以及数据集标签。图例的标签取决于 为图表中使用的数据集对象设置的标签。如果没有标签 对于已指定的数据集对象,图表将 自动生成。如果一种颜色使用多种颜色 数据集中,这些颜色被分组并仅由一个标签描述

我意识到我需要增加ChartColorTemplate.color()定义中的颜色数量,以匹配我尝试使用的标签数量。当前示例代码仅定义了5种颜色

public class func colorful () -> [UIColor]
{
    return [
        UIColor(red: 193/255.0, green: 37/255.0, blue: 82/255.0, alpha: 1.0),
        UIColor(red: 255/255.0, green: 102/255.0, blue: 0/255.0, alpha: 1.0),
        UIColor(red: 245/255.0, green: 199/255.0, blue: 0/255.0, alpha: 1.0),
        UIColor(red: 106/255.0, green: 150/255.0, blue: 31/255.0, alpha: 1.0),
        UIColor(red: 179/255.0, green: 100/255.0, blue: 53/255.0, alpha: 1.0),
        UIColor(red: 200/255.0, green: 100/255.0, blue: 53/255.0, alpha: 1.0), // added colour
        UIColor(red: 150/255.0, green: 150/255.0, blue: 70/255.0, alpha: 1.0), // added colour
        UIColor(red: 84/255.0, green: 78/255.0, blue: 53/255.0, alpha: 1.0), // added colour
    ]
}
如果你有同样的问题,那么定义更多的颜色以满足所需标签的最大数量。如果你尝试用文字包装图例(我也面临着这个问题),这也将解决一个问题