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 entries of the same item in legend #1042

Closed
yigitserin opened this issue May 16, 2016 · 2 comments
Closed

Multiple entries of the same item in legend #1042

yigitserin opened this issue May 16, 2016 · 2 comments

Comments

@yigitserin
Copy link

yigitserin commented May 16, 2016

Hey there,

Trying to implement a bar chart into my app. It works but there is an issue with legend. As you can see in the image, color boxes are shown for all items:

http://i.imgur.com/ZuVHpDC.png

However expected behaviour is as shown bellow:

http://i.imgur.com/cFivjDc.png

Why is that happening? My code is bellow:

`

            let barChart = BarChartView(frame: CGRectMake(0, 0, parent.frame.width, 400))
            let json = JSON(data: jsonString)

            var dataSets = [BarChartDataSet]()
            var xVals = [String]()
            for i in 0..<json.count{
                if let items = json[i]["Items"].array{

                    var yVals = [BarChartDataEntry]()

                    for j in 0..<items.count{

                        if i == 0{
                            xVals.append(items[j]["X"].string!)
                        }
                        yVals.append(BarChartDataEntry(value: items[j]["Value"].double!, xIndex: j))
                    }

                    let dataSet = BarChartDataSet(yVals: yVals, label: json[i]["Name"].string!)
                    dataSet.setColors(ChartColorTemplates.pastel(), alpha: 100)
                    dataSets.append(dataSet)
                }
            }
            let data = BarChartData(xVals: xVals, dataSets: dataSets)

            barChart.data = data

`

@yigitserin
Copy link
Author

And this is the json data if it is required:

