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 not population correctly #3619

Closed
yoamod opened this issue Sep 3, 2018 · 2 comments
Closed

CombinedChartView not population correctly #3619

yoamod opened this issue Sep 3, 2018 · 2 comments

Comments

@yoamod
Copy link

yoamod commented Sep 3, 2018

What did you do?

Tried to populate a combinedChartView (bar and line).

What did you expect to happen?

Expected each y value to be plotted against one x value. Also expected the y values to be plotted against specific x values.

What happened instead?

On some x values, two y values were plotted against it. Also the y values were not plotted against the correct x values.

untitled

Charts Environment

**Charts version/Branch/Commit Number:3.0
**Xcode version:9.3
**Swift version:4.2
**Platform(s) running Charts:iOS
**macOS version running Xcode:10.13.6

Code

func updateTotalChart(xValues: [Int], yValuesBarChart: [Int], yValuesLineChart: [Int]) {
    
    var yValuesLine = [ChartDataEntry]()
    var yValuesBar = [BarChartDataEntry]()
    
    for i in 0..<graphRounds.count {
        let yValueBar = BarChartDataEntry(x: Double(rounds[i]), y: Double(perRoundThrownArray[i]))
        yValuesBar.append(yValueBar)
        
        let yValueLine = ChartDataEntry(x: Double(rounds[i]), y: Double(perRoundLandedArray[i]))
        yValuesLine.append(yValueLine)
    }
    
    let lineChartSet = LineChartDataSet(values: yValuesLine, label: "Total Punches Landed")
    let barChartSet = BarChartDataSet(values: yValuesBar, label: "Total Punches Thrown")
    lineChartSet.colors = [UIColor.black]
    barChartSet.colors = [UIColor.green]
    lineChartSet.circleRadius = 1
    lineChartSet.drawValuesEnabled = false
    barChartSet.valueTextColor = UIColor.white
    let data: CombinedChartData = CombinedChartData(dataSets: [lineChartSet, barChartSet])
    data.barData = BarChartData(dataSet: barChartSet)
    data.lineData = LineChartData(dataSet: lineChartSet)
    totalThrownChart.data = data
    //    Formating
    totalThrownChart.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
    totalThrownChart.chartDescription?.text = ""
    totalThrownChart.leftAxis.labelTextColor = UIColor.white
    totalThrownChart.rightAxis.enabled = false
    totalThrownChart.legend.textColor = UIColor.white
    totalThrownChart.xAxis.labelPosition = .bottom
    totalThrownChart.xAxis.labelTextColor = UIColor.white
    totalThrownChart.xAxis.gridColor = UIColor.white
    
    totalThrownChart.xAxis.setLabelCount(graphRounds.count, force: true)
    totalThrownChart.xAxis.granularityEnabled = true
    totalThrownChart.xAxis.granularity = 1
    totalThrownChart.xAxis.axisMaximum = Double(graphRounds.max()!)
    totalThrownChart.xAxis.axisMinimum = Double(graphRounds.min()!)
    totalThrownChart.xAxis.axisMinLabels = graphRounds.count
    totalThrownChart.leftAxis.drawZeroLineEnabled = true
    totalThrownChart.leftAxis.axisMinimum = 0
}
@thierryH91200
Copy link
Contributor

what is this rounds[I] ?

@yoamod
Copy link
Author

yoamod commented Sep 7, 2018

Yip I think that was the issue. Thanks!

@yoamod yoamod closed this as completed Sep 7, 2018
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