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 not consistently showing data #2753

Closed
martheli opened this issue Aug 28, 2017 · 0 comments
Closed

Chart not consistently showing data #2753

martheli opened this issue Aug 28, 2017 · 0 comments

Comments

@martheli
Copy link

martheli commented Aug 28, 2017

I have the following function to create and display chart:

    func setChart(chartview: BarChartView, xarray: [String], yarray: [Double]){
        
       
        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: "")
        
        let chartData = BarChartData(dataSet: chartDataSet)
        
        chartview.xAxis.valueFormatter = IndexAxisValueFormatter(values:xarray)
        
        chartview.xAxis.labelPosition = .bottom
        
        chartview.chartDescription?.enabled = false
        
        chartview.rightAxis.enabled = false
        
        chartview.legend.enabled = false
        
        chartview.data = chartData
    
    }

And then I have two Views with two charts like this:

setChart(chartview: barChartView, xarray: countArray, yarray: doubleArray)
            
setChart(chartview: barChartView2, xarray: agversionarray, yarray: doubleArray2)

Sometimes the chart looks good like this:

screen shot 2017-08-28 at 1 19 55 pm

But other times the chart X-Axis has two many values or is missing values like this:

screen shot 2017-08-28 at 1 20 06 pm

I also printed out my X and Y array when the graph looks weird and they are as follows:

Graph 1

["iOS 10", "iOS 9"]
[193.0, 3.0]

Graph 2

["2.1.0.6", "2.1.0.5", "2.0.32", "2.0.30", "2.0.23"]
[173.0, 3.0, 15.0, 4.0, 1.0]

The data looks fine, not sure why its being formatted like that.

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