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

Missing alternate x-axis labels on line chart #3139

Closed
takitaktak opened this issue Dec 27, 2017 · 1 comment
Closed

Missing alternate x-axis labels on line chart #3139

takitaktak opened this issue Dec 27, 2017 · 1 comment

Comments

@takitaktak
Copy link

takitaktak commented Dec 27, 2017

What I got:
screen shot 2017-12-27 at 12 53 15 pm

The x-axis is not displaying all the labels in the chart. It should display all the month labels. Here is my code:

        let chart = LineChartView(frame: .zero)
        chart.setExtraOffsets(left: 20, top: 15, right: 20, bottom: 15)
        chart.drawGridBackgroundEnabled = true
        chart.gridBackgroundColor = .clear
        chart.backgroundColor = .clear
        chart.chartDescription = nil
        chart.highlightPerTapEnabled = false
        chart.isUserInteractionEnabled = false
        
        chart.rightAxis.enabled = false
        chart.legend.enabled = false
        
        let yAxis = chart.leftAxis
        yAxis.gridColor = UIColor(hexString: "C7C7C7")!
        yAxis.drawAxisLineEnabled = false
        yAxis.drawLabelsEnabled = false
        yAxis.axisMaximum = 6000
        yAxis.gridLineWidth = 1
        yAxis.enabled = true
        
        let xAxisLabels = ["Jan", "Feb", "Mar", "April", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
        chart.xAxis.valueFormatter = IndexAxisValueFormatter(values: xAxisLabels)
        chart.xAxis.labelFont = UIFont.sourceSansProSemibold(withSize: 15.5)
        chart.xAxis.labelTextColor = UIColor(hexString: "808080")!
        chart.xAxis.drawGridLinesEnabled = false
        chart.xAxis.drawAxisLineEnabled = false
        chart.xAxis.drawLabelsEnabled = true
        chart.xAxis.labelPosition = .bottom
        chart.xAxis.enabled = true
        chart.xAxis.granularityEnabled = true
        chart.xAxis.granularity = 1
        chart.xAxis.wordWrapEnabled = true

Can somebody point out what I'm doing wrong? Thanks!

@takitaktak
Copy link
Author

Solved it by adding this line:

chart.xAxis.setLabelCount(xAxisLabels.count, force: true)

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

1 participant