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 Colors not properly set #3809

Closed
1 task
PrashantKT opened this issue Jan 7, 2019 · 2 comments
Closed
1 task

PIE Chart Colors not properly set #3809

PrashantKT opened this issue Jan 7, 2019 · 2 comments

Comments

@PrashantKT
Copy link

PrashantKT commented Jan 7, 2019

ℹ Please fill out this template when filing an issue.
All lines beginning with an ℹ symbol instruct you with what info we expect. You can delete those lines once you've filled in the info.

Per our *CONTRIBUTING guidelines, we use GitHub for
bugs and feature requests, not general support. Other issues should be opened on Stack Overflow with the tag ios-charts.

Please remove this line and everything above it before submitting.

What did you do?

I have tableview and in cell There is pie chart.

I am showing data of quarters so it will be 4 Maximum pie slices and 1 min.

I have provided 4 Colors to pie chart but both charts picking colors in different order

`class PieChartCell: UITableViewCell {

@IBOutlet weak var chartView: PieChartView!

var data:[PieGraphData]? {
    didSet {
        setData()
    }
}

override func awakeFromNib() {
    super.awakeFromNib()
    self.chartView.holeColor = Constants.AppTheme.Colors.ColorsOfApp.Light_Black.color
    self.chartView.holeRadiusPercent = 0.35
    self.chartView.legend.enabled = false
    self.chartView.rotationEnabled = false
    self.chartView.drawHoleEnabled = true
    self.chartView.drawSlicesUnderHoleEnabled = true
    self.chartView.transparentCircleColor = UIColor.white
    self.chartView.transparentCircleRadiusPercent = 0.40
    self.chartView.setExtraOffsets(left: 5, top: 0, right: 5, bottom: 0)
  //  setData()
    
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

func setData () {
    
    guard let dataChartQuterly = self.data else {
        chartView.data = nil
        return
    }
    
    var arrayDataEntery = [PieChartDataEntry]()
    for data in dataChartQuterly {
        let entry = PieChartDataEntry(value: data.value, label:data.title)
        
        arrayDataEntery.append(entry)
    }
    let totalAmount = arrayDataEntery.map{$0.value}.reduce(0,+)
    let formatedCurr = totalAmount > 0 ?  AppGlobalManager.shared.getFormmatedCurr(actualAmount: totalAmount) : "-"
    
    let attributes = [NSAttributedString.Key.font : Constants.AppTheme.Fonts.font(type: .Bold, size: 12),
                      NSAttributedString.Key.foregroundColor : UIColor.white]
    self.chartView.centerAttributedText = NSAttributedString(string: formatedCurr, attributes: attributes)

    // HERE COLORS ARE NOT SAME IN PIE Chart
    let set = PieChartDataSet(values: arrayDataEntery, label: nil)
    set.sliceSpace = 8
    set.setColors(Constants.AppTheme.Colors.ColorsOfApp.Purpule.color,
                  Constants.AppTheme.Colors.ColorsOfApp.Sky_blue.color,
                  Constants.AppTheme.Colors.ColorsOfApp.Blue_Mix.color,
                  Constants.AppTheme.Colors.ColorsOfApp.Yellow.color)

    set.valueLinePart1OffsetPercentage = 0.8
    set.valueLinePart1Length = 0.5
    
    set.valueLinePart2Length = 0.5
    //set.xValuePosition = .outsideSlice
    set.yValuePosition = .outsideSlice
    
    
    let data = PieChartData(dataSet: set)
    
 
   let formmater =  DefaultValueFormatter { (value, entry, someInt, handler) -> String in
        return AppGlobalManager.shared.getFormmatedCurr(actualAmount: value)

    }
    data.setValueFormatter(formmater)
 //   data.setValueFormatter(DefaultValueFormatter(formatter: pFormatter))
    data.setValueFont(Constants.AppTheme.Fonts.font(type: .Medium, size: 12))
    data.setValueTextColor(.black)
    
    
    
    chartView.data = data
    chartView.highlightValues(nil)

}

}

Here is colors

    struct Colors {
         enum ColorsOfApp:String {
            case Blue_Mix           = "#60E6CE"
            case Dark_Black         = "#272727"
            case Dark_White         = "#E5E7E6"
            case Light_Black        = "#3C464F"
            case Purpule            = "#878BEF"
            case Sky_blue           = "#5CE2FF"
            case Light_White        = "#F6F6F6"
            case Yellow             = "#FFB842"
            
            var color:UIColor {
                return UIColor(hexFromString: self.rawValue)
            }
        }
       
    }

`
simulator screen shot - iphone 8 - 2019-01-07 at 15 14 14

What did you expect to happen?

I was expecting that both charts has same colors

What happened instead?

Both charts has different colors

Charts Environment

I am using swift 4.2
XCODE 10:
Swift 4.2:
IOS 12
macOS version 10.14.1

Demo Project

ℹ Please link to or upload a project we can download that reproduces the issue.

@PrashantKT
Copy link
Author

I think I found the issue.

Because of Data is not sorted in Q1,Q2,Q3,Q4

@liuxuan30
Copy link
Member

please refer charts demo pie chart.

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