[{"Name":"Ceviz","Items":[{"X":"2016-04-22","Value":16.32},{"X":"2016-04-21","Value":12.40},{"X":"2016-04-20","Value":0.00},{"X":"2016-04-19","Value":0.00},{"X":"2016-04-18","Value":0.00},{"X":"2016-04-16","Value":0.00},{"X":"2016-04-15","Value":0.00},{"X":"2016-04-14","Value":0.00},{"X":"2016-04-13","Value":0.00},{"X":"2016-04-11","Value":17.28},{"X":"2016-04-09","Value":0.00},{"X":"2016-04-08","Value":0.00},{"X":"2016-04-07","Value":16.10},{"X":"2016-04-06","Value":0.00},{"X":"2016-04-05","Value":31.30},{"X":"2016-04-04","Value":0.00},{"X":"2016-04-02","Value":31.46},{"X":"2016-04-01","Value":36.76},{"X":"2016-03-31","Value":13.68},{"X":"2016-03-30","Value":34.46},{"X":"2016-03-29","Value":28.90},{"X":"2016-03-28","Value":0.00},{"X":"2016-03-26","Value":31.98},{"X":"2016-03-25","Value":0.00},{"X":"2016-03-24","Value":0.00}]},{"Name":"Fındık","Items":[{"X":"2016-04-22","Value":0.00},{"X":"2016-04-21","Value":0.00},{"X":"2016-04-20","Value":0.00},{"X":"2016-04-19","Value":0.00},{"X":"2016-04-18","Value":0.00},{"X":"2016-04-16","Value":0.00},{"X":"2016-04-15","Value":0.00},{"X":"2016-04-14","Value":0.00},{"X":"2016-04-13","Value":0.00},{"X":"2016-04-11","Value":0.00},{"X":"2016-04-09","Value":0.00},{"X":"2016-04-08","Value":0.00},{"X":"2016-04-07","Value":0.00},{"X":"2016-04-06","Value":0.00},{"X":"2016-04-05","Value":11.50},{"X":"2016-04-04","Value":0.00},{"X":"2016-04-02","Value":0.00},{"X":"2016-04-01","Value":0.00},{"X":"2016-03-31","Value":0.00},{"X":"2016-03-30","Value":0.00},{"X":"2016-03-29","Value":0.00},{"X":"2016-03-28","Value":0.00},{"X":"2016-03-26","Value":0.00},{"X":"2016-03-25","Value":0.00},{"X":"2016-03-24","Value":0.00}]},{"Name":"0-7","Items":[{"X":"2016-04-22","Value":166.50},{"X":"2016-04-21","Value":154.04},{"X":"2016-04-20","Value":297.94},{"X":"2016-04-19","Value":195.86},{"X":"2016-04-18","Value":192.58},{"X":"2016-04-16","Value":190.24},{"X":"2016-04-15","Value":176.60},{"X":"2016-04-14","Value":217.74},{"X":"2016-04-13","Value":265.72},{"X":"2016-04-11","Value":147.08},{"X":"2016-04-09","Value":145.26},{"X":"2016-04-08","Value":109.46},{"X":"2016-04-07","Value":191.14},{"X":"2016-04-06","Value":126.40},{"X":"2016-04-05","Value":45.74},{"X":"2016-04-04","Value":130.00},{"X":"2016-04-02","Value":65.00},{"X":"2016-04-01","Value":120.00},{"X":"2016-03-31","Value":52.60},{"X":"2016-03-30","Value":161.42},{"X":"2016-03-29","Value":45.56},{"X":"2016-03-28","Value":111.34},{"X":"2016-03-26","Value":0.00},{"X":"2016-03-25","Value":111.22},{"X":"2016-03-24","Value":118.02}]},{"Name":"5-7","Items":[{"X":"2016-04-22","Value":0.00},{"X":"2016-04-21","Value":0.00},{"X":"2016-04-20","Value":0.00},{"X":"2016-04-19","Value":0.00},{"X":"2016-04-18","Value":0.00},{"X":"2016-04-16","Value":0.00},{"X":"2016-04-15","Value":0.00},{"X":"2016-04-14","Value":0.00},{"X":"2016-04-13","Value":0.00},{"X":"2016-04-11","Value":0.00},{"X":"2016-04-09","Value":0.00},{"X":"2016-04-08","Value":0.00},{"X":"2016-04-07","Value":0.00},{"X":"2016-04-06","Value":0.00},{"X":"2016-04-05","Value":0.00},{"X":"2016-04-04","Value":0.00},{"X":"2016-04-02","Value":0.00},{"X":"2016-04-01","Value":0.00},{"X":"2016-03-31","Value":0.00},{"X":"2016-03-30","Value":0.00},{"X":"2016-03-29","Value":0.00},{"X":"2016-03-28","Value":0.00},{"X":"2016-03-26","Value":0.00},{"X":"2016-03-25","Value":0.00},{"X":"2016-03-24","Value":0.00}]},{"Name":"0-5","Items":[{"X":"2016-04-22","Value":0.00},{"X":"2016-04-21","Value":0.00},{"X":"2016-04-20","Value":0.00},{"X":"2016-04-19","Value":0.00},{"X":"2016-04-18","Value":0.00},{"X":"2016-04-16","Value":0.00},{"X":"2016-04-15","Value":0.00},{"X":"2016-04-14","Value":0.00},{"X":"2016-04-13","Value":0.00},{"X":"2016-04-11","Value":0.00},{"X":"2016-04-09","Value":0.00},{"X":"2016-04-08","Value":0.00},{"X":"2016-04-07","Value":0.00},{"X":"2016-04-06","Value":0.00},{"X":"2016-04-05","Value":0.00},{"X":"2016-04-04","Value":0.00},{"X":"2016-04-02","Value":0.00},{"X":"2016-04-01","Value":0.00},{"X":"2016-03-31","Value":0.00},{"X":"2016-03-30","Value":0.00},{"X":"2016-03-29","Value":0.00},{"X":"2016-03-28","Value":0.00},{"X":"2016-03-26","Value":0.00},{"X":"2016-03-25","Value":0.00},{"X":"2016-03-24","Value":0.00}]}]

@liuxuan30
Copy link
Member

I think because you are using grouped bars rather than single bar. Check out ChartsDemo

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