Search code examples
iosswiftchartsios-charts

How to draw a line in line chart for single value in Charts(IOS)


I need to draw a single value in line chart. Currently i am using ios-charts library for line graph purpose.

The data will be varied some times i'll get the single data inside the data set at that time i need to draw the single value in the line chart.

What i am getting:

enter image description here

What i required:

enter image description here


Solution

  • The library cannot do this automatically, but there is the following option.
    You check if your data contains exactly one point. If yes, then you add a so called LimitLine.

    For example:

    let limitLine = ChartLimitLine(
       limit: value,
       label: labelText)
    
    limitLine.lineColor = .blue
    limitLine.labelPosition = .topLeft
    limitLine.valueFont = UIFont.systemFont(ofSize: 14)
    
    chartView.leftAxis.addLimitLine(limitLine)