public xAxis GetOrdersAmountxAxis() { xAxis xAxis = new xAxis(); xAxis.axisLabel = new axisLabel(); xAxis.type = "category"; xAxis.data = new List <object>(); Random random = new Random(); DateTime startDate = DateTime.Today.AddDays(-7); DateTime endDate = DateTime.Today; int diffDate = tools.NullInt((endDate - startDate).TotalDays); string SqlList = ""; SqlDataReader RdrList = null; SqlList = " select min(CONVERT(varchar(5), Orders_Addtime, 110)) as orders_date,SUM(Orders_Total_AllPrice) as order_amount from Orders "; SqlList += " WHERE DATEDIFF(d, Orders_Addtime, '" + startDate + "') <= 0"; SqlList += " AND DATEDIFF(d, Orders_Addtime, '" + endDate + "') >= 0 and Orders_PaymentStatus=1 and Orders_Status=1"; SqlList += " group by datepart(DY,Orders_Addtime)"; try { RdrList = DBHelper.ExecuteReader(SqlList); if (RdrList.HasRows) { while (RdrList.Read()) { diffDate = diffDate - 1; xAxis.data.Add(tools.NullStr(RdrList["orders_date"])); //数据依次递增 } } else { double upper = (endDate - startDate).TotalDays; for (int i = 1; i <= upper; i++) { xAxis.data.Add(startDate.AddDays(i).ToString("MM-dd")); } } } catch (Exception ex) { throw ex; } finally { RdrList.Close(); RdrList = null; } return(xAxis); }
public JsonResult GetChart() { B_Manager_log b_log = new B_Manager_log(); var res = b_log.GetNavClick(7); List <string> legend = new List <string>(); List <Series> list = new List <Series>(); foreach (var item in res.Keys) { if (item == "图表工具" || item == "数据备份" || item == "短信工具" || item == "栏目管理") { continue; } legend.Add(item); Series menuSeries = new Series(); menuSeries.name = item; menuSeries.type = "line"; menuSeries.areaStyle = new itemStyle() { normal = new object() }; menuSeries.data = res[item].ToList(); //menuSeries.stack = "总量"; list.Add(menuSeries); } xAxis xaxis = new xAxis() { boundaryGap = false, type = "category", data = new List <object>() { DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd"), DateTime.Now.AddDays(-5).ToString("yyyy-MM-dd"), DateTime.Now.AddDays(-4).ToString("yyyy-MM-dd"), DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd"), DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd"), DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd") } }; List <object> data = new List <object>(); data.Add(legend); data.Add(xaxis); data.Add(list); return(Json(data)); }
public void TradeIndex_Charts() { DateTime startDate; if (!DateTime.TryParse(tools.CheckStr(Request["startDate"]), out startDate)) { startDate = DateTime.Today.AddDays(-15); } DateTime endDate; if (!DateTime.TryParse(tools.CheckStr(Request["endDate"]), out endDate)) { endDate = DateTime.Today; } //图标X轴 List <xAxis> xAxisList = new List <xAxis>(); //考虑到图表的series数据为一个对象数组 这里额外定义一个series的类 List <Series> seriesList = new List <Series>(); //考虑到Echarts图表需要设置legend内的data数组为series的name集合这里需要定义一个legend数组 List <string> legendList = new List <string>(); Random random = new Random(); string[] categoryArry = new string[] { "定价黄金", "计价黄金", "钻石", "铂金", "K金", "宝石", "珍珠", "银饰", "翡翠玉石珠" }; try { xAxis xAxis = new xAxis(); xAxis.axisLabel = new axisLabel(); xAxis.type = "category"; xAxis.axisLabel.interval = 0; xAxis.data = new List <object>(); if (categoryArry != null) { foreach (string itesms in categoryArry) { xAxis.data.Add(itesms); } } xAxisList.Add(xAxis); xAxisList.Add(GetOrdersAmountxAxis()); //将sereis对象压入sereis数组列表内 seriesList.Add(GetKeywordSeries()); seriesList.Add(GetOrdersAmountSeries()); } catch (Exception ex) { throw ex; } //最后调用相关函数将List转换为Json //因为我们需要返回category和series、legend多个对象 这里我们自己在new一个新的对象来封装这两个对象 var newObj = new { xAxis = xAxisList, series = seriesList }; string jsonstr = JsonHelper.ObjectToJSON(newObj); //Response返回新对象的json数据 Response.Write(JsonHelper.ObjectToJSON(newObj)); Response.End(); }
/// <summary> /// Add By Mayi; /// 实现接收拖拽对象的函数; /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Address_Drop(object sender, DragEventArgs e) { try { DataGridCell_MIB_MouseEventArgs cell = e.Data.GetData(typeof(DataGridCell_MIB_MouseEventArgs)) as DataGridCell_MIB_MouseEventArgs; foreach (var iter in cell.SelectedCell.Properties) { // 找与其对应的节点; if (cell.HeaderName == (iter.Value as DataGrid_Cell_MIB).MibName_CN) { Console.WriteLine("Selected Cell Keys is " + iter.Key + "and value is " + (iter.Value as DataGrid_Cell_MIB).MibName_CN + " This Node oid is " + (iter.Value as DataGrid_Cell_MIB).oid); List <string> inputoid = new List <string>(); inputoid.Add((iter.Value as DataGrid_Cell_MIB).oid); GettingValue = true; // 启动一个线程不断读取该节点的数值并回填到EChart的option中; Task ReadValue_FromSNMP = new Task(() => { string[] data = { }; double[] da_Num = { }; // 构造option,以显示在js中,作为初始默认显示; Dictionary <string, string> Ret = new Dictionary <string, string>(); List <double> da_Num_content = new List <double>(); List <string> data_content = new List <string>(); // 持续获取数据; while (GettingValue) { // !!!后续需要扩展功能,保存日志文件; SnmpMessageV2c snmpmsg1 = new SnmpMessageV2c(); Ret = snmpmsg1.GetRequest(inputoid, "public", "172.27.245.92"); double temp = 0; foreach (var iter2 in Ret) { Console.WriteLine("Get MibValue is " + iter2.Value); Double.TryParse(iter2.Value, out temp); da_Num_content.Add(temp); da_Num = da_Num_content.ToArray(); // 将数据集再转换回数组; data_content.Add(DateTime.Now.ToString("T")); data = data_content.ToArray(); } Thread.Sleep(2000); series mySeries = new series((iter.Value as DataGrid_Cell_MIB).MibName_CN, "line", false, "circle", "", da_Num); m_CbForJs.listForLegend.Add((iter.Value as DataGrid_Cell_MIB).MibName_CN); m_CbForJs.listForSeries.Add(mySeries); legend myLegend = new legend(m_CbForJs.listForLegend); xAxis xaxis = new xAxis(data); Option myOption = new Option(myLegend, m_CbForJs.listForSeries, xaxis); m_CbForJs.Option = Option.ObjectToJson(myOption); } }); ReadValue_FromSNMP.Start(); } } } catch (Exception ex) { Console.WriteLine("LineChart Receive Mouse Drop Exception " + ex.ToString()); } }