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

I need to put dates from an array on xAxis #3277

Closed
mpapado3 opened this issue Feb 20, 2018 · 1 comment
Closed

I need to put dates from an array on xAxis #3277

mpapado3 opened this issue Feb 20, 2018 · 1 comment

Comments

@mpapado3
Copy link

I am trying to understand how I can use an array populated with dates on the xAxis, but I haven't figured it out yet.

Below is my code for the setChart function. On the last row I use the dataPoints provided on the function bt they cannot be casted as IAxisValueFormatter.
If I remove this line the app works but returns the bar chart with 0 - 6 enumeration based on the for clause.

func setChart(dataPoints: [String], values: [Int]) {
        barChartView.noDataText = "You need to run some tests first to use the charts"
        
        var dataEntries: [BarChartDataEntry] = []
        
        for i in 0..<dataPoints.count {
            let dataEntry = BarChartDataEntry(x: Double(i), y: Double(values[i]))
            dataEntries.append(dataEntry)
        }
        
        let chartDataSet = BarChartDataSet(values: dataEntries, label: "Hyper")
        let chartData = BarChartData(dataSet: chartDataSet)
        let xAxis = barChartView.xAxis
        xAxis.labelWidth = 5
        barChartView.data = chartData
        barChartView.xAxis.labelPosition = .bottom
        barChartView.chartDescription?.text = "Hyper Diagram"
        barChartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0)
        barChartView.xAxis.valueFormatter = dataPoints as! IAxisValueFormatter  //This returns error
 
    }

Thank you!

@jjatie
Copy link
Collaborator

jjatie commented Feb 20, 2018

Please use Stack Overflow with the ios-charts tag for support issues. https://stackoverflow.com/questions/tagged/ios-charts

@jjatie jjatie closed this as completed Feb 20, 2018
@ChartsOrg ChartsOrg locked and limited conversation to collaborators Feb 20, 2018
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

2 participants