2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using iWareLog.Report.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace iWareWms.View.Echarts.Alert.Detail
{
    public partial class Two : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string dateStart = Request.QueryString["dateStart"];
                string dateEnd = Request.QueryString["dateEnd"];
 
                var barOptions = String.Empty;
 
                if (string.IsNullOrEmpty(dateStart) && string.IsNullOrEmpty(dateEnd))
                {
                    dateStart = DateTime.Now.AddDays(-9).ToShortDateString();//默认加载十天数据
                    dateEnd = DateTime.Now.AddDays(1).ToShortDateString();
                }
 
                var data = AlertService.GetInstance().GetAlertByAlertCode(Convert.ToDateTime(dateStart), Convert.ToDateTime(dateEnd).AddDays(1));
 
                List<int> countList = data.Select(x => x.alertcount).ToList();
                List<int> diffList = data.Select(x => x.datediffs).ToList();
                List<string> nameList = data.Select(x => x.alertcode).ToList();
 
                string data1 = string.Join(",", countList);
                string data2 = string.Join(",", diffList);
                string data3 = string.Empty;
                foreach (var p in nameList)
                {
                    data3 += "\"代码" + p + "\",";
                }
                if (data3.Length > 0)
                {
                    data3 = data3.Substring(0, data3.Length - 1);
                }
 
 
 
                barOptions = "{\"title\": {\"text\": \"设备报警记录\"},\"tooltip\": {\"trigger\": \"axis\"},\"legend\": {\"data\": [\"报警次数\", \"报警总时长\"]},\"toolbox\": {\"show\": true,\"feature\": {\"dataView\": { \"show\": true, \"readOnly\": false },\"magicType\": { \"show\": true, \"type\": [\"line\", \"bar\"] },\"restore\": { \"show\": true },\"saveAsImage\": { \"show\": true }}},\"calculable\": true,\"xAxis\": [{\"type\": \"category\",\"data\": [" + data3 + "]}],\"yAxis\": [{\"type\": \"value\",\"name\": \"次数\",\"min\": 0,\"axisLabel\": {\"formatter\": \"{value} 次\"}},{\"type\": \"value\",\"name\": \"时间\",\"min\": 0,\"axisLabel\": {\"formatter\": \"{value} 秒\"}}],\"series\": [{\"name\": \"报警次数\",\"type\": \"bar\",\"data\": [" + data1 + "],\"markPoint\": {\"data\": [{ \"type\": \"max\", \"name\": \"最大值\" },{ \"type\": \"min\", \"name\": \"最小值\" }]}},{\"name\": \"报警总时长\",\"type\": \"line\",\"yAxisIndex\": 1,\"data\": [" + data2 + "]}]}";
 
                hfBarOptions.Value = barOptions;
            }
        }
    }
}