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

Charts 3.0 how set xAxis gridline between bars like before? #1766

Open
Asavarkhul opened this issue Nov 2, 2016 · 10 comments
Open

Charts 3.0 how set xAxis gridline between bars like before? #1766

Asavarkhul opened this issue Nov 2, 2016 · 10 comments
Labels

Comments

@Asavarkhul
Copy link

Asavarkhul commented Nov 2, 2016

Before the update we had this :

capture d ecran 2016-11-02 a 10 01 59

The grids bars where between each bars, but after the update, we have this now :

capture d ecran 2016-11-02 a 09 59 55

Do you know what to change in order to have our last behavior?

Here it's our configuration :

//Chart configuration
self.chartView.drawBarShadowEnabled = false
self.chartView.drawGridBackgroundEnabled = false
self.chartView.setScaleEnabled(false)
self.chartView.highlightPerTapEnabled = false
self.chartView.highlightPerDragEnabled = false
self.chartView.drawValueAboveBarEnabled = false
self.chartView.noDataText = "list_issues_no_issue".localizedString()
self.chartView.chartDescription?.font = textFont
self.chartView.chartDescription?.textColor = UIColor.fBlueColor()
        
self.chartView.leftAxis.enabled = false
        
let rightAxis = self.chartView.rightAxis
rightAxis.drawGridLinesEnabled = false
rightAxis.labelFont = UIFont.preferredFont(forTextStyle: UIFontTextStyle.caption1)
rightAxis.labelTextColor = UIColor.fBlueColor()
rightAxis.valueFormatter = DefaultAxisValueFormatter(decimals: 1)
        
self.chartView.chartDescription?.text = ""
self.chartView.legend.enabled = false
        
let xAxis = self.chartView.xAxis
xAxis.drawGridLinesEnabled = true
xAxis.axisLineColor = UIColor.fBlueColor()
xAxis.labelPosition = .bottomInside
xAxis.labelFont = UIFont.preferredFont(forTextStyle: UIFontTextStyle.caption1)

Regards

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 3, 2016

xAxis.centerAxisLabelsEnabled = YES; copy from Multiple Bar Chart

@Asavarkhul
Copy link
Author

It doesn't fix our problem, this property is made for centering labels between charts, but that's not my question.. The problem is about centering gridline between charts, do you see?

@mavoi
Copy link

mavoi commented Nov 3, 2016

I'm having the same issue in #1763

@Asavarkhul
Copy link
Author

@liuxuan30 Do you see what I mean?

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 7, 2016

@Asavarkhul I am taking multiple bar chart in ChartsDemo as example, and looks like answered your question. The grid line is centered between bars as well as the labels. That's why I say centerAxisLabelsEnabled.
However I don't understand It doesn't fix our problem while in ChartsDemo, no matter whether you turn on centerAxisLabelsEnabled or not, the grid line is fine though.. Could you try?

@Asavarkhul
Copy link
Author

@liuxuan30 Hello, can you try with this example project https://github.com/Asavarkhul/ChartsSampleProject/tree/chartsIssue/1767-xAxis-gridline-between-bars

You can see how we have implement your solution proposal and the wired behavior we get.

Regards

@convergeeducacao
Copy link

convergeeducacao commented Dec 7, 2016

Theres some way to do the same gridline separator? Like this image (https://cloud.githubusercontent.com/assets/10169030/19922578/849602da-a0e3-11e6-9f41-4d3aa6c24517.png)?
Regards...

@liuxuan30 liuxuan30 reopened this Dec 8, 2016
@liuxuan30
Copy link
Member

liuxuan30 commented Dec 8, 2016

hmm, It seems like a bug..
It did work in ChartsDemo - multiple bar chart. It seems work as expected for multiple bar chart/horizontal bar chart but not in single bar/horizontal bar chart.

@danielgindi do you know we support such grid lines for single bar? I can't remember.. But I had a feeling in Chart 2.0, we used to support this.

I just changed <=1 to <1 condition in open func groupBars(fromX: Double, groupSpace: Double, barSpace: Double) to make it work with single bars.. It seems works.. And I don't know why you say there must be two data sets in first place. Am I missing anything? @danielgindi

@Asavarkhul Below is how I did it with ChartsDemo - multiple bar chart, you can have a try:

Make sure your groupSpace + (barSpace + barWidth) * set count = 1.0

     float groupSpace = 0.08f;
     float barSpace = 0.02f;
     float barWidth = 0.9f;
     // (0.9 + 0.02) * 1 + 0.08 = 1.00 -> interval per "group"

     [dataSets addObject:set1];  // only need one

     // specify the width each bar should have
     data.barWidth = barWidth;
     [data groupBarsFromX: startYear groupSpace: groupSpace barSpace: barSpace];

     _chartView.data = data;

change:

    open func groupBars(fromX: Double, groupSpace: Double, barSpace: Double)
    {
        let setCount = _dataSets.count
        if setCount <= 1
        {
            print("BarData needs to hold at least 2 BarDataSets to allow grouping.", terminator: "\n")
            return
        }

to:

    open func groupBars(fromX: Double, groupSpace: Double, barSpace: Double)
    {
        let setCount = _dataSets.count
        if setCount < 1   // here
        {
            print("BarData needs to hold at least 2 BarDataSets to allow grouping.", terminator: "\n")
            return
        }

Now it looks like this (due to the x axis interval, it will show every two bars:
image
but if you zoom in:
image

@liuxuan30 liuxuan30 added the bug label Dec 8, 2016
@harariyakamal
Copy link

Is this fixed. I am trying to draw something like https://cloud.githubusercontent.com/assets/10169030/19922578/849602da-a0e3-11e6-9f41-4d3aa6c24517.png

The Axis labels are drawn at centers but the grid lines are not as per expectations. Here is the the code I am trying.

    xAxis.drawAxisLineEnabled = true
	xAxis.drawGridLinesEnabled = true
	xAxis.gridColor = .red
	xAxis.gridLineWidth = 0.5
	xAxis.labelCount = 20
	xAxis.centerAxisLabelsEnabled = true

@floriangbh
Copy link

floriangbh commented Dec 13, 2018

capture d ecran 2018-12-13 a 09 51 43

Hello, same issue here, fixed with grouped bar :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants