0

Finding data on chart

The user will make data inputs in textfield which meets x and y axis. Is there a way to take these two inputs and find their interaection on existing line chart and tell the user if that intersection is over or below that line chart line?

1st Dec 2018, 10:44 AM
Murat
Murat - avatar
18 Réponses
+ 7
y axis 4 + 3 2 x 1 + 0 Jan Feb March x axis Assume above line chart with (Feb,2) marked already Now if any value comes like (Feb,4) or (Feb,1) You just need to compare values of y with original to tell if above or below // Assuming x is discrete
1st Dec 2018, 11:22 AM
Rstar
Rstar - avatar
+ 6
You can share via Google Drive or copy paste code on Sololearn playground and save it . Then link it here. By the way what on your x axis and y axis?
10th Dec 2018, 5:54 AM
Rstar
Rstar - avatar
+ 5
If user enters between 1-2 still you can compare But I don't understand what is between Feb and March?(What value is between Feb and March) Feb month represent all values in month of Feb I.e from 1-28
9th Dec 2018, 3:28 PM
Rstar
Rstar - avatar
+ 5
Can you make docs public
11th Dec 2018, 5:37 AM
Rstar
Rstar - avatar
+ 1
thank you but i already read this, the thing i am trying to do is finding data on line chart not making a new chart. there is a line chart and user will enter data which represents x an y axis then ios will mark and tell if the intersection of these two datas is over or below the chart
1st Dec 2018, 11:09 AM
Murat
Murat - avatar
+ 1
thank you i’ll try it
1st Dec 2018, 11:58 AM
Murat
Murat - avatar
+ 1
on x axis theres hours beginnin from 0 to 166 increasing by 12, and on y axis theres numbers from 0 to 21 increasing by 1. x axis = 0, 12, 24...166 y axis = 0,1,2...21 the problem is if the input in x axis is 13 and in y axis is 1.2 how am i gonna calculate the intersection of these two and tell the user if it is over or below the line chart
10th Dec 2018, 8:21 AM
Murat
Murat - avatar
+ 1
which command line will i use? first i suppouse it can be solved with an if statement but i cant
10th Dec 2018, 8:33 AM
Murat
Murat - avatar
+ 1
i am a pediatrician and i am at hospital right now, but when i get home i’ll share the code and also the chart Rstar thank you so much for your responses
10th Dec 2018, 9:00 AM
Murat
Murat - avatar
+ 1
sure, i did it now
11th Dec 2018, 9:12 AM
Murat
Murat - avatar
0
still couldnt manage to do because it is ok if the user selects (Feb,1) or (Feb,4) but what if selects values between Feb and March and between 1-2. e.g (Feb8, 1.2) and additin to these should i use the if statement to declare it or sth else
9th Dec 2018, 7:25 AM
Murat
Murat - avatar
0
i wanna show my code but i dont know how to post in here
9th Dec 2018, 3:58 PM
Murat
Murat - avatar
0
so i can ask more clearly
9th Dec 2018, 3:58 PM
Murat
Murat - avatar
0
Created a textfield and a date picker textfield data matches the y axis and the date picker value is amount of hours calculated by ios using birthdate matches x axis Code below is for generating chart @IBAction func displayChart(_ sender: Any) { let chartConfig = ChartConfigXY( xAxisConfig: ChartAxisConfig(from: 0, to:192 , by: 24), yAxisConfig: ChartAxisConfig(from: 0, to: 22, by: 1) ) let frame = CGRect(x: 10, y: 200, width: self.view.frame.width-50, height: 400) let chart = LineChart(frame: frame, chartConfig: chartConfig, xTitle: "Postnatal Yaş Saat", yTitle: "Total Bilirubin mg/dl" , lines: [ (chartPoints:[(0, 4.0), (12, 6.0), (24, 8.0), (36, 9.5), (48, 11.0), (60, 12.5), (72, 13.5), (84, 14.0), (96, 14.5), (108, 14.9), (120, 15.0), (132, 15.0), (144, 15.0), (156, 15.0), (168, 15.0)], color: UIColor.red), (chartPoints:[(0, 5.0), (12, 7.5), (24, 10.0), (36, 11.8), (48, 13.0), (60, 14.5), (72, 15.1), (84, 16.4), (96, 17.1), (108, 18.0), (120, 18.0), (120, 18.0), (132, 18.0), (144, 18.0), (156, 18.0), (168, 18.0)], color : UIColor.blue), (chartPoints:[(0, 6.5), (12, 9.0), (24, 11.5), (36, 13.5), (48, 15.0), (60, 16.5), (72, 17.5), (84, 19.0), (96, 20.0), (108, 20.5), (120, 21.0), (132, 21.0), (144, 21.0), (156, 21.0), (168, 21.0)], color: UIColor.green) ]) self.view.addSubview(chart.view) self.pttChartView = chart
10th Dec 2018, 1:38 PM
Murat
Murat - avatar
0
code for date picker func createDatePicker(){ postNatalAgeTextField.inputView = datePicker let toolbar = UIToolbar() toolbar.sizeToFit() let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: #selector (doneClicked)) toolbar.setItems([doneButton], animated: true) postNatalAgeTextField.inputAccessoryView = toolbar } @objc func doneClicked(){ self.view.endEditing(true) let birthDate = self.datePicker.date let today = Date() let calendar = Calendar.current let components = calendar.dateComponents([.hour], from: birthDate, to: today) let ageHours = components.hour let dateFormatter = DateFormatter() dateFormatter.dateStyle = .medium dateFormatter.timeStyle = .short dateFormatter.locale = Locale(identifier: "tr") postNatalAgeTextField.text = dateFormatter.string(from: datePicker.date) self.postNatalAgeLabel.text = "\(ageHours!) saat" if birthDate >= today{ let alertView = UIAlertController(title: "Hata!", message: "Lütfen geçerli bir doğum tarihi giriniz. ", preferredStyle: .alert) let action = UIAlertAction(title: "Tamam", style: .default, handler: nil) alertView.addAction(action) self.present(alertView, animated: false, completion: nil) return }
10th Dec 2018, 1:40 PM
Murat
Murat - avatar
0
And the textfield for y axis override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { self.view.endEditing(true) } func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() return true } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { guard let oldText = textField.text, let r = Range(range, in: oldText) else { return true } let newText = oldText.replacingCharacters(in: r, with: string) let isNumeric = newText.isEmpty || (Double(newText) != nil) let numberOfDots = newText.components(separatedBy: ".").count - 1 let numberOfDecimalDigits: Int if let dotIndex = newText.index(of: ".") { numberOfDecimalDigits = newText.distance(from: dotIndex, to: newText.endIndex) - 1 } else { numberOfDecimalDigits = 0 } return isNumeric && numberOfDots <= 1 && numberOfDecimalDigits <= 2 }
10th Dec 2018, 1:41 PM
Murat
Murat - avatar
0
https://docs.google.com/document/d/1j5Pf7vyknX3FdQxQRGcxk5wQcsMpenxn_rJq_VRnFGQ/edit This is the linechart. Please help me with the code to find the inputs' intersection. x axis is hours, y axis is serum bilirubin level. If the number in the textfield, is 5.2, and hours is 11 how swift will find and tell the intersection.
10th Dec 2018, 6:12 PM
Murat
Murat - avatar