public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser)
        {
            StateSettings    appConfigServiceStateSettings = AppConfigService.GetInstance().StateSettings;
            TableLayoutPanel panel = new TableLayoutPanel {
                ColumnCount = 1, AutoScroll = true
            };
            ILikeService likeService = new LikesService(i_LoggedInUser);

            // get data as defined in settings
            List <Task> getDataTasks = new List <Task>();
            Dictionary <string, int> allPostemItemsLikes = new Dictionary <string, int>();

            foreach (KeyValuePair <eLikedItem, bool> keyValuePair in appConfigServiceStateSettings.LikedItems.Where(i_Item => i_Item.Value))
            {
                Task getDataTask = Task.Run(
                    async() =>
                {
                    PropertyInfo propertyInfo = i_LoggedInUser.GetType()
                                                .GetProperty(keyValuePair.Key.ToString());
                    if (propertyInfo != null)
                    {
                        try
                        {
                            object prop = propertyInfo.GetValue(i_LoggedInUser, null);
                            IEnumerable collectionOfUnknownType = (IEnumerable)prop;
                            ObservableCollection <PostedItem> currentPostedItems =
                                new ObservableCollection <PostedItem>();
                            foreach (PostedItem o in collectionOfUnknownType)
                            {
                                currentPostedItems.Add(o);
                            }

                            Dictionary <string, int> currenLikes =
                                await likeService.GetLikesHistogram(currentPostedItems).ConfigureAwait(false);
                            allPostemItemsLikes.AddRange <string, int>(currenLikes);
                        }
                        catch (Exception)
                        {
                            Console.WriteLine(Resources.FailedToRretrieveDataLikesForErrorMessage + propertyInfo);
                        }
                    }
                });
                getDataTasks.Add(getDataTask);
            }

            await Task.WhenAll(getDataTasks);

            Chart likeMeTheMostChart = ChartsUtil.CreateChart("Who Likes me the most!", DockStyle.Top,
                                                              allPostemItemsLikes.OrderByDescending(i_L => i_L.Value).
                                                              Take(appConfigServiceStateSettings.NumberOfFriend));
            Chart likeMeTheLeastChart = ChartsUtil.CreateChart("Who Likes me the least!", DockStyle.Bottom,
                                                               allPostemItemsLikes.OrderBy(i_L => i_L.Value).
                                                               Take(appConfigServiceStateSettings.NumberOfFriend));

            panel.Controls.Add(likeMeTheMostChart, 0, 0);
            panel.Controls.Add(likeMeTheLeastChart, 0, 1);

            return(panel);
        }
Пример #2
0
        /// <summary>
        /// refer: https://www.cnblogs.com/kulong995/p/5237796.html
        /// </summary>
        /// <returns></returns>
        public static string StdLine()
        {
            IList <string> weeks = ChartsUtil.Weeks();

            IList <int> datas1 = ChartsUtil.Datas(7, 10, 15);

            IList <int> datas2 = ChartsUtil.Datas(7, -2, 5);

            int min   = datas2.Min();
            int index = datas2.IndexOf(min);

            ChartOption option = new ChartOption();

            #region option.title

            /** origional code
             * option.title = new Title()
             * {
             *  show = true,
             *  text = "未来一周天气变化",
             *  subtext = "纯虚构数据"
             * };
             */
            option.title = new List <Title>()
            {
                new Title()
                {
                    show    = true,
                    text    = "未来一周天气变化",
                    subtext = "纯虚构数据"
                }
            };
            #endregion

            #region option.tooltip
            option.tooltip = new Forms.Model.ECharts.ToolTip()
            {
                trigger = TriggerType.axis
            };
            #endregion

            #region option.legend
            option.legend = new Legend()
            {
                data = new List <object>()
                {
                    "最高温度",
                    "最低温度"
                }
            };
            #endregion

            option.calculable = true;

            #region option.xAxis
            option.xAxis = new List <Forms.Model.ECharts.axis.Axis>()
            {
                new Forms.Model.ECharts.axis.CategoryAxis()
                {
                    type        = AxisType.category,
                    boundaryGap = false,
                    data        = new List <object>(weeks)
                }
            };
            #endregion

            #region option.yAxis
            option.yAxis = new List <Axis>()
            {
                new ValueAxis()
                {
                    type      = AxisType.value,
                    axisLabel = new AxisLabel()
                    {
                        formatter = new JRaw("{value} ℃").ToString()
                    }
                }
            };
            #endregion

            #region option.series
            option.series = new List <object>()
            {
                new Line()
                {
                    name      = "最高温度",
                    type      = ChartType.line,
                    data      = datas1,
                    markPoint = new MarkPoint()
                    {
                        data = new List <object>()
                        {
                            new MarkData()
                            {
                                name = "最大值",
                                type = MarkType.max,
                            },
                            new MarkData()
                            {
                                name = "最小值",
                                type = MarkType.min,
                            }
                        }
                    },
                    markLine = new MarkLine()
                    {
                        data = new List <object>()
                        {
                            new MarkData()
                            {
                                name = "平均值",
                                type = MarkType.average
                            }
                        }
                    }
                },
                new Line()
                {
                    name      = "最低温度",
                    type      = ChartType.line,
                    data      = datas2,
                    markPoint = new MarkPoint()
                    {
                        data = new List <object>()
                        {
                            new MarkData()
                            {
                                name  = "周最低",
                                value = min,
                                xAxis = index,
                                yAxis = min + 0.5,
                            }
                        }
                    },
                    markLine = new MarkLine()
                    {
                        data = new List <object>()
                        {
                            new MarkData()
                            {
                                type = MarkType.average,
                                name = "平均值"
                            }
                        }
                    }
                }
            };
            #endregion

            var result = JsonHelper.ObjectToJson2(option);

            return(result);
        }