Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

119
Views
How to use String values for X-Axis in Charts instead of doubles?

I want to display String values for X-Axis in line chart via using 'Charts' I've followed tutorial for same here. As per wrote there
let lineChartData = LineChartData(xVals: dataPoints, dataSet: lineChartDataSet)
I'm not finding in current latest version of library. In, current library version's demo code I'm only able to fill double type of data for X-axis and Y-axis. Please help me to solve this.
Here is desired output. Line chart

8 months ago · Santiago Trujillo
1 answers
Answer question

0

There's a protocol IAxisValueFormatter that you can implement and achieve your expected result.

EDIT:
How to use it

While initialising
chartView.xAxis.valueFormatter = self

and implementing protocol.

extension LineChart1ViewController: IAxisValueFormatter {
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        let months = ["January","February","March","April","May","June","July","Auguest","September","October","November","December"]
        return months[Int(value)]
    }
}
8 months ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.