/// <summary> /// Executes the chart demo. /// </summary> /// <param name="context"> the context </param> /// <returns> the built intent </returns> public override Intent Execute(Context context) { string[] titles = new string[] { "2007", "2008" }; IList <double[]> values = new List <double[]>(); values.Add(new double[] { 5230, 7300, 9240, 10540, 7900, 9200, 12030, 11200, 9500, 10500, 11600, 13500 }); values.Add(new double[] { 14230, 12300, 14240, 15244, 15900, 19200, 22030, 21200, 19500, 15500, 12600, 14000 }); int[] colors = new int[] { Color.Cyan, Color.Blue }; XYMultipleSeriesRenderer renderer = BuildBarRenderer(colors); renderer.SetOrientation(XYMultipleSeriesRenderer.Orientation.Vertical); SetChartSettings(renderer, "Monthly sales in the last 2 years", "Month", "Units sold", 0.5, 12.5, 0, 24000, Color.Gray, Color.LightGray); renderer.XLabels = 1; renderer.YLabels = 10; renderer.AddXTextLabel(1, "Jan"); renderer.AddXTextLabel(3, "Mar"); renderer.AddXTextLabel(5, "May"); renderer.AddXTextLabel(7, "Jul"); renderer.AddXTextLabel(10, "Oct"); renderer.AddXTextLabel(12, "Dec"); int length = renderer.SeriesRendererCount; for (int i = 0; i < length; i++) { SimpleSeriesRenderer seriesRenderer = renderer.GetSeriesRendererAt(i); seriesRenderer.DisplayChartValues = true; } return(ChartFactory.GetBarChartIntent(context, BuildBarDataset(titles, values), renderer, global::AChartEngine.Charts.BarChart.Type.Default)); }
public override Android.Content.Intent Execute(Android.Content.Context context) { double[] minValues = new double[] { -24, -19, -10, -1, 7, 12, 15, 14, 9, 1, -11, -16 }; double[] maxValues = new double[] { 7, 12, 24, 28, 33, 35, 37, 36, 28, 19, 11, 4 }; XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); RangeCategorySeries series = new RangeCategorySeries("Temperature"); int length = minValues.Length; for (int k = 0; k < length; k++) { series.Add(minValues[k], maxValues[k]); } dataset.AddSeries(series.ToXYSeries()); int[] colors = new int[] { Color.Cyan }; XYMultipleSeriesRenderer renderer = BuildBarRenderer(colors); SetChartSettings(renderer, "Monthly temperature range", "Month", "Celsius degrees", 0.5, 12.5, -30, 45, Color.Gray, Color.LightGray); renderer.BarSpacing = 0.5; renderer.XLabels = 0; renderer.YLabels = 10; renderer.AddXTextLabel(1, "Jan"); renderer.AddXTextLabel(3, "Mar"); renderer.AddXTextLabel(5, "May"); renderer.AddXTextLabel(7, "Jul"); renderer.AddXTextLabel(10, "Oct"); renderer.AddXTextLabel(12, "Dec"); renderer.AddYTextLabel(-25, "Very cold"); renderer.AddYTextLabel(-10, "Cold"); renderer.AddYTextLabel(5, "OK"); renderer.AddYTextLabel(20, "Noci"); renderer.SetMargins(new int[] { 30, 70, 10, 0 }); renderer.SetYLabelsAlign(Android.Graphics.Paint.Align.Right); SimpleSeriesRenderer r = renderer.GetSeriesRendererAt(0); r.DisplayChartValues = true; r.ChartValuesTextSize = 12; r.ChartValuesSpacing = 3; r.GradientEnabled = true; r.SetGradientStart(-20, Color.Blue); r.SetGradientStop(20, Color.Green); return(ChartFactory.GetRangeBarChartIntent(context, dataset, renderer, BarChart.Type.Default, "Temperatur range")); }
private void openChart() { int[] x = { 0, 1, 2, 3, 4, 5, 6, 7 }; int[] income = { 2000, 2500, 2700, 3000, 2800, 3500, 3700, 3800 }; int[] expense = { 2200, 2700, 2900, 2800, 2600, 3000, 3300, 3400 }; // Creating an XYSeries for Income XYSeries incomeSeries = new XYSeries("Income"); // Creating an XYSeries for Expense XYSeries expenseSeries = new XYSeries("Expense"); // Adding data to Income and Expense Series for (int i = 0; i < x.Length; i++) { incomeSeries.Add(i, income[i]); expenseSeries.Add(i, expense[i]); } // Creating a dataset to hold each series XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); // Adding Income Series to the dataset dataset.AddSeries(incomeSeries); // Adding Expense Series to dataset dataset.AddSeries(expenseSeries); // Creating XYSeriesRenderer to customize incomeSeries XYSeriesRenderer incomeRenderer = new XYSeriesRenderer(); incomeRenderer.Color = Color.Rgb(130, 130, 230); incomeRenderer.FillPoints = true; incomeRenderer.LineWidth = 2; incomeRenderer.DisplayChartValues = true; // Creating XYSeriesRenderer to customize expenseSeries XYSeriesRenderer expenseRenderer = new XYSeriesRenderer(); expenseRenderer.Color = Color.Rgb(220, 80, 80); expenseRenderer.FillPoints = true; expenseRenderer.LineWidth = 2; expenseRenderer.DisplayChartValues = true; // Creating a XYMultipleSeriesRenderer to customize the whole chart XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer(); multiRenderer.XLabels = 0; multiRenderer.ChartTitle = "Income vs Expense Chart"; multiRenderer.XTitle = "Year 2012"; multiRenderer.YTitle = "Amount in Dollars"; multiRenderer.ZoomButtonsVisible = true; multiRenderer.BackgroundColor = Color.Transparent; for (int i = 0; i < x.Length; i++) { multiRenderer.AddXTextLabel(i, mMonth[i]); } // Adding incomeRenderer and expenseRenderer to multipleRenderer // Note: The order of adding dataseries to dataset and renderers to multipleRenderer // should be same multiRenderer.AddSeriesRenderer(incomeRenderer); multiRenderer.AddSeriesRenderer(expenseRenderer); // Creating an intent to plot bar chart using dataset and multipleRenderer Intent intent = ChartFactory.GetBarChartIntent(this, dataset, multiRenderer, BarChart.Type.Default); // Start Activity StartActivity(intent); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Chart); db = new DataDB(this); mDataSet.AddSeries(SeriesCreate("DataOne")); mDataSet.AddSeries(SeriesCreate("DataTwo")); mDataSet.AddSeries(SeriesCreate("DataThree")); XYSeriesRenderer renderOne = singleRenderer(255, 000, 000); XYSeriesRenderer renderTwo = singleRenderer(000, 255, 000); XYSeriesRenderer renderThree = singleRenderer(000, 000, 255); mRenderer.SetMargins(new int[] { 10, 60, 100, 30 }); mRenderer.XLabels = 0; mRenderer.ChartTitle = "Data Chart"; mRenderer.XTitle = "UserID"; mRenderer.YTitle = "Data Inputs"; mRenderer.AxisTitleTextSize = 32; mRenderer.ChartTitleTextSize = 40; mRenderer.LabelsTextSize = 32; mRenderer.PointSize = 3; mRenderer.ShowLegend = false; mRenderer.ShowGridX = true; mRenderer.ShowGridY = true; mRenderer.ZoomButtonsVisible = true; mRenderer.ApplyBackgroundColor = true; mRenderer.AxesColor = Color.Black; mRenderer.LabelsColor = Color.Black; mRenderer.MarginsColor = Color.White; mRenderer.GridColor = Color.Black; mRenderer.SetYLabelsColor(0, Color.Black); mRenderer.XLabelsColor = Color.Black; mRenderer.BackgroundColor = Color.White; for (int i = 0; i < db.Count(); i++) { mRenderer.AddXTextLabel(i, db.readPrimary("UserID", i)); } mRenderer.AddSeriesRenderer(renderOne); mRenderer.AddSeriesRenderer(renderTwo); mRenderer.AddSeriesRenderer(renderThree); if (mChartView == null) { chartLayout = FindViewById <LinearLayout>(Resource.Id.chart); mChartView = ChartFactory.GetLineChartView(this, mDataSet, mRenderer); chartLayout.AddView(mChartView, new LinearLayout.LayoutParams( Android.Views.ViewGroup.LayoutParams.FillParent, Android.Views.ViewGroup.LayoutParams.FillParent)); } listView = FindViewById <ListView>(Resource.Id.DataList); tableItems.Add(new TableItem() { DataName = "DataOne", ID = 9001, Red = 255, Green = 000, Blue = 000 }); tableItems.Add(new TableItem() { DataName = "DataTwo", ID = 9002, Red = 000, Green = 255, Blue = 000 }); tableItems.Add(new TableItem() { DataName = "DataThree", ID = 9003, Red = 000, Green = 000, Blue = 255 }); listView.Adapter = new ChartActivityAdapter(this, tableItems); btnSave = FindViewById <Button>(Resource.Id.btnSave); btnSave.Click += BtnSave_Click; }