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

Strange margin/space in a grouped BarChart #1763

Closed
mavoi opened this issue Nov 1, 2016 · 5 comments
Closed

Strange margin/space in a grouped BarChart #1763

mavoi opened this issue Nov 1, 2016 · 5 comments

Comments

@mavoi
Copy link

mavoi commented Nov 1, 2016

I'm having an issue with positioning the bars of a grouped barchart. This is my chart:

bildschirmfoto 2016-11-01 um 11 49 22

This is my chart setup:

        chart.drawValueAboveBarEnabled = true
        chart.drawGridBackgroundEnabled = false
        chart.pinchZoomEnabled = false
        chart.scaleXEnabled = false
        chart.scaleYEnabled = false
        chart.doubleTapToZoomEnabled = false
        chart.dragEnabled = false
        chart.isUserInteractionEnabled = false
        chart.rightAxis.enabled = false
        chart.legend.enabled = true
        
        let xAxis = chart.xAxis
        xAxis.labelCount = 6
        xAxis.axisMaximum = 6
        xAxis.drawGridLinesEnabled = true
        xAxis.labelPosition = XAxis.LabelPosition.bottom
        xAxis.valueFormatter = self
        
        let numberFormatter = Foundation.NumberFormatter()
        numberFormatter.numberStyle = Foundation.NumberFormatter.Style.decimal
        numberFormatter.maximumFractionDigits = 0
        numberFormatter.multiplier = 1
        numberFormatter.decimalSeparator = "."
        
        let yAxis = chart.leftAxis
        yAxis.valueFormatter = DefaultAxisValueFormatter(formatter: numberFormatter)
        yAxis.drawGridLinesEnabled = false
        yAxis.axisMinimum = 0
        yAxis.setLabelCount(4, force: true)
        
        let legend: Legend = chart.legend
        legend.horizontalAlignment = .center
        legend.verticalAlignment = .bottom
        legend.orientation = .horizontal

And this is how I set up the chart data:

        let barSpace = 0.06
        let barWidth = 0.25
        let groupSpace = 1 - (3 * barWidth) - (2 * barSpace)
        
        let data = BarChartData(dataSets: yVals)
        data.barWidth = barWidth
        data.groupBars(fromX: 0, groupSpace: groupSpace, barSpace: barSpace)
        
        chart.data = data
        chart.fitBars = true
        chart.notifyDataSetChanged()

The first group starts at the center of the first X-Label. Or there seems to be some kind of offset or margin?
I need the first bar to be drawn at the beginning of the chart. And I don't want the grid line center drawn to the label/group. I need 3 bars next to each other (a group), a grid line after them and then the next group. Any suggestion?

@liuxuan30
Copy link
Member

have you check out ChartsDemo - Multiple Bar chart for how to get the values?
like

    float groupSpace = 0.08f;
    float barSpace = 0.03f;
    float barWidth = 0.2f;
    // (0.2 + 0.03) * 4 + 0.08 = 1.00 -> interval per "group"

@danielgindi
Copy link
Collaborator

You're doing fine! The labels are supposed to draw like that, because they are centered below the axis lines, which are the exact x-value point.

What you want to do now, is enable: centerAxisLabelsEnabled. Boom! Now the labels are centered between every 2 x-value points.

You can see the demos to watch it in action.

@mavoi
Copy link
Author

mavoi commented Nov 3, 2016

@danielgindi @liuxuan30
Sorry but this does not fix the problem. I'm not talking about the labels! This was my chart before I got to Charts 3:

bildschirmfoto 2016-11-03 um 10 04 31

And this is my Chart now:

bildschirmfoto 2016-11-01 um 11 49 22

1. All Bars are shifted to the right. Why? 2. The Grid lines moved. Why?

I don't know how to describe the problem with other words. The problem is obvious and this is not fixable at the moment...

@harshvishu
Copy link

harshvishu commented Nov 4, 2016

barChartView.xAxis.axisMinimum = 0.0 // Change this value to move the xAxis

resetCustomAxisMin() // to undo this change

@liuxuan30
Copy link
Member

@mavoi when you update your library, make sure you made changes as well. Take a look at ChartsDemo for multiple bar chart as example

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

4 participants