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

Use the right axis for calculating xMin and xMax on charts using righ… #4751

Closed
wants to merge 0 commits into from

Conversation

mmazzei
Copy link

@mmazzei mmazzei commented Nov 9, 2021

Use the right axis for calculating xMin and xMax on charts using right and left axis but having left axis data empty.

Issue Link 🔗

For line charts where two data sets are configured, one with right axis dependency, and the other for left axis dependency.

If the left axis data set is empty, then the right data sets is no displayed.

Goals ⚽

Implementation Details 🚧

This commit fixes the issue by choosing the best axis to calculate xmax and xmin when rendering.

The following chart will have no lines rendered unless the costDataSet is not empty, then both lines are rendered:

        let valueDataSet: LineChartDataSet = LineChartDataSet(entries: valueEntries, label: "Value".localized())
        valueDataSet.setColor(.violet)
        valueDataSet.drawValuesEnabled = false
        valueDataSet.drawCirclesEnabled = false
        valueDataSet.axisDependency = .right

        let costDataSet: LineChartDataSet = LineChartDataSet(entries: [], label: "Cost".localized())
        costDataSet.setColor(.dark)
        costDataSet.drawValuesEnabled = false
        costDataSet.drawCirclesEnabled = false
        costDataSet.axisDependency = .left

        let dataSets: [LineChartDataSet] = [valueDataSet, costDataSet, benchmarkDataSet]
        let chartData = LineChartData(dataSets: dataSets)
        let chartView = LineChartView()
        chartView.data = chartData

        chartView.rightAxis.enabled = true
        chartView.rightAxis.axisMinimum = valueDataSet.yMin * 0.9
        chartView.rightAxis.axisMaximum = valueDataSet.yMax * 1.1 + 1

        chartView.leftAxis.enabled = true
        chartView.leftAxis.axisMinimum = costDataSet.yMin * 0.9
        chartView.leftAxis.axisMaximum = costDataSet.yMax * 1.1 + 1

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

Successfully merging this pull request may close these issues.

None yet

1 participant