// Method for making the chart based on the data and user input private PlotModel Chartmaker(string inhoud, int maand, string mastr) { new Thread(new ThreadStart(Getdata)).Start(); // Filtering the Bike containers AdaptedList <BikeContainer> Fietstrommels2 = FietsTrommels.Filter(element => element.Deelgemeente == inhoud.ToLower()); // Filtering the Theft AdaptedList <Theft> FietsDiefstal2 = FietsDiefstal.Filter(element => element.Neighbourhood == inhoud.ToLower()); AdaptedList <Month> months = this.dataFactory.CreateMonths(new AdaptedList <DateTime>(FietsDiefstal2.Map <DateTime>(e => e.Date).OrderBy(e => e.Date).ToList()), false); months = months.Filter(item => item.GetMonth == maand); //Making arrays int[] bak = new int[] { Fietstrommels2.Count }; int[] thefts = new[] { months[0].EventsThisMonth }; string[] xas = new[] { Extensions.FirstCharToUpper("Bike thefts in " + Fietstrommels2[0].Deelgemeente + " for the month " + mastr) }; //Making a chart PlotModel model = GraphMaker.Mutiplebarschartmaker(bak, thefts, "Fietstrommels", "Diefstallen"); model = GraphMaker.Axisdecorator(model, xas, false); return(model); }
public AdaptedList <Month> CreateMonths(AdaptedList <DateTime> Dates, bool splitYears) { AdaptedList <Month> SortedMonths = new AdaptedList <Month>(); Predicate <Month> Predicate; //e => (e.GetYear == date.Year) && (e.GetMonth == date.Month) foreach (DateTime date in Dates) { if (splitYears) { Predicate = e => (e.GetYear == date.Year) && (e.GetMonth == date.Month); } else { Predicate = e => (e.GetMonth == date.Month); } // Temporary filtered list to check if the month already exists. AdaptedList <Month> PredicateMonthList = SortedMonths.Filter(Predicate); if (PredicateMonthList.Count == 0) { SortedMonths.Add(new Month(date, 1)); } else if (PredicateMonthList.Count == 1) { PredicateMonthList[0].EventsThisMonth += 1; } else { break; } } return(SortedMonths); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.BarPage); plotViewModel = FindViewById <PlotView>(Resource.Id.plotViewModel); mLLayoutModel = FindViewById <LinearLayout>(Resource.Id.linearLayoutModel); AdaptedList <BikeContainer> FietsTrommels = DataFactory.GetBikeContainers(); string[] neighbourhoods = new string[] { "noord", "delfshaven", "centrum", "feijenoord", "kralingen" }; int[] CountsPerNeighbourhood = new int[5]; for (int i = 0; i < neighbourhoods.Length; i++) { CountsPerNeighbourhood[i] = FietsTrommels.Filter( item => item.Deelgemeente == neighbourhoods[i] ).Count; neighbourhoods[i] = Extensions.FirstCharToUpper(neighbourhoods[i]); } plotModel = Core.GraphMaker.Barchartmaker(CountsPerNeighbourhood, colors); //Makes the axes unscrollable. Do not use with pie-chart! plotModel = Core.GraphMaker.Axisdecorator(plotModel, neighbourhoods, false); //Adding a legend (Optional) Best use with Pie chart. //mLLayoutModel = Core.GraphMaker.Legendamaker(colors, this, modelAllocations, mLLayoutModel, 150); //Adding the model to the view MyModel = plotModel; plotViewModel.Model = MyModel; }
private void GetData() { // Getting BikeTheft data from the database. if (TheftDates == null) { InvokeUI(() => Toast.MakeText(Application.Context, "Graph is loading...", ToastLength.Long).Show()); TheftDates = dataFactory.GetBikeThefts().Map <DateTime>(e => new DateTime(e.Date.Year, e.Date.Month, 1)); TheftDates = TheftDates.Filter(e => e > new DateTime(2011, 1, 1) && e < DateTime.Now); } // For sparing memory, we clear the Theftlist. IDataProcessor <PlotModel> LineChart = new LineChartBuilder(ref TheftDates); Model = LineChart.GetProcessedData(); InvokeUI(() => this.plotView.Model = Model); }