public void SetNavigator(SfDateTimeRangeNavigator navigator, SfLineSparkline navigatorChart, string seriesName) { List <Point> source = seriesDictionary[seriesName]; navigator.ItemsSource = (List <Point>)source; navigator.XBindingPath = "X"; navigatorChart.ItemsSource = (List <Point>)source; navigatorChart.YBindingPath = "Y"; }
// get data and bind components private void cmdGetData(string _type, string _from, string _to) { try { string _urldata = ""; if (_type == "interval") { _urldata = _domain + "/e.aspx?json=1&dfrom=" + _from + "&dto=" + _to + _dasToken; } else if (_type == "latest") { _urldata = _domain + "/e.aspx?json=1&from=" + _from + "&to=" + _to + _dasToken; } WebRequest request = WebRequest.Create(_urldata); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); // txtResult.Text = (responseFromServer); reader.Close(); response.Close(); DataSet dataSet = JsonConvert.DeserializeObject <DataSet>(responseFromServer); DataTable dataTable = dataSet.Tables[0]; dataTable.DefaultView.Sort = "id ASC"; dataTable = dataTable.DefaultView.ToTable(); // rearange to the latest DataColumnCollection columns = dataTable.Columns; Data = new ObservableCollection <VitalData>(); BodyData = new ObservableCollection <BodyTemp>(); OxyData = new ObservableCollection <OxygenSaturation>(); HeartData = new ObservableCollection <BodyPulse>(); if (dataTable.Rows.Count < 1) { MessageBox.Show("No data available."); return; } int i = 0; foreach (DataRow row in dataTable.Rows) { foreach (DataColumn column in dataTable.Columns) { if (column.ColumnName == "AIDate") { if (i == dataTable.Rows.Count - 1) { lblLatestUpdate.Content = row[column].ToString(); DateTime now = DateTime.Now; DateTime updated = DateTime.Parse(row[column].ToString()).AddHours(-1); // server time is -1 hour CET TimeSpan updatespan = now.Subtract(updated); TimeSpan e5sec = TimeSpan.FromSeconds(5.0); lblInfo.Content = updatespan + " " + e5sec.ToString(); if (updatespan < e5sec) { lblStatusCrown.Content = "CROWN ON HEAD"; crownSign.Visibility = Visibility.Visible; imgHuman.Opacity = 1; } else { lblStatusCrown.Content = "CROWN NOT MOUNTED"; crownSign.Visibility = Visibility.Hidden; imgHuman.Opacity = 0.8; } } timestamp = DateTime.Parse(row[column].ToString()); } if (column.ColumnName == "TemperatureBody") { if (i == dataTable.Rows.Count - 1) { double tempVal = Convert.ToDouble(row[column].ToString()); cpbBodyTemp.Progress = Convert.ToDouble(tempVal); if (tempVal > 37.8) { lblTemperature.Content = "High temperature"; } else { lblTemperature.Content = "Normal temperature"; } // latestTemp = Convert.ToDouble(row[column].ToString()); } BodyData.Add(new BodyTemp() { Timestamp = timestamp, TempVal = Convert.ToDouble(row[column].ToString()) }); } if (column.ColumnName == "OxygenSaturation") { if (i == dataTable.Rows.Count - 1) { double oxyVal = Convert.ToDouble(row[column].ToString()); cpbBodyOxygen.Progress = Convert.ToDouble(oxyVal); if (oxyVal > 93) { lblSO2.Content = "Normal Oxygen"; } else { lblSO2.Content = "Low Oxygen"; } } OxyData.Add(new OxygenSaturation() { Timestamp = timestamp, OxygenVal = Convert.ToDouble(row[column].ToString()) }); } if (column.ColumnName == "HeartRate") { if (i == dataTable.Rows.Count - 1) { double pulseVal = Convert.ToDouble(row[column].ToString()); cpbBodyPulse.Progress = Convert.ToDouble(pulseVal); if (pulseVal > 160) { lblPulse.Content = "High Pulse"; } else if (pulseVal < 40) { lblPulse.Content = "Low Pulse"; } else { lblPulse.Content = "Normal Pulse"; } } HeartData.Add(new BodyPulse() { Timestamp = timestamp, PulseVal = Convert.ToDouble(row[column].ToString()) }); } } i += 1; } SparkGridTemp.Children.Clear(); SfLineSparkline sparkline = new SfLineSparkline() { ItemsSource = BodyData, YBindingPath = "TempVal", BandRangeStart = 38, BandRangeEnd = 41, RangeBandBrush = new SolidColorBrush(Colors.Red), MaximumYValue = 42, MinimumYValue = 34, ShowTrackBall = false }; this.SparkGridTemp.Children.Add(sparkline); SparkGridOxygen.Children.Clear(); SfLineSparkline sparklineOxy = new SfLineSparkline() { ItemsSource = OxyData, YBindingPath = "OxygenVal", BandRangeStart = 90, BandRangeEnd = 94, RangeBandBrush = new SolidColorBrush(Colors.Red), MaximumYValue = 90, MinimumYValue = 100, ShowTrackBall = false }; this.SparkGridOxygen.Children.Add(sparklineOxy); SparkGridHeart.Children.Clear(); SfLineSparkline sparklineHeart = new SfLineSparkline() { ItemsSource = HeartData, YBindingPath = "PulseVal", BandRangeStart = 140, BandRangeEnd = 180, RangeBandBrush = new SolidColorBrush(Colors.Red), MaximumYValue = 200, MinimumYValue = 40, ShowTrackBall = false }; this.SparkGridHeart.Children.Add(sparklineHeart); } catch (Exception e) { lblInfo.Content = e.Message.ToString(); } }
public Sparkline_Phone() { InitializeComponent(); var dataModel = new SparkViewModel(); stack.BindingContext = dataModel; area = new SfAreaSparkline { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; area.ItemsSource = dataModel.Datas; area.YBindingPath = "Performance"; areaLabel = new Label { Text = "Area", FontSize = 14, HorizontalOptions = LayoutOptions.Center, FontAttributes = FontAttributes.Bold }; stack.Children.Add(area); stack.Children.Add(areaLabel); line = new SfLineSparkline { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; line.ItemsSource = dataModel.Datas; line.YBindingPath = "Performance"; lineLabel = new Label { Text = "Line", FontSize = 14, HorizontalOptions = LayoutOptions.Center, FontAttributes = FontAttributes.Bold }; stack.Children.Add(line); stack.Children.Add(lineLabel); column = new SfColumnSparkline { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; column.ItemsSource = dataModel.ColumnDatas; column.YBindingPath = "YearPerformance"; columnLabel = new Label { Text = "Column", FontSize = 14, HorizontalOptions = LayoutOptions.Center, FontAttributes = FontAttributes.Bold }; stack.Children.Add(column); stack.Children.Add(columnLabel); winLoss = new SfWinLossSparkline { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; winLoss.ItemsSource = dataModel.ColumnDatas; winLoss.YBindingPath = "YearPerformance"; winLossLabel = new Label { Text = "Win/Loss", FontSize = 14, HorizontalOptions = LayoutOptions.Center, FontAttributes = FontAttributes.Bold }; stack.Children.Add(winLoss); stack.Children.Add(winLossLabel); if (Device.RuntimePlatform == Device.iOS) { stack.SizeChanged += Layout_SizeChanged; } else { area.Margin = new Thickness(0, 5, 0, 5); line.Margin = new Thickness(0, 5, 0, 5); column.Margin = new Thickness(0, 5, 0, 5); winLoss.Margin = new Thickness(0, 5, 0, 5); } }
public override View GetSampleContent(Context context) { var AreaData = new List <SparklineModel> { new SparklineModel { Value = 0.8 }, new SparklineModel { Value = 1.8 }, new SparklineModel { Value = 1.3 }, new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 1.6 }, new SparklineModel { Value = 2.0 }, new SparklineModel { Value = 1.7 }, new SparklineModel { Value = 2.3 }, new SparklineModel { Value = 2.7 }, new SparklineModel { Value = 2.3 }, new SparklineModel { Value = 1.9 }, new SparklineModel { Value = 1.4 }, new SparklineModel { Value = 1.2 }, new SparklineModel { Value = 0.8 }, }; var LineData = new List <SparklineModel> { new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 0.9 }, new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 1.3 }, new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 1.8 }, new SparklineModel { Value = 2.1 }, new SparklineModel { Value = 2.3 }, new SparklineModel { Value = 1.7 }, new SparklineModel { Value = 1.5 }, new SparklineModel { Value = 2.5 }, new SparklineModel { Value = 1.9 }, new SparklineModel { Value = 1.3 }, new SparklineModel { Value = 0.9 }, }; var ColumnData = new List <SparklineModel> { new SparklineModel { Value = 34 }, new SparklineModel { Value = -12 }, new SparklineModel { Value = 43 }, new SparklineModel { Value = 66 }, new SparklineModel { Value = 26 }, new SparklineModel { Value = 10 } }; var WinLossData = new List <SparklineModel> { new SparklineModel { Value = 34 }, new SparklineModel { Value = 23 }, new SparklineModel { Value = -31 }, new SparklineModel { Value = 0 }, new SparklineModel { Value = 26 }, new SparklineModel { Value = 44 } }; float width = context.Resources.DisplayMetrics.WidthPixels; float height = context.Resources.DisplayMetrics.HeightPixels; LayoutInflater layoutInflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService); View view = layoutInflater.Inflate(Resource.Layout.SfSparkline, null); lineSparkLine = new SfLineSparkline(context); columnSparkLine = new SfColumnSparkline(context); areaSparLine = new SfAreaSparkline(context); winLossSparkLine = new SfWinLossSparkline(context); int layoutPadding = 30; int topPadding = 80; TextView lineSparkLineLabel = new TextView(context); lineSparkLineLabel.Text = "Line"; lineSparkLineLabel.SetPadding(0, topPadding, 0, 0); lineSparkLineLabel.Typeface = Typeface.Create((Typeface)null, TypefaceStyle.Bold); lineSparkLineLabel.Gravity = GravityFlags.Center; TextView columnSparkLineLabel = new TextView(context); columnSparkLineLabel.Text = "Column"; columnSparkLineLabel.SetPadding(0, topPadding, 0, 0); columnSparkLineLabel.Typeface = Typeface.Create((Typeface)null, TypefaceStyle.Bold); columnSparkLineLabel.Gravity = GravityFlags.Center; TextView areaSparLineLabel = new TextView(context); areaSparLineLabel.Text = "Area"; areaSparLineLabel.SetPadding(0, topPadding, 0, 0); areaSparLineLabel.Typeface = Typeface.Create((Typeface)null, TypefaceStyle.Bold); areaSparLineLabel.Gravity = GravityFlags.Center; TextView winLossSparkLineLabel = new TextView(context); winLossSparkLineLabel.Text = "WinLoss"; winLossSparkLineLabel.SetPadding(0, topPadding, 0, 0); winLossSparkLineLabel.Typeface = Typeface.Create((Typeface)null, TypefaceStyle.Bold); winLossSparkLineLabel.Gravity = GravityFlags.Center; RelativeLayout lineSparkLineLayout = view.FindViewById <RelativeLayout>(Resource.Id.lineSparkLineLayout); lineSparkLineLayout.SetPadding(0, layoutPadding, 0, 0); lineSparkLineLayout.SetGravity(GravityFlags.Center); var lineParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height / 10); lineParams.AddRule(LayoutRules.AlignParentTop); lineSparkLine.LayoutParameters = lineParams; var lineLabelParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height); lineLabelParams.AddRule(LayoutRules.AlignBaseline, lineSparkLine.Id); lineSparkLineLabel.LayoutParameters = lineLabelParams; lineSparkLineLayout.AddView(lineSparkLine, lineParams); lineSparkLineLayout.AddView(lineSparkLineLabel, lineLabelParams); RelativeLayout columnSparkLineLayout = view.FindViewById <RelativeLayout>(Resource.Id.columnSparkLineLayout); columnSparkLineLayout.SetPadding(0, layoutPadding, 0, 0); columnSparkLineLayout.SetGravity(GravityFlags.Center); var columnParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height / 10); columnParams.AddRule(LayoutRules.AlignParentTop); columnSparkLine.LayoutParameters = columnParams; var columnLabelParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height); columnLabelParams.AddRule(LayoutRules.Below, columnSparkLine.Id); columnSparkLineLabel.LayoutParameters = columnLabelParams; columnSparkLineLayout.AddView(columnSparkLine, columnParams); columnSparkLineLayout.AddView(columnSparkLineLabel, columnLabelParams); RelativeLayout areaSparLineLayout = view.FindViewById <RelativeLayout>(Resource.Id.areaSparLineLayout); areaSparLineLayout.SetPadding(0, layoutPadding, 0, 0); areaSparLineLayout.SetGravity(GravityFlags.Center); var areaParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height / 10); areaParams.AddRule(LayoutRules.AlignParentTop); areaSparLine.LayoutParameters = areaParams; var areaLabelParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height); areaLabelParams.AddRule(LayoutRules.Below, areaSparLine.Id); areaSparLineLabel.LayoutParameters = areaLabelParams; areaSparLineLayout.AddView(areaSparLine, areaParams); areaSparLineLayout.AddView(areaSparLineLabel, areaLabelParams); RelativeLayout winLossSparkLineLayout = view.FindViewById <RelativeLayout>(Resource.Id.winLossSparkLineLayout); winLossSparkLineLayout.SetPadding(0, layoutPadding, 0, 0); winLossSparkLineLayout.SetGravity(GravityFlags.Center); var winLossParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height / 10); winLossParams.AddRule(LayoutRules.AlignParentTop); winLossSparkLine.LayoutParameters = winLossParams; var winLossLabelParams = new RelativeLayout.LayoutParams((int)width / 2, (int)height); winLossLabelParams.AddRule(LayoutRules.Below, winLossSparkLine.Id); winLossSparkLineLabel.LayoutParameters = winLossLabelParams; winLossSparkLineLayout.AddView(winLossSparkLine, winLossParams); winLossSparkLineLayout.AddView(winLossSparkLineLabel, winLossLabelParams); lineSparkLine.ItemsSource = LineData; lineSparkLine.YBindingPath = "Value"; lineSparkLine.Marker.Visibility = ViewStates.Visible; columnSparkLine.ItemsSource = ColumnData; columnSparkLine.YBindingPath = "Value"; areaSparLine.ItemsSource = AreaData; areaSparLine.YBindingPath = "Value"; areaSparLine.Marker.Visibility = ViewStates.Visible; winLossSparkLine.ItemsSource = WinLossData; winLossSparkLine.YBindingPath = "Value"; return(view); }
public Sparkline() { var AreaData = new List <SparklineModel> { new SparklineModel { Value = 0.8 }, new SparklineModel { Value = 1.8 }, new SparklineModel { Value = 1.3 }, new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 1.6 }, new SparklineModel { Value = 2.0 }, new SparklineModel { Value = 1.7 }, new SparklineModel { Value = 2.3 }, new SparklineModel { Value = 2.7 }, new SparklineModel { Value = 2.3 }, new SparklineModel { Value = 1.9 }, new SparklineModel { Value = 1.4 }, new SparklineModel { Value = 1.2 }, new SparklineModel { Value = 0.8 }, }; var LineData = new List <SparklineModel> { new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 0.9 }, new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 1.3 }, new SparklineModel { Value = 1.1 }, new SparklineModel { Value = 1.8 }, new SparklineModel { Value = 2.1 }, new SparklineModel { Value = 2.3 }, new SparklineModel { Value = 1.7 }, new SparklineModel { Value = 1.5 }, new SparklineModel { Value = 2.5 }, new SparklineModel { Value = 1.9 }, new SparklineModel { Value = 1.3 }, new SparklineModel { Value = 0.9 }, }; var ColumnData = new List <SparklineModel> { new SparklineModel { Value = 34 }, new SparklineModel { Value = 23 }, new SparklineModel { Value = -31 }, new SparklineModel { Value = 66 }, new SparklineModel { Value = 26 }, new SparklineModel { Value = 44 } }; var WinLossData = new List <SparklineModel> { new SparklineModel { Value = 24 }, new SparklineModel { Value = 32 }, new SparklineModel { Value = 14 }, new SparklineModel { Value = -29 }, new SparklineModel { Value = 33 }, new SparklineModel { Value = 44 } }; areaLabel = new UILabel(); areaLabel.Text = "Area"; areaLabel.Font = UIFont.FromName("HelveticaNeue-Bold", 13f); areaLabel.TextAlignment = UITextAlignment.Center; lineLabel = new UILabel(); lineLabel.Text = "Line"; lineLabel.Font = UIFont.FromName("HelveticaNeue-Bold", 13f); lineLabel.TextAlignment = UITextAlignment.Center; columnLabel = new UILabel(); columnLabel.Text = "Column"; columnLabel.Font = UIFont.FromName("HelveticaNeue-Bold", 13f); columnLabel.TextAlignment = UITextAlignment.Center; winLossLabel = new UILabel(); winLossLabel.Text = "WinLoss"; winLossLabel.Font = UIFont.FromName("HelveticaNeue-Bold", 13f); winLossLabel.TextAlignment = UITextAlignment.Center; area = new SfAreaSparkline(); //area.Marker = new SparklineMarker() { IsVisible = true, Color= UIColor.Clear }; area.ItemsSource = AreaData; area.YBindingPath = "Value"; area.StrokeColor = UIColor.FromRGB(166.0f / 255.0f, 173.0f / 255.0f, 134.0f / 255.0f); //area.HighPointColor = UIColor.Green; //area.LowPointColor = UIColor.Red; area.Color = UIColor.FromRGBA(166.0f / 255.0f, 173.0f / 255.0f, 134.0f / 255.0f, 0.5f); line = new SfLineSparkline(); //line.Marker = new SparklineMarker() { IsVisible = true, Color = UIColor.Clear }; line.ItemsSource = LineData; line.StrokeColor = UIColor.FromRGB(166.0f / 255.0f, 173.0f / 255.0f, 134.0f / 255.0f); //line.HighPointColor = UIColor.Green; //line.LowPointColor = UIColor.Red; line.YBindingPath = "Value"; column = new SfColumnSparkline(); column.ItemsSource = ColumnData; column.YBindingPath = "Value"; column.Color = UIColor.FromRGB(86.0f / 255.0f, 140.0f / 255.0f, 233.0f / 255.0f); column.FirstPointColor = UIColor.FromRGB(86.0f / 255.0f, 140.0f / 255.0f, 233.0f / 255.0f); column.LastPointColor = UIColor.FromRGB(86.0f / 255.0f, 140.0f / 255.0f, 233.0f / 255.0f); column.HighPointColor = UIColor.FromRGBA(166.0f / 255.0f, 173.0f / 255.0f, 134.0f / 255.0f, 0.9f); column.LowPointColor = UIColor.FromRGB(252.0f / 255.0f, 98.0f / 255.0f, 93.0f / 255.0f); winLoss = new SfWinLossSparkline(); winLoss.ItemsSource = WinLossData; winLoss.YBindingPath = "Value"; winLoss.Color = UIColor.FromRGB(86.0f / 255.0f, 140.0f / 255.0f, 233.0f / 255.0f); winLoss.FirstPointColor = UIColor.FromRGB(86.0f / 255.0f, 140.0f / 255.0f, 233.0f / 255.0f); winLoss.LastPointColor = UIColor.FromRGB(86.0f / 255.0f, 140.0f / 255.0f, 233.0f / 255.0f); winLoss.HighPointColor = UIColor.FromRGBA(166.0f / 255.0f, 173.0f / 255.0f, 134.0f / 255.0f, 0.9f); winLoss.LowPointColor = UIColor.FromRGB(252.0f / 255.0f, 98.0f / 255.0f, 93.0f / 255.0f);; winLoss.NeutralPointsColor = UIColor.FromRGB(86.0f / 255.0f, 140.0f / 255.0f, 233.0f / 255.0f); this.AddSubview(areaLabel); this.AddSubview(lineLabel); this.AddSubview(columnLabel); this.AddSubview(winLossLabel); this.AddSubview(area); this.AddSubview(line); this.AddSubview(column); this.AddSubview(winLoss); }