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

CombinedChartView: Wrong positions of bars when using multiple Bar and Graph -Datasets #775

Closed
AndreasIgelCC opened this issue Feb 26, 2016 · 5 comments

Comments

@AndreasIgelCC
Copy link
Contributor

Hi together,

its a real cool SDK. Unfortunately there is a bug when using the CombinedChartView and multiple Graph-Datasets with Bar-Datasets. Please could you help me?

I did the follwing:

for (index , sourceobject) in sourceObjectArray.enumerate()
{
    xVals.append(numberFormatterYear.stringFromNumber(sourceobject.jahr)!)
    datenArray1.append(BarChartDataEntry(value: sourceobject.data1, xIndex: index) )
    datenArray2.append(BarChartDataEntry(value: sourceobject.data2, xIndex: index))
    datenArray3.append(ChartDataEntry(value: sourceobject.data3, xIndex: index))
    if sourceobject.data4 != nil {
        datenArray4.append(ChartDataEntry(value: sourceobject.data4!, xIndex: index))
    }
}

let dataSet1 = BarChartDataSet(yVals: datenArray1, label: "label1")
dataSet1.setColor(UIColor(red: 158/255.0, green: 156/255.0, blue: 161/255.0, alpha: 1.0))
dataSet1.barSpace = 0.2
dataSet1.axisDependency = ChartYAxis.AxisDependency.Left
dataSet1.drawValuesEnabled = false

let dataSet2 = BarChartDataSet(yVals: datenArray2, label: "label2")
dataSet2.setColor(UIColor(red: 75/255.0, green: 131/255.0, blue: 169/255.0, alpha: 1.0))
dataSet2.barSpace =  dataSet1.barSpace
dataSet2.axisDependency = ChartYAxis.AxisDependency.Left
dataSet2.drawValuesEnabled = false

let dataSet3 = LineChartDataSet(yVals: datenArray3, label: "label3")
let dataSet3Color = UIColor(red: 175/255.0, green: 50/255.0, blue: 51/255.0, alpha: 1.0)
dataSet3.setColor(dataSet3Color)
dataSet3.setCircleColor(dataSet3Color)
dataSet3.lineWidth = 2.5
dataSet3.circleRadius = 4
dataSet3.axisDependency = ChartYAxis.AxisDependency.Right
dataSet3.drawValuesEnabled = false
dataSet3.drawCirclesEnabled = true
dataSet3.drawCubicEnabled = false
dataSet3.drawCircleHoleEnabled = false
dataSet3.visible = true

let dataSet4 = LineChartDataSet(yVals: datenArray4, label: "label4")
let dataSet4Color = UIColor(red: 20/255.0, green: 154/255.0, blue: 220/255.0, alpha: 1.0)
let dataSet4ColorHole = UIColor(red: 243/255.0, green: 234/255.0, blue: 9/255.0, alpha: 1.0)
dataSet4.setColor(dataSet4Color)
dataSet4.setCircleColor(dataSet4Color)
dataSet4.circleHoleColor = dataSet4ColorHole
dataSet4.lineWidth = 2.5
dataSet4.circleRadius = 6
dataSet4.axisDependency = ChartYAxis.AxisDependency.Right
dataSet4.drawValuesEnabled = false
dataSet4.drawCirclesEnabled = true
dataSet4.drawCubicEnabled = false
dataSet4.drawCircleHoleEnabled = true
dataSet4.visible = true

let barChartData = BarChartData(xVals: xVals, dataSets: [dataSet2, dataSet1])
barChartData.groupSpace = 0.2
let graphChartData = LineChartData(xVals: xVals, dataSets: [dataSet3, dataSet4])

let chartData = CombinedChartData(xVals: xVals)
chartData.barData = barChartData
chartData.lineData = graphChartData

_chartView.data = chartData

The Result (bars not properly aligned with x-values):
screenshot_277

If just using a BarChart and not a combinedChart, the bars are correct (but the graphs are missing):
screenshot_278

@liuxuan30
Copy link
Member

current combined chart view does not support multiple bars (grouped bars). I had a PR #269 for that, pending review and discussion. You can take a look at the PR and use it for some testing :) (I have been using it)

BTW, I haven't update this PR for some time; if you encounter conflict or issues, let me know, I will try find some time to sync with master (maybe tomorrow if I had time). (it should not have many conflicts with master, since the data set changing should not impact combined chart rendering)

@liuxuan30
Copy link
Member

you know what, I just synced my PR with master, had some conflicts to solve. Generally, there may have issues with highlighting if you need fine-grained control. Give a try with my branch https://github.com/liuxuan30/ios-charts/tree/GroupedBarsCombinedChart, I had a view controller in ChartsDemo that demonstrate the grouped bar support.

@AndreasIgelCC
Copy link
Contributor Author

Thx a lot! Worked as promised!

@liuxuan30
Copy link
Member

np. be careful of highlighting if you use it

@adad184
Copy link

adad184 commented Jul 4, 2016

need this

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