0

I am using "SwiftChart" library. Im uploading x and y axis to the chart.

1.) I do not know how to upload the values properly to the array

self.chartArray.insert(grChartStruct(x: xFloat, y: bearishFloatY), at: 0)

2.) I neeed to tranform that array to data (as shown below)

series = ChartSeries(data: chartArray[indexPath])

I do not want to upload these like this because im going to have to change the data

let data = [(x: 0.0, y: 0)

My code which needs fixing.

struct grChartStruct {
        let x : Float
        let y : Float

    }

       var chartArray = [grChartStruct]()


            let bearishFloat = 1.1
            let bullishFloat = 0.0
            var xFloat = 0.0

            self.chartArray.insert(grChartStruct(x: xFloat, y: bearishFloatY), at: 0)

         series = ChartSeries(data: chartArray[indexPath])

The class(library) im using

open class ChartSeries {
    open var data: Array<(x: Float, y: Float)>
    open var area: Bool = false
    open var line: Bool = true
    open var color: UIColor = ChartColors.blueColor() {
        didSet {
            colors = (above: color, below: color, 0)
        }
    }
    open var colors: (above: UIColor, below: UIColor, zeroLevel: Float) = (above: ChartColors.blueColor(), below: ChartColors.redColor(), 0)

    public init(_ data: Array<Float>) {
        self.data = []

        data.enumerated().forEach { (x, y) in
            let point: (x: Float, y: Float) = (x: Float(x), y: y)
            self.data.append(point)
        }
    }

    public init(data: Array<(x: Float, y: Float)>) {
        self.data = data
    }

    public init(data: Array<(x: Double, y: Double)>) {
        self.data = data.map ({ (Float($0.x), Float($0.y))})
    }
}   
4
  • 1
    I feel like you may not get many responses because the wording of your question is unclear. What data are you trying to organize in what way. I interpreted that you are trying to orrganize some data (still not sure what) as an array of grCharStruct. Also, it would help if you only include the necessary code. What is ref? Commented Mar 15, 2017 at 4:14
  • I have fixed the code. All I am trying to do is load information from firebase data base into an array. The array has to have to float values x and y Commented Mar 15, 2017 at 4:20
  • also just added part of the code im using for library Commented Mar 15, 2017 at 4:22
  • @GabeSpound I have been way more specific in my code now Commented Mar 15, 2017 at 5:06

1 Answer 1

1

The type of data that ChartSeries is expecting is an array of tuples where each tuple is two Floats. So, in this case, you don't need a grChartStruct type. This should compile:

   var chartArray = [(x: Float, y: Float)]()

        let bearishFloat = 1.1
        let bullishFloat = 0.0
        var xFloat = 0.0

        chartArray.append((xFloat, bearishFloatY))

     series = ChartSeries(data: chartArray)

However, I'm concerned by the reference to indexPath in the last line of your code snippet. Are you displaying a number of different charts in a UITableView?

Sign up to request clarification or add additional context in comments.

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.