async void OnFetchDataTap(object sender, EventArgs e) { InitialiseChart(); BTProgressHUD.Show("Fetching data"); var data = await GetDataAsync(); // set data source var barSeriesSource = new IGCategorySeriesDataSourceHelper(); barSeriesSource.Values = data.ProductSales.ToArray(); barSeriesSource.Labels = data.ProductName.ToArray(); // Create axis types and add it to the chart var xAxisBar = new IGNumericXAxis("xAxis"); var yAxisBar = new IGCategoryYAxis("yAxis"); yAxisBar.LabelAlignment = IGHorizontalAlign.IGHorizontalAlignRight; chart.AddAxis(xAxisBar); chart.AddAxis(yAxisBar); // decide on what series need to be displayed on the chart var barSeries = new IGBarSeries("series"); barSeries.XAxis = xAxisBar; barSeries.YAxis = yAxisBar; // set the appropriate data sources barSeries.DataSource = barSeriesSource; chart.AddSeries(barSeries); BTProgressHUD.Dismiss(); }
public override void ViewDidLoad() { base.ViewDidLoad(); _chart = new IGChartView(new RectangleF(this.View.Frame.X, 30, this.View.Frame.Width, this.View.Frame.Height - 40)); _chart.Delegate = new CustomDelegate(); _chart.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth; var xAxis = new IGCategoryXAxis("xAxis"); var yAxis = new IGNumericYAxis("yAxis"); _chart.AddAxis(xAxis); _chart.AddAxis(yAxis); yAxis.Minimum = 0; var columnSeries = new IGAreaSeries("columnSeries"); columnSeries.XAxis = xAxis; columnSeries.YAxis = yAxis; SetDataSourceOnSeries(columnSeries); _chart.AddSeries(columnSeries); ViewModel.DataPoints.Changed.ObserveOn(RxApp.MainThreadScheduler).Subscribe(p => SetDataSourceOnSeries(columnSeries)); _invalidInputsLabel = new UILabel(new RectangleF(this.View.Frame.X + 60, 40, this.View.Frame.Width - 60, this.View.Frame.Height - 40)); _invalidInputsLabel.Lines = 0; _invalidInputsLabel.LineBreakMode = UILineBreakMode.WordWrap; _invalidInputsLabel.Text = ViewModel.InvalidInputsMessage; _invalidInputsLabel.TextAlignment = UITextAlignment.Left; this.View.AddSubview(_invalidInputsLabel); this.View.AddSubview(_chart); Action assignVisibility = () => { _invalidInputsLabel.Hidden = ViewModel.HasValidInputs; _chart.Hidden = !ViewModel.HasValidInputs; }; assignVisibility(); ViewModel.WhenAnyValue(p => p.HasValidInputs) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(p => assignVisibility()); }