Reputation: 2139
I am not getting all the labels to show when doing a legend for a Pie Chart.
here is the code;
func AllocationsChart( pieChart: PieChartView ) {
let entry1 = PieChartDataEntry(value: 65, label: "Stock")
let entry2 = PieChartDataEntry(value: 35, label: "Bond")
let dataSet = PieChartDataSet(entries: [entry1, entry2 ] , label: "Allocation" )
let data = PieChartData(dataSet: dataSet)
pieChart.data = data
let labels = ["Stock","Bonds"] // would like to set the label here
let colors = [ Color.stock, Color.bond ]
dataSet.colors = colors
dataSet.sliceSpace = 2
pieChart.drawHoleEnabled = true
pieChart.transparentCircleColor = .white
pieChart.holeRadiusPercent = 0.6667
let l = pieChart.legend
l.enabled = true
l.orientation = .vertical
l.form = .circle
}
and here is the results.
Is there anyway to set the labels like we can do with other charts views like this:
xAxis.valueFormatter = IndexAxisValueFormatter(values: labels)
First, why is the bond entry not showing?
Also the color for the legend label does not match entry.
Thank you very much.
Upvotes: 0
Views: 1060
Reputation: 3433
Change the label statement to label: "nil" and see what it displays.
Upvotes: 0
Reputation: 2139
it was a matter of adding this line of code to the end:
pieChart.notifyDataSetChanged()
still no idea how to set the labels other than the PieChartDataEntry label?
good luck.
Upvotes: 0