Show time on x axis of the chart using Charts library by Daniel Gindi
NickName:Lilya Ask DateTime:2020-03-12T21:56:56

Show time on x axis of the chart using Charts library by Daniel Gindi

I am using Charts library by Daniel Gindi: https://github.com/danielgindi/Charts

For my project, I need to replace the x axis with time that shows only hours and minutes (HH:mm).

I've created the class with an extension based on this answer: ios Charts 3.0 - Align x labels (dates) with plots

import UIKit
import Charts

class ChartXAxisFormatter: NSObject {
      fileprivate var dateFormatter: DateFormatter?
      fileprivate var referenceTimeInterval: TimeInterval?

      convenience init(referenceTimeInterval: TimeInterval, dateFormatter: DateFormatter) {
          self.init()
          self.referenceTimeInterval = referenceTimeInterval
          self.dateFormatter = dateFormatter
      }
}

extension ChartXAxisFormatter: IAxisValueFormatter {

     func stringForValue(_ value: Double, axis: AxisBase?) -> String {
           guard let dateFormatter = dateFormatter,
           let referenceTimeInterval = referenceTimeInterval
           else {
               return ""
           }

           let date = Date(timeIntervalSince1970: value * 3600 * 24 + referenceTimeInterval)
           return dateFormatter.string(from: date)
       }

}

I have one Charts view that shows a pressure or temperature chart when I click on the particular button (there are separate buttons for showing temperature/pressure).

So, my question is that I can't figure out how I can actually use this class to transform my x axis to show time?

Any ideas? Thank you!

Copyright Notice:Content Author:「Lilya」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60655640/show-time-on-x-axis-of-the-chart-using-charts-library-by-daniel-gindi

More about “Show time on x axis of the chart using Charts library by Daniel Gindi” related questions

Show time on x axis of the chart using Charts library by Daniel Gindi

I am using Charts library by Daniel Gindi: https://github.com/danielgindi/Charts For my project, I need to replace the x axis with time that shows only hours and minutes (HH:mm). I've created the

Show Detail

date and time on x axis in ios charts by Daniel Gindi

how can i add both time and date on x axis in ios charts by Daniel Gindi? Thanks in advance for the answers! extension ChartXAxisFormatter: IAxisValueFormatter { func stringForValue(_ value: Dou...

Show Detail

How to shift data on xAxis to right on Daniel Gindi charts?

I have a data chart DataChart would like to shift data of xAxis along with data lines to right by certain value. DataChart Screen Shot Please help me out which property to use from the library t...

Show Detail

iOS Charts(Daniel Gindi) - how to set dual y axis dual graph lines in Swift

I am using Charts (Git Repo of Daniel Gindi's). Here is my code for single y axis single line chart: When I try to add a second line to the y axis it throws the error 'Cannot convert value of type '

Show Detail

Using both String and Date on axis charts ios

I am using Charts library by Daniel Gindi On the X axis of the line chart, I want to show 3 values (string, date, date). 1) Is it possible to format only one particular label into a string type v...

Show Detail

How to show Percentage sign in pie chart using daniel gindi/Chart library in swift(IOS Chart)

I am using the Charts framework (by Daniel gindi). It was working fine but how to show % (sign) on piechart? I am also try use NSNumberFormatter() method for covert data value in percantage but n...

Show Detail

Swift Charts with logarithmic axis

I want to draw a plot with a logarithmic X-axis. This is possible with CorePlot. However, the Charts package from Daniel Gindi danielgindi/Charts seems to fit better in a Swift environment. Unfortu...

Show Detail

Is it possible to use iOS Charts (Daniel Gindi) to generate graphs in pdf document on iOS

I am using iOS Charts (Daniel Gindi) to generate graphs in an iOS app and I want to be able to generate a PDF report with those graphs included in the body of the report. Can anyone explain how to...

Show Detail

how to run chart in iOS 7 using daniel gindi chart library?

I want to show the chart in iOS 7 using this library https://github.com/danielgindi/ios-charts. I can able to show a chart using iOS 8 and iOS 9.If i run in iOS 7 means,It shows linker error.Provid...

Show Detail

How to draw horizontal stacked area chart by ios-charts

I am using iOS Charts by Daniel Gindi. I need to draw horizontal stacked area chart (Example). But I cannot find similar charts in examples of the library. I am trying to customise Horizontal Bar ...

Show Detail