请看一下实体:
public partial class MonthWeekCity
{
///
/// 月份日期
///
public DateTime MonthDate { get; set; }
///
/// 描述。为月 或者周几 周几
///
public string DateText { get; set; }
///
/// 总量
///
public int AllCount { get; set; }
///
/// 认证总量
///
public int AuthCount { get; set; }
///
/// 该时间内的城市数据列表
///
public List CityList { get; set; }
}
public partial class CityData
{
public City Cityinfo { get; set; }
public int AllCount { get; set; }
public int AuthCount { get; set; }
}
然后我通过一般处理程序ashx返回数据,我这个数据是从数据库取的,大家可以自行修改:
返回数据集合:
private List GetMonthList()
{
List list = new List();
DateTime date = CheckResponse.GetDateTimeResponse("dt");
ShopStay ds = new ShopStay();
try
{
IAnalysisService APService = KtContainer.Instance.Resolve();
//本月第一天时间
DateTime dt_First = date.AddDays(1 - (date.Day));
//获得某年某月的天数
int year = date.Date.Year;
int month = date.Date.Month;
int dayCount = DateTime.DaysInMonth(year, month);
DateTime dt_Last = dt_First.AddDays(dayCount - 1);
List listcity = new List();
listcity = APService.GetCityDayCount(dt_First, dt_Last, 0);
for (int i = 0; i <= dayCount; i++)
{
MonthWeekCity oneday = new MonthWeekCity();
oneday.MonthDate = dt_First.AddDays(i);
oneday.CityList = new List();
oneday.AuthCount = 0;
oneday.AllCount = 0;
list.Add(oneday);
}
foreach (Tb_Statistic cd in listcity)
{
MonthWeekCity temp = list.SingleOrDefault(a => a.MonthDate == cd.StatisticDate);
if (temp == null)
{
function LoadLastMonth() {
var html = "";
var thismonth = new Date();
for (var i = 1;i < 10; i++) {
var months = thismonth.DateAdd("m", -i);
html = html + " " + months.Format("yyyy年MM月") + "";
}
$("#divlast").html(html);
}
js日期的格式化请看:[Javacript对Date日期的格式化及转换]
var staticsdt;
$(document).ready(function () {
$("#SDate").val((new Date()).Format("yyyy年MM月"));
LoadLastMonth();
btnGetData();
});
function LoadLastMonth() {
var html = "";
var thismonth = new Date();
for (var i = 1;i < 10; i++) {
var months = thismonth.DateAdd("m", -i);
html = html + " " + months.Format("yyyy年MM月") + "";
}
$("#divlast").html(html);
}
function ClickGetData(datee) {
$("#SDate").val(datee);
btnGetData();
}
function btnGetData() {
staticsdt = $("#SDate").val();
// 使用
require(
[
"echarts",
"echarts/chart/line" // 使用柱状图就加载bar模块,按需加载
],
showdatacllback
);
}
var echarts;
function showdatacllback(ec) {
echarts = ec;
GetDetailData(ec);
}
var MonthData;
function GetDetailData(ec) {
var AjaxUrl = "../../Service/MonthWeekStat.ashx";
if (staticsdt.length == 0) {
alert("请选择月份进行统计"); return;
}
$.ajax({
type: "post",
dataType: "json",
url: AjaxUrl,
data: {
dt: staticsdt,
oper: "month"
},
success: function (data, textStatus) {
if (data != null) {
var customfre = eval(data);
//设置点击事件
var ecConfig = require("echarts/config");
if (customfre != null && customfre != "undefined") {
var Xdata = new Array();
var MonthAllCount = new Array();
var MonthRenZhengCount = new Array();
var myChart = ec.init(document.getElementById("mainmonth"));
customfre.sort();
$.each(customfre, function (i, val) {
Xdata.push((new Date(val.MonthDate)).Format("yyyy-MM-dd"));
MonthRenZhengCount.push(val.AuthCount);
MonthAllCount.push(val.AllCount);
});