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

How to set xAxis values from array in Swift 3.0 #2090

Closed
ghost opened this issue Jan 18, 2017 · 2 comments
Closed

How to set xAxis values from array in Swift 3.0 #2090

ghost opened this issue Jan 18, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 18, 2017

In Swift 2.3 I'm able to set xAxis values from array. Now in Swift 3.0, not able to set.

I want to assign custom values from my array.

dataPoints = ["18","17","16","15","14","13","12"...] // It contains last 30 days from current date, that's why it contain 18 1st because 18 is current date.

values = [65.66,68.78,64.66,63.37...]

func setChart(dataPoints: [String], values: [Float])
 {
          barChartView.noDataText = "You need to provide data for the chart."
          for i in 1..<dataPoints.count
        {
            let dataEntry = BarChartDataEntry(x: Double(i), yValues: [Double(values[i])])
            dataEntries.append(dataEntry)
        }
        print("ChartDataEntry :\(dataEntries)")
        let chartDataSet = BarChartDataSet(values: dataEntries, label: "INR Rates(₹)/$")
        let chartData = BarChartData(dataSet: chartDataSet)
        barChartView.data = chartData](url)
}

Please help me to assign values for x-Axis using swift 3.0

@talisk
Copy link

talisk commented Jan 26, 2017

Please see here :)

@ghost
Copy link
Author

ghost commented Jan 31, 2017

Couple of days, I'm struggling for this, but now I got the solution, so I'm updating here.

In Swift 3.0 we can set x-axis values like this by passing array.

barChartView.xAxis.valueFormatter = IndexAxisValueFormatter(values: dataPoints)
barChartView.xAxis.granularityEnabled = true
barChartView.xAxis.granularity = 2

That's it.

@ghost ghost closed this as completed Jan 31, 2017
This issue was closed.
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