Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pie chart specific colors #1824

Closed
dnamna opened this issue Nov 11, 2016 · 2 comments
Closed

Pie chart specific colors #1824

dnamna opened this issue Nov 11, 2016 · 2 comments

Comments

@dnamna
Copy link

dnamna commented Nov 11, 2016

Hi,
First I would like to thank you for this amazing project.
I am trying to specify colors for pie charts.
I have 3 label x y z and I want to specify for x the red color and y the orange color and z the green color.
I am using Swift 3.0 but the pie charts is taking 2 colors only,it gives x and y red and z green.
Am using the below code:

var colors: [UIColor] = []
      let redcolor = UIColor(red: CGFloat(255/255), green: CGFloat(0/255), blue: CGFloat(0/255), alpha: 1)
      let greencolor = UIColor(red: CGFloat(0/255), green: CGFloat(128/255), blue: CGFloat(0/255), alpha: 1)
      let orangecolor = UIColor(red: CGFloat(255/255), green: CGFloat(140/255), blue: CGFloat(0/255),        alpha: 1)
      colors.append(redcolor)
      colors.append(orangecolor)
      colors.append(greencolor)
      var taskChartDataEntries: [ChartDataEntry] = []
      taskChartDataEntries.append(PieChartDataEntry(value: 10, label: "x"))
       taskChartDataEntries.append(PieChartDataEntry(value: 11, label: "y"))
       taskChartDataEntries.append(PieChartDataEntry(value: 1, label: "z"))
       let data = PieChartData()
       let ds1 = PieChartDataSet(values: taskChartDataEntries, label: "Status")     
       ds1.colors = colors
       ds1.colors = ChartColorTemplates.joyful();
       data.addDataSet(ds1)
@liuxuan30
Copy link
Member

liuxuan30 commented Nov 15, 2016

I don't understand "but the pie charts is taking 2 colors only", pie chart will render multiple colors for sure. Do check ChartsDemo for this kind of issues.

@dnamna
Copy link
Author

dnamna commented Nov 21, 2016

hey,
sorry setting the colors was wrong,it should be like that(adding .0 )

 let redcolor = UIColor(red: CGFloat(255.0/255), green: CGFloat(0/255), blue: CGFloat(0/255), alpha: 1)
      let greencolor = UIColor(red: CGFloat(0/255), green: CGFloat(128.0/255), blue: CGFloat(0/255), alpha: 1)
      let orangecolor = UIColor(red: CGFloat(255.0/255), green: CGFloat(140.0/255), blue: CGFloat(0/255),        alpha: 1)

Just in case someone faced the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants