Пример #1
0
        private RadarChartData GetRadarChartDataFromUserProfileList(List <TestUserProfile> userProfileList, List <string> hometownList)
        {
            RadarChartData            radarChartData = new RadarChartData();
            List <RadarChartUserData> userDataList   = new List <RadarChartUserData>();

            foreach (string hometown in hometownList)
            {
                RadarChartUserData userData = new RadarChartUserData();

                List <TestUserProfile> residentList = userProfileList.Where(user => user.Hometown == hometown).ToList();
                userData.Hometown    = hometown;
                userData.Count       = residentList.Count;
                userData.ProfileList = new List <TestUserProfile>();
                foreach (TestUserProfile resident in residentList)
                {
                    userData.ProfileList.Add(resident);
                }

                userDataList.Add(userData);
            }

            // Generate Schema
            foreach (RadarChartUserData data in userDataList)
            {
                data.GenerateUserProfileSchema();
            }

            radarChartData.HometownList = hometownList;
            radarChartData.UserData     = userDataList;

            return(radarChartData);
        }
Пример #2
0
        public HttpResponseMessage DrawMultiRadarChart()
        {
            RadarChart[] charts = new RadarChart[2];

            charts[0]             = new Models.RadarChart();
            charts[0].name        = "set1";
            charts[0].fillColor   = "#f15c80";
            charts[0].borderColor = "#8085e9";

            charts[0].points = new List <Point> {
                new Point {
                    x = "Rome", y = "42"
                }, new Point {
                    x = "London", y = "44"
                }, new Point {
                    x = "Paris", y = "95"
                }, new Point {
                    x = "Bern", y = "37"
                }
            };

            charts[1]             = new Models.RadarChart();
            charts[1].name        = "set2";
            charts[1].fillColor   = "#7cb5ec";
            charts[1].borderColor = "#434348";
            charts[1].points      = new List <Point> {
                new Point {
                    x = "Rome", y = "12"
                }, new Point {
                    x = "London", y = "24"
                }, new Point {
                    x = "Paris", y = "125"
                }, new Point {
                    x = "Bern", y = "7"
                }
            };

            RadarChartData chartData = new RadarChartData();

            chartData.datasets = charts;

            string json = JsonConvert.SerializeObject(chartData);

            using (JsonTextReader reader = new JsonTextReader(new StringReader(json)))
            {
                JObject o2 = (JObject)JToken.ReadFrom(reader);
                return(this.Request.CreateResponse(HttpStatusCode.OK, o2, "application/json"));
            }
        }
Пример #3
0
        protected override void OnInitializeChartData()
        {
            base.OnInitializeChartData();
            if (OriginalChartView != null && SupportChartView != null && SupportChartView.ChartData != null)
            {
                var dataSetItems     = SupportChartView.ChartData.DataSets;
                var listDataSetItems = new List <RadarChartDataSet>();

                foreach (var itemChild in dataSetItems)
                {
                    var entryOriginal         = itemChild.IF_GetValues().Select(item => new RadarChartDataEntry(item.GetValue()));
                    RadarChartDataSet dataSet = new RadarChartDataSet(entryOriginal.ToArray(), itemChild.IF_GetLabel());
                    OnIntializeDataSet(itemChild, dataSet);
                    listDataSetItems.Add(dataSet);
                }

                var data = new RadarChartData(listDataSetItems.ToArray());

                OriginalChartView.Data = data;
                OriginalChartView.ReloadInputViews();
                OriginalChartView.SetNeedsDisplay();
            }
        }
Пример #4
0
        public HttpResponseMessage DrawRadarChart()
        {
            RadarChart[] charts = new RadarChart[1];

            charts[0]             = new Models.RadarChart();
            charts[0].name        = "set1";
            charts[0].fillColor   = "#f15c80";
            charts[0].borderColor = "#8085e9";
            charts[0].points      = new List <Point> {
                new Point {
                    x = "USA", y = "24"
                }, new Point {
                    x = "Fiji", y = "38"
                }, new Point {
                    x = "UK", y = "77"
                }, new Point {
                    x = "Italy", y = "17"
                }, new Point {
                    x = "PR", y = "53"
                }, new Point {
                    x = "India", y = "99"
                }
            };

            RadarChartData chartData = new RadarChartData();

            chartData.datasets = charts;

            string json = JsonConvert.SerializeObject(chartData);

            using (JsonTextReader reader = new JsonTextReader(new StringReader(json)))
            {
                JObject o2 = (JObject)JToken.ReadFrom(reader);
                return(this.Request.CreateResponse(HttpStatusCode.OK, o2, "application/json"));
            }
        }
