Exemplo n.º 1
0
        /// <summary>
        /// 获取某月的历史数据
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public EChartInfoJson GetHistoryMonthDays(FlowInfo flow)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(" [Time] = {0} ", flow.Time.ToString("yyyyMM"));

            if (flow.FlowUserId.HasValue)
            {
                sb.AppendFormat(" and FlowUserId={0} ", flow.FlowUserId);
            }
            if (flow.AdId.HasValue)
            {
                sb.AppendFormat(" and AdId={0} ", flow.AdId);
            }


            ChartPara cp = new ChartPara();

            cp.CommandText = string.Format(@"select * from (
select AdId, count(distinct(ClientIp)) as clickcount,  time as time from[dbo].[AdBrowseHistory]
where {0}
group by AdId, time
) a order by a.time asc ", sb);


            //时间数据
            var hours = CommonBLL.GetDayTable(int.Parse(flow.Time.ToString("yyyyMM")));
            //数据
            DataTable table = acc.GetTable(cp);

            //图形
            Entity.EChartInfoJson chart = new Entity.EChartInfoJson();
            chart.legend = new List <string>();
            chart.xAxis  = hours;
            chart.series = new List <Entity.serie>();

            var adlist = AdUserPageBLL.Instance.GetModels(new AdUserPagePara()
            {
                FlowUserId = flow.FlowUserId.Value
            });

            chart.xAxis = hours;

            foreach (var item in adlist)
            {
                string title = AdPageInfoBLL.Instance.GetTitleById(item.AdPageId);
                chart.legend.Add(title);

                Entity.serie data = new Entity.serie();
                data.name  = title;
                data.data  = new List <string>();
                data.stack = "浏览量";
                data.type  = "line";

                foreach (var hour in hours)
                {
                    var row = table.Select(string.Format("AdId={0} and time='{1}'", item.AdPageId, hour));
                    if (row.Length == 0)
                    {
                        data.data.Add("0");
                    }
                    else
                    {
                        data.data.Add(row[0]["clickcount"].ToString());
                    }
                }

                chart.series.Add(data);
            }

            return(chart);
        }