Search code examples
iosswiftcolorsmpandroidchartios-charts

How can i set each color of a pie Chart in iOS Charts separately with Swift?


i am working on an iOS App to create a pie Chart with Swift in Xcode. I added the iOS Charts Framework.

How can i set each color of a pie chart separately with iOSCharts and Swift??

I did not found something in the MPAndroid Charts Wiki Page. Only how to set the color of a dataset as a whole. But i want to set each color of a value of the Array separately on my own, if possible.

By the Way, i followed the Steps in this Tutorial: http://www.appcoda.com/ios-charts-api-tutorial/

So, Thanks in Advance.


Solution

  • So after some trial and error, now i found a "workaround" to set a color separately.

    self.pieChartView.data?.getDataSetByIndex(0).colors[3] = UIColor.orangeColor()
    

    This will set the third value in the piechart to orange. Maybe not the best solution, but it works.