1

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

2
  • 1
    Please edit your question and share your code as a minimal reproducible example showing what you have already tried. It’s very difficult to help you otherwise. See also How to Ask. Commented May 26, 2022 at 15:47
  • It’s a contradiction to draw a line using only a single point so I am not surprised if the library doesn’t support it. Commented May 26, 2022 at 17:13

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

Comments

3

For Swift Charts (Xcode 14 Beta)

Should someone decide to do something similar with Apple's Swift Charts, RuleMark() can be used to draw the line and PointMark() for a point like this:

Chart() {
    RuleMark(
        xStart: .value("Start", 0),
        xEnd: .value("End", 20),
        y: .value("Value", 125)
    )
    
    PointMark(
        x: .value("X Value", 10),
        y: .value("Y Value", 125)
    )
}

Example Output:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.