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

Chart Grid Lines Don't Always Draw #2791

Closed
martheli opened this issue Sep 15, 2017 · 6 comments
Closed

Chart Grid Lines Don't Always Draw #2791

martheli opened this issue Sep 15, 2017 · 6 comments

Comments

@martheli
Copy link

I have two graphs that are set up identically but if you notice the left chart has a border around the entire chart but the right chart doesn't have the top border line (grid line). How do I get the top border to appear on the right chart?

screen shot 2017-09-15 at 2 01 51 pm

@liuxuan30
Copy link
Member

liuxuan30 commented Sep 21, 2017

becuase the label is different. Set axis.axisMaximum to force them have same max value. Also, the label is calculated by computeAxisValues(), which you definitely should check out the logic.

@martheli
Copy link
Author

This is the function that I use to set up the charts:

func setChart(chartview: BarChartView, xarray: [String], yarray: [Double], count: Int){
        
       
        var dataEntries: [BarChartDataEntry] = []
        
        
        for i in 0..<xarray.count {
            
            let dataEntry = BarChartDataEntry(x: Double(i), y: Double(yarray[i]))
            
            dataEntries.append(dataEntry)
        }
        
        
        let chartDataSet = BarChartDataSet(values: dataEntries, label: "")
        
        chartDataSet.drawValuesEnabled = true
        
        
        let chartData = BarChartData(dataSet: chartDataSet)
        
        let format = NumberFormatter()
        
        format.numberStyle = .none
        
        let formatter = DefaultValueFormatter(formatter: format)
        
        chartData.setValueFormatter(formatter)
        
        chartview.xAxis.valueFormatter = IndexAxisValueFormatter(values:xarray)
        
        chartview.xAxis.granularityEnabled = true
        
        chartview.xAxis.labelPosition = .bottom
        
        chartview.chartDescription?.enabled = false
        
        chartview.rightAxis.axisMinimum = 0.0
        
        chartview.leftAxis.axisMinimum = 0.0
        
        
        chartview.legend.enabled = false
        
        chartview.xAxis.drawGridLinesEnabled = false
        
        chartview.rightAxis.drawLabelsEnabled = false
        
        chartview.rightAxis.drawGridLinesEnabled = true
        
        chartview.xAxis.setLabelCount(count, force: false)
        
        chartview.data = chartData

        
    }

I tried adding the following and it made the labels on top not visible:

chartview.leftAxis.axisMaximum = (yarray.max()!)

@liuxuan30
Copy link
Member

after you set chartview.leftAxis.axisMaximum = (yarray.max()!), call notifyDataSetChanged() or put chartview.data = chartData at last line. Changing anything that impact the axis range requires recalcuation.

@martheli
Copy link
Author

martheli commented Sep 28, 2017

screen shot 2017-09-28 at 9 26 29 am

I made the change but it looks like there are additional horizontal bar lines near the 40 and 60 levels.

@liuxuan30
Copy link
Member

did you add any limit line or anything? axisMaximum just impact the axis range, it will not draw any lines for you.

@JCMcLovin
Copy link
Contributor

JCMcLovin commented May 1, 2018

@martheli I don't know if you were able to fix this but I had a similar problem with multiple y-axis gridlines. It happened to me because I did not disable these right axis properties:

    rightAxis.enabled = false // this fixed the extra xAxis grid lines
    rightAxis.drawLabelsEnabled = false

HTH

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