Пример #5
0
        public ActionResult GetChartData()
        {
            DateTime      today        = DateTime.Today;
            JsonReturnObj jsonReturn   = new JsonReturnObj();
            List <string> hometownList = new List <string>()
            {
                //"Johor",
                //"Kedah",
                //"Kelantan",
                "Kuala Lumpur",
                "Labuan",
                //"Melaka",
                //"Negeri Sembilan",
                //"Pahang",
                //"Penang",
                //"Perak",
                //"Perlis",
                "Putrajaya",
                "Sabah",
                "Sarawak",
                //"Selangor",
                //"Terengganu"
            };

            try
            {
                //Get App Token
                string     appTokenURL  = $"https://graph.facebook.com/oauth/access_token?client_id={APP_ID}&client_secret={APP_SECRET}&grant_type=client_credentials";
                FBAppToken appTokenObj  = JsonConvert.DeserializeObject <FBAppToken>(WebRequestHelper.Get(appTokenURL));
                string     access_token = appTokenObj.AccessToken;

                //Get list of test users
                string testUserURL         = $"https://graph.facebook.com/v3.2/{APP_ID}/accounts/test-users?access_token={access_token}";
                string testUsersJson       = WebRequestHelper.Get(testUserURL);
                TestUserQueryResult result = JsonConvert.DeserializeObject <TestUserQueryResult>(testUsersJson);
                if (result.Error != null)
                {
                    throw new Exception(result.Error);
                }

                //Get list of test users profile
                Random rnd = new Random();
                List <TestUserProfile> userProfileList = new List <TestUserProfile>();
                foreach (TestUser user in result.TestUserList)
                {
                    string          profileURL  = $"https://graph.facebook.com/v3.2/{user.Id}/?fields=id,name,birthday,gender,hometown&access_token={user.AccessToken}";
                    TestUserProfile userProfile = JsonConvert.DeserializeObject <TestUserProfile>(WebRequestHelper.Get(profileURL));

                    char[] genderCharArray = userProfile.Gender.ToCharArray();
                    genderCharArray[0] = char.ToUpper(genderCharArray[0]);
                    userProfile.Gender = new string(genderCharArray);

                    DateTime birthday = DateTime.ParseExact(userProfile.Birthday, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                    userProfile.BirthdayMYFormat = birthday.ToString("dd/MM/yyyy");
                    userProfile.Hometown         = hometownList[rnd.Next(hometownList.Count)];
                    userProfileList.Add(userProfile);
                }

                //Populate JSON data for barchart
                BarChartData   barChartData   = GetBarChartDataFromUserProfileList(userProfileList, today);
                RadarChartData radarChartData = GetRadarChartDataFromUserProfileList(userProfileList, hometownList);

                jsonReturn.BarChartData   = barChartData;
                jsonReturn.RadarChartData = radarChartData;

                jsonReturn.IsSuccess = true;
            }
            catch (Exception ex)
            {
                jsonReturn.IsSuccess = false;
                jsonReturn.ErrorMsg  = ex.Message;
            }
            return(Json(jsonReturn, "application/json"));
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();

            var entries  = new List <RadarEntry>();
            var entries2 = new List <RadarEntry>();
            var labels   = new List <string>();

            var FontFamily = "";

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                FontFamily = "Pacifico-Regular";
                break;

            case Device.Android:
                FontFamily = "Fonts/Pacifico-Regular.ttf";
                break;

            default:
                break;
            }

            Random random = new Random();

            for (int i = 0; i < 8; i++)
            {
                entries.Add(new RadarEntry(random.Next(100)));
                entries2.Add(new RadarEntry(random.Next(100)));
                labels.Add("Entry" + i);
            }

            var dataSet5 = new RadarDataSet(entries2, "Radar DataSet 1")
            {
                Colors = new List <Color> {
                    Color.Red
                },
                FillColor       = Color.Red,
                DrawFilled      = true,
                DrawValues      = false,
                ValueFontFamily = FontFamily
            };

            var dataSet4 = new RadarDataSet(entries, "Radar DataSet 2")
            {
                Colors = new List <Color> {
                    Color.Green
                },
                FillColor  = Color.Green,
                DrawFilled = true,
                DrawValues = false,
            };
            var data4 = new RadarChartData(new List <IRadarDataSet>()
            {
                dataSet4, dataSet5
            });

            radarChart.ChartData = data4;
            radarChart.XAxis.AxisValueFormatter = new TextByIndexXAxisFormatter(labels);

            radarChart.XAxis.FontFamily = FontFamily;
        }