Injecting data into different series.Index


#1

I am pulling data from a JSON file.
Against any given date are four separate items of data that I want to display separately, on the same chart.
Taking the time series example supplied by Shinobi how do I inject the data into multiple series.Index rather than just one.
The code below, apart from being inelligent, doesn’t work and I can’t quite fathom the data data structure Shinobi requires to separate the data against each series.

    func loadChartData() {
         // Create volume and stock price data points from JSON data
         for dataPoint inJSONDataFromFile("AppleData") {
             guardlet
                 dateString = dataPoint["date"] as? String,
                 stockOpen  = dataPoint["open"] as? NSNumber,
                 stockHigh  = dataPoint["high"] as? NSNumber,
                 stockLow   = dataPoint["low"] as? NSNumber,
                 stockClose = dataPoint["close"] as? NSNumber 
                 else {
                     print("Malformed JSON data")
                     return
             }
             let date = dateFormatter.dateFromString(dateString)
             let stockDataPoint = SChartDataPoint()
             stockDataPoint.sChartDataPointIndex = 0
             stockDataPoint.xValue = date
             stockDataPoint.yValue = stockClose
             stockPriceData.append(stockDataPoint)
             stockDataPoint.sChartDataPointIndex = 1
             stockDataPoint.xValue = date
             stockDataPoint.yValue = stockOpen
             stockPriceData.append(stockDataPoint)
             stockDataPoint.sChartDataPointIndex = 2
             stockDataPoint.xValue = date
             stockDataPoint.yValue = stockHigh
             stockPriceData.append(stockDataPoint)
             stockDataPoint.sChartDataPointIndex = 3
             stockDataPoint.xValue = date
             stockDataPoint.yValue = stockLow
             stockPriceData.append(stockDataPoint)
         }
    }

#2

Hi Ed,

As you know I’ve already responded to your ticket. However for the benefit of anyone who might read this post here was my response.

From reading your issue I’m gathering you’re looking to stream multiple series at the same time. I would recommend you take a look at the AppendData sample available with the regular charts download. This demonstrates how to stream with one series. In order to get it to work for multiple series you need to change the number of series in numberOfSeriesInSChart to however many you are after. You’ll then need to manage the data points being appended and prepended from your datasource in the same way it is done for the first series within the appendData sample.

Kind regards,

Matt / iOS Developer