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

Issue with coloring grouped datasets in barchart #1050

Closed
yigitserin opened this issue May 18, 2016 · 1 comment
Closed

Issue with coloring grouped datasets in barchart #1050

yigitserin opened this issue May 18, 2016 · 1 comment

Comments

@yigitserin
Copy link

yigitserin commented May 18, 2016

Hi there,

I want to create the same chart as the example image you provided here :
BarChart (grouped DataSets)

I managed to create the same grouping, but when I add color sets, it doesn't work like this.

Here is my attempt:

Code:
`

           var xVals = [String]()
            var datasets = [BarChartDataSet]()

            for i in 0..<json.count{

                var entries = [BarChartDataEntry]()

                for j in 0..<json[i]["Items"].count{

                    if i == 0{
                        xVals.append(json[i]["Items"][j]["X"].string!)
                    }

                    let entry = BarChartDataEntry(value: json[i]["Items"][j]["Value"].double!, xIndex: j)
                    entries.append(entry)

                }

                let dataset = BarChartDataSet(yVals: entries, label: json[i]["Name"].string)
                dataset.setColors(ChartColorTemplates.pastel(), alpha: 100)
                datasets.append(dataset)

            }


            let data = BarChartData(xVals: xVals, dataSets: datasets)

            barChart.data = data`

How do I color by type rather than group?

@yigitserin
Copy link
Author

Solved by using
dataset.setColor(ChartColorTemplates.pastel()[i])
instead of
dataset.setColors(ChartColorTemplates.pastel(), alpha: 100)

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

1 participant