在ios-pieChart中设置description-labels

时间:2015-11-12 10:25:05

标签: ios xcode swift pie-chart ios-charts

我正在使用this库。我需要构建一个PieChart来显示一些数据。我从raywenderlich-website复制了示例代码和平,所以问题是我如何设置来自数组的所有标签" "以下描述标签(现在只显示" qwe "显示)与和平颜色相同或如何删除全部?

此外,无法更改标签" 说明"从右下角开始,因为它告诉我" 描述是不可改变的"

@IBOutlet weak var pieChartView: PieChartView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let months = ["qwe", "asd", "zxc"]
        let unitsSold = [20.0, 15.0, 17.0]

        pieChartView.noDataTextDescription = "nothing here"

        setChart(months, values: unitsSold)

    }

    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)

        let pieChartData = PieChartData(xVals: dataPoints, dataSet: pieChartDataSet)
        pieChartDataSet.label = ""
        pieChartView.data = pieChartData

        var colors: [UIColor] = []

         colors.append(UIColor.greenColor())
         colors.append(UIColor.blueColor())
         colors.append(UIColor.blackColor())

        pieChartDataSet.colors = colors





    }

1 个答案:

答案 0 :(得分:4)

In the library document, it says

By default, all chart types support legends and will automatically generate and draw a legend after setting data for the chart.

Edited

READ through the library please!

As shown in the demo of the library, you should be able to do

pieChartView.descriptionText = "";

For the legend, you should be able to set the legend by

let legend = pieCharView.legend
legend.setCustom(colors: [UIColor.greenColor(), UIColor.blueColor(), UIColor.blackColor()], labels: ["qwe", "asd", "zxc"])

or disable it by

legend.isEnabled = false