如何在asp.net中显示图表控件中的用户数 [英] How to show number of users in chart control in asp.net
问题描述
我想显示其数据存储在SQL数据库中的表中的用户总数,该数据库基于asp.net中图表控件中的年份,即在特定年份注册的所有用户,这些数据应显示为一年中的所有月份。首先,我必须显示所有年份的数据。用户可以从下拉列表中选择特定年份,然后填充该特定年份的图表控件。当用户从下拉列表中选择一年而不是该特定年份时,应该为个别月份填充数据示例:1月份的40位用户,3月份的85位用户等。
I want to show total number of users whose data is stored in a table in SQL database which is based on year in chart control in asp.net i.e. all the users who registered in a particular year, these data should be displayed for all the months in a year. Firstly I have to show data for all the years. Than the user can select a particular year from the dropdownlist and than populate the chart control for that particular year. When the user has selected a year from dropdownlist than for that particular year the data should be populated for individual months example: 40 users from Jan, 85 from March, etc.
int month = 1;
for (int i = month; i <= 12; i++)
{
var usercount = (from u in context.Profiles
where u.CreatedOn.Month == month
select u).Count();
}
我正在使用实体框架来编写与数据库相关的代码。
I am using entity framework for writing the database related codes.
推荐答案
您可以在很好的图表库选择中找到很多信息。例如,请参阅:
https://msdn.microsoft.com/en -us / magazine / dd453008.aspx [ ^ ],
http://www.asp.net/web-pages/overview/data/7-displaying-data-in-a-chart [ ^ ],
http://www.w3schools.com/aspnet/webpages_chart.asp [ ^ ]。
-SA
You could find a lot of information on a good choice of charts libraries. See, for example:
https://msdn.microsoft.com/en-us/magazine/dd453008.aspx[^],
http://www.asp.net/web-pages/overview/data/7-displaying-data-in-a-chart[^],
http://www.w3schools.com/aspnet/webpages_chart.asp[^].
—SA
如果您想获得指定年份每月创建的用户数,请使用:
If you want to get the count of users created each month of specified year, use:
//get distinct years and bind data to combobox
var years = context.Profiles
.Select(u=>u.CreatedOn.Year)
.Distinct()
.ToList();
ComboBox1.DataSource = years;
int uyear = 2014; //ComboBox1 value
var qry = context.Profiles
.Where(u=>u.CreatedOn.Year == uyear)
.GroupBy(u=> u.CreatedOn.Month)
.Select(grp=>new{month=grp.Key, count=grp.Count()})
.ToList();
//now, you can bind data from qry object to GridView, ListView, etc.
祝你好运!
Good luck!
这篇关于如何在asp.net中显示图表控件中的用户数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!