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

Multiple colors issue in stacked bar line charts swift3 #1989

Closed
jiheneme opened this issue Dec 21, 2016 · 2 comments
Closed

Multiple colors issue in stacked bar line charts swift3 #1989

jiheneme opened this issue Dec 21, 2016 · 2 comments

Comments

@jiheneme
Copy link

Hi everyone,

I need to create a stacked bar chart with 3 dataSets like this :

capture d ecran 2016-12-21 a 10 53 42

But when I used this code :
********************** Begin ******************************
let chiffreAffaire = [3282.0, 4179.0]
let chiffreAffaireDetails1 = [788.0, 889.0]
let chiffreAffaireDetails2 = [300.0, 330.0]
let chiffreAffaireDetails3 = [2247.0, 1843.0]

    var yse1 = chiffreAffaireDetails1.enumerated().map { x, y in return BarChartDataEntry(x: Double(x), y: y) }
    var yse2 = chiffreAffaireDetails2.enumerated().map { x, y in return BarChartDataEntry(x: Double(x), y: y) }
    var yse3 = chiffreAffaireDetails3.enumerated().map { x, y in return BarChartDataEntry(x: Double(x), y: y) }
    var yse = chiffreAffaire.enumerated().map { x, y in return BarChartDataEntry(x: Double(x), y: y) }

    let data = BarChartData()
    let ds1 = BarChartDataSet(values: yse1, label: "")
    let ds2 = BarChartDataSet(values: yse2, label: "")
    let ds3 = BarChartDataSet(values: yse3, label: "")
    let ds4 = BarChartDataSet(values: yse, label: "")
    
    data.barWidth=0.6
    
    ds4.setColor (UIColor.detailsBtnGreen)
    ds4.valueFont=UIFont(name:"Avenir-Book" ,size:20.0)!
    data.addDataSet(ds4)
  
    ds2.setColor (UIColor.pistachioGreen)
    ds2.valueFont=UIFont(name:"Avenir-Book" ,size:20.0)!
    ds2.valueTextColor=UIColor.white
    data.addDataSet(ds2)
    
    ds1.setColor (UIColor.pinkBar)
    ds1.valueFont=UIFont(name:"Avenir-Book" ,size:20.0)!
    ds1.valueTextColor=UIColor.white
    data.addDataSet(ds1)
    
    ds3.setColor(UIColor.royalBlue)
    ds3.valueFont=UIFont(name:"Avenir-Book" ,size:20.0)!
    ds3.valueTextColor=UIColor.white
    data.addDataSet(ds3)

    self.barChartView.data = data

********************** End ******************************

I had this result :
capture d ecran 2016-12-21 a 10 53 59

The problem is that it takes only the first and the last dataSet colors !

Someone can help me please ?
Thanks in advance ( and sorry for my bad english ;-) )

@liuxuan30
Copy link
Member

Please check out ChartsDemo, there are full examples.. As far as I know from your picture, there should only be one data set with multiple entries.

@HPRaval
Copy link

HPRaval commented May 13, 2017

there is no example for swift 3. is there any?

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

3 participants