Пример #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            BarChart barChart = new BarChart(this);

            barChart.LayoutParameters = new Android.Views.ViewGroup.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
            var flag = new string[] { "First Bar,Second Bar", "93,93.15" };

            //--this is response
            string[] strDate   = flag[0].ToString().Split(',');
            string[] strValues = flag[1].ToString().Split(',');

            List <BarEntry> entries = new List <BarEntry>();

            for (int i = 0; i < strValues.Length; i++)
            {
                entries.Add(new BarEntry(float.Parse(strValues[i]), i));
            }

            BarDataSet dataset = new BarDataSet(entries, "");

            dataset.ValueTextSize = 15.0f;

            List <string> labels = new List <string>();

            for (int i = 0; i < strDate.Length; i++)
            {
                labels.Add(strDate[i].ToString());
            }

            BarData data = new BarData(labels, dataset);

            barChart.Data = data;
            barChart.SetDescription("");

            barChart.NotifyDataSetChanged();
            barChart.Invalidate();
            var root = FindViewById <LinearLayout>(Resource.Id.root);

            root.AddView(barChart);
        }
        private void setData(int count, float range)
        {
            float start = 1f;

            List <BarEntry> yVals1 = new List <BarEntry>();

            for (int i = (int)start; i < start + count + 1; i++)
            {
                float mult = (range + 1);
                //random data
                float val = (float)(Java.Lang.Math.Random() * mult);
                yVals1.Add(new BarEntry(i, val));
            }

            BarDataSet set1;

            if (mChart.Data != null && mChart.BarData.DataSetCount > 0)
            {
                set1        = (BarDataSet)mChart.BarData.GetDataSetByIndex(0);
                set1.Values = yVals1;
                mChart.BarData.NotifyDataChanged();
                mChart.NotifyDataSetChanged();

                mChart.BarData.AddDataSet(set1);
            }
            else
            {
                set1 = new BarDataSet(yVals1, "2017");

                List <MikePhil.Charting.Interfaces.Datasets.IBarDataSet> dataSets = new List <MikePhil.Charting.Interfaces.Datasets.IBarDataSet>();

                dataSets.Add(set1);
                BarData data = new BarData(dataSets);

                dataSets.Add(set1);
                mChart.Data = data;
            }
        }