Reputation: 336
I'm working with this library. I need to construct a PieChart do display some data. I copied and example peace of code from raywenderlich-website, so the question is that how can I set all labels from array "months" to below description labels (where now just "qwe" is shown) with the same colors as peaces OR how to remove them all?
Also it's impossible to change label "description" from right-below corner because it says me that "description is immutable"
@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
}
Upvotes: 0
Views: 3323
Reputation: 1514
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
Upvotes: 4