title: How to display json data in line chart using swift
body: <p>I am a newcomer to the ios app, and I am currently designing an app that reads json data.
  The current design challenge is that the json data is captured. I don't know how to use the "Charts" library to create a line chart to display json data.</p>
  
  <p>At the moment, I just simply transferred json to an array.</p>
  
  <pre><code>@objc func getlatestTh_5min(){
        guard let th_5minUrl = URL(string: kivaLoanURl) else{
            return
        }
  
        let request = URLRequest(url: th_5minUrl)
        let task = URLSession.shared.dataTask(with: request, completionHandler: {(data,response,error) -&gt; Void in
  
            if let error = error {
                print(error)
                return
            }
            if let data = data {
                self.th_5mins = self.pardrJsonData(data: data)
            }
        })
        task.resume()
    }
    func pardrJsonData(data: Data) -&gt; [Th_5min]{
        var th_5mins = [Th_5min]()
        do {
            let jsonResult = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as? NSDictionary
  
            let jsonTh_5mins = jsonResult?["TH_5min"] as! [AnyObject]
            for jsonTh_5min in jsonTh_5mins{
                var th_5min = Th_5min()
                th_5min.XTP_A = jsonTh_5min["XTP_A"] as! Double
               // th_5min.XHP_A = jsonTh_5min["XHP_A"] as! Double
                th_5min.XTP_B = jsonTh_5min["XTP_B"] as! Double
               // th_5min.XHP_B = jsonTh_5min["XHP_B"] as! Double
                th_5min.XTP_C = jsonTh_5min["XTP_C"] as! Double
                //th_5min.XHP_C = jsonTh_5min["XHP_C"] as! Double
                th_5min.XTP_D = jsonTh_5min["XTP_D"] as! Double
                //th_5min.XHP_D = jsonTh_5min["XHP_D"] as! Double
                th_5min.XTP_E = jsonTh_5min["XTP_E"] as! Double
                //th_5min.XHP_E = jsonTh_5min["XHP_E"] as! Double
                //alarm_event.Al_Message = jsonAlarm_Event["Al_Message"] as! String
  
                th_5mins.append(th_5min)
            }        }catch{
                print(error)
        }
        return th_5mins
    }
  </code></pre>
  
  <p>I want to display the json data using the line chart, but I don't know how to start.</p>
  
  <p><a href="https://i.stack.imgur.com/goTZ4.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>This is my json data from website</p>
  
  <pre><code>{
  TH_5min: [
  {
  Data: "2019-02-23T00:00:00",
  Time: "11:00:00",
  XTP_A: 10.5,
  XHP_A: 11.5,
  XTP_B: 33.5,
  XHP_B: 44.6,
  XTP_C: 88.9,
  XHP_C: 66.6,
  XTP_D: 77.9,
  XHP_D: 99.6,
  XTP_E: 87.87,
  XHP_E: 66.66
  },
  {
  Data: "2019-02-23T00:00:00",
  Time: "11:05:00",
  XTP_A: 55.2,
  XHP_A: 44.3,
  XTP_B: 66.6,
  XHP_B: 77.87,
  XTP_C: 87.77,
  XHP_C: 87.87,
  XTP_D: 8.87,
  XHP_D: 78.78,
  XTP_E: 87.78,
  XHP_E: 87.87
  }
  ]
  }
  </code></pre>