0

我正在尝试在我的图表中添加一个图例,但它唯一的颜色是没有文字出现的。我想不通这是为什么?要创建我的图表,我使用:

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


}

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

4

1 回答 1

0

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

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

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

于 2018-04-25T22:03:03.173 回答