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

X-Axis Labels not showing #3154

Closed
martheli opened this issue Jan 4, 2018 · 9 comments
Closed

X-Axis Labels not showing #3154

martheli opened this issue Jan 4, 2018 · 9 comments

Comments

@martheli
Copy link

martheli commented Jan 4, 2018

I have the below function that I use to set up a simple bar chart. The resulting chat appears but with no x-axis labels on the chart at all. I am not sure if I missed something in my set up of the chart that would leave the x-axis labels off.

 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
        
        
    }
@martheli
Copy link
Author

martheli commented Jan 5, 2018

Now I have it to where it only shows 1 xValue under the second bar in the chart. Anyone know how to get all of the Values to show up?

@sundeepios
Copy link

Even i am facing the same problem..X axis labels are not showing up in Barchart. And below is my code. Can any one help me out.

func setChart(dataPoints: [String], values: [Double]) {

    var dataEntries: [BarChartDataEntry] = []
    
    for i in 0..<dataPoints.count {
        let dataEntry = BarChartDataEntry(x: Double(i), y: values[i])
        dataEntries.append(dataEntry)
    }
    
    var chartDataSet = BarChartDataSet()
    chartDataSet = BarChartDataSet(values: dataEntries, label: "Work Orders")
    chartDataSet.colors = ChartColorTemplates.material()
    chartDataSet.valueFont = .boldSystemFont(ofSize: 15)
    
    let chartData = BarChartData(dataSet: chartDataSet)
    
    let format = NumberFormatter()
    format.numberStyle = .decimal
    let formatter = DefaultValueFormatter(formatter: format)
    chartData.setValueFormatter(formatter)
    
    barChartView.data = chartData
    barChartView.xAxis.granularity = 1
    barChartView.xAxis.granularityEnabled = true
        
    barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values:dataPoints)
    
    barChartView.xAxis.setLabelCount(dataPoints.count , force: true)
    
    barChartView.xAxis.drawGridLinesEnabled = false
    barChartView.xAxis.labelPosition = .bottom
    barChartView.xAxis.labelRotationAngle = 315
    barChartView.pinchZoomEnabled = false
    
    for datastring in dataPoints {
        if datastring.characters.count > 20 {
            barChartView.xAxis.labelRotationAngle = 270
            break
        }
    }
    
    barChartView.doubleTapToZoomEnabled = false
    barChartView.chartDescription?.text = ""
    barChartView.rightAxis.enabled = false
    barChartView.leftAxis.enabled = false
    barChartView.barData?.barWidth = 0.4
    barChartView.isUserInteractionEnabled = false
    
    barChartView.xAxis.avoidFirstLastClippingEnabled = false
    
    barChartView.dragEnabled = false
    
    barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInOutCubic)
}

@jjatie
Copy link
Collaborator

jjatie commented Jan 11, 2018

Has this code worked fine before, or are you both new to using Charts? Is this still the case in 3.0.5 (just released)?

@georgeerol
Copy link

Yes, i'm having the same problem. It works fine with release 3.04 but not release 3.0.5.

@jjatie
Copy link
Collaborator

jjatie commented Jan 11, 2018

If anyone can investigate this, it would be appreciated. I will do my best to look into it this week.

@leedsalex
Copy link
Contributor

leedsalex commented Jan 11, 2018

@jjatie I have submitted a pull request that fixes this (#3174).

@jjatie jjatie closed this as completed Jan 12, 2018
@ChartsOrg ChartsOrg locked as resolved and limited conversation to collaborators Jan 12, 2018
@jjatie
Copy link
Collaborator

jjatie commented Jan 12, 2018

PR accepted and will be deployed in the near future.

@liuxuan30
Copy link
Member

@jjatie have you checked why causing this?

@jjatie
Copy link
Collaborator

jjatie commented Jan 12, 2018

Yes, I made a mistake in one of my commits. #3174 reverts it.

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

No branches or pull requests

6 participants