Beispiel #1
0
        /// <summary>
        /// 取得用户所有电站跨小时的功率图表
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="startYYYYMMDDHH"></param>
        /// <param name="endYYYYMMDDHH"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult AllPlantDayChart(int userId, string startYYYYMMDDHH, string endYYYYMMDDHH, string chartType, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            User user = UserService.GetInstance().Get(userId);

            //获得报表业务逻辑类
            PlantChartService reportService = PlantChartService.GetInstance();
            //获得报表js代码
            int         monitorCode = MonitorType.PLANT_MONITORITEM_POWER_CODE;//发电量测点
            MonitorType Mt          = MonitorType.getMonitorTypeByCode(monitorCode);
            string      unit        = Mt.unit;
            string      chartName   = LanguageUtil.getDesc("CHART_DAY_POWER_CHART");
            string      reportData  = string.Empty;

            if (user != null && user.plants != null)
            {
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = reportService.PlantDayChart(user.plants, chartName, startYYYYMMDDHH, endYYYYMMDDHH, chartType, unit, monitorCode, intervalTime);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.useridnoexist, Resources.SunResource.CHART_USER_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
Beispiel #2
0
        /// <summary>
        /// 用户所有电站的年度发电量图表数据
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult AllPlantYearChart(int userId, string chartType, string lan)
        {
            setlan(lan);

            string reportData = string.Empty;

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            User user = UserService.GetInstance().Get(userId);

            if (user != null && user.plants != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                string      unit     = energyMt.unit;
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = PlantChartService.GetInstance().YearChartBypList(user.plants, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.useridnoexist, Resources.SunResource.CHART_USER_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
Beispiel #3
0
        /// <summary>
        /// 电站的月天数据
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="startYYYYMMDD"></param>
        /// <param name="endYYYYMMDD"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult PlantMonthDayChart(int pid, string startYYYYMMDD, string endYYYYMMDD, string chartType, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Plant  plant      = PlantService.GetInstance().GetPlantInfoById(pid);
            string reportData = string.Empty;

            if (plant != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                string      unit     = energyMt.unit;
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = PlantChartService.GetInstance().MMDDChartBypList(new List <Plant> {
                    plant
                }, startYYYYMMDD, endYYYYMMDD, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.plantnoexist, Resources.SunResource.CHART_PLANT_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
Beispiel #4
0
        /// <summary>
        /// 取得某个设备跨小时的某测点图表
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="startYYYYMMDD"></param>
        /// <param name="endYYYYMMDD"></param>
        /// <returns></returns>
        public ActionResult MonitorDayChart(int dId, string startYYYYMMDDHH, string endYYYYMMDDHH, string chartType, int monitorCode, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device = DeviceService.GetInstance().get(dId);
            //获得报表js代码
            MonitorType energyMt   = MonitorType.getMonitorTypeByCode(monitorCode);
            string      unit       = energyMt.unit;
            string      chartName  = device.fullName + " " + LanguageUtil.getDesc("CHART_DAY_CHART");
            string      reportData = string.Empty;

            if (device != null)
            {
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().DayChart(device, chartName, startYYYYMMDDHH, endYYYYMMDDHH, chartType, unit, monitorCode, intervalTime);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.devicenoexist, Resources.SunResource.CHART_DEVICE_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
Beispiel #5
0
        /// <summary>
        /// 逆变器设备的月天数据
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="startYYYYMMDD"></param>
        /// <param name="endYYYYMMDD"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult DeviceMonthDayChart(int dId, string startYYYYMMDD, string endYYYYMMDD, string chartType, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device     = DeviceService.GetInstance().get(dId);
            string reportData = string.Empty;

            if (device != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.MIC_INVERTER_TODAYENERGY);
                string      unit     = energyMt.unit;
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().MonthDDChartByDevice(device, 1.0F, string.Format(LanguageUtil.getDesc("DEVICEMONTHCHART_NAME"), device.fullName), startYYYYMMDD, endYYYYMMDD, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.devicenoexist, Resources.SunResource.CHART_DEVICE_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
Beispiel #6
0
        /// <summary>
        /// 单个设备的年月发电量图表数据
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <param name="startYM">开始年月</param>
        /// <param name="endYM">截止年月</param>
        /// <param name="chartType">图表类型</param>
        /// <returns></returns>
        public ActionResult DeviceYearMMChart(int dId, string startYM, string endYM, string chartType, string lan)
        {
            setlan(lan);

            string reportData = string.Empty;

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device = DeviceService.GetInstance().get(dId);

            if (device != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                string      unit     = energyMt.unit;
                //取得用户年度发电量图表数据
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().YearMMChartByDevice(device, 1.0F, string.Format(LanguageUtil.getDesc("DEVICEYEAR_CHART_NAME"), device.fullName), startYM, endYM, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.devicenoexist, Resources.SunResource.CHART_DEVICE_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
Beispiel #7
0
        /// <summary>
        /// 取得某个设备跨小时的功率图表
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="startYYYYMMDD"></param>
        /// <param name="endYYYYMMDD"></param>
        /// <returns></returns>
        public ActionResult DeviceDayChart(int dId, string startYYYYMMDDHH, string endYYYYMMDDHH, string chartType, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device      = DeviceService.GetInstance().get(dId);
            int    monitorCode = MonitorType.MIC_INVERTER_TOTALYGPOWER;//功率

            switch (device.deviceTypeCode)
            {
            case DeviceData.HUILIUXIANG_CODE:
                monitorCode = MonitorType.MIC_BUSBAR_TOTALCURRENT;
                break;

            case DeviceData.CABINET_CODE:
                monitorCode = MonitorType.MIC_BUSBAR_TOTALCURRENT;
                break;

            case DeviceData.ENVRIOMENTMONITOR_CODE:
                monitorCode = MonitorType.MIC_DETECTOR_SUNLINGHT;
                break;

            case DeviceData.AMMETER_CODE:
                monitorCode = MonitorType.MIC_AMMETER_POSITIVEACTIVEPOWERDEGREE;
                break;

            default:
                monitorCode = MonitorType.MIC_INVERTER_TOTALYGPOWER;    //功率
                break;
            }

            MonitorType Mt         = MonitorType.getMonitorTypeByCode(monitorCode);
            string      unit       = Mt.unit;
            string      chartName  = device.fullName + " " + LanguageUtil.getDesc("CHART_DAY_CHART");
            string      reportData = string.Empty;

            if (device != null)
            {
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().DayChart(device, chartName, startYYYYMMDDHH, endYYYYMMDDHH, chartType, unit, monitorCode, intervalTime);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.devicenoexist, Resources.SunResource.CHART_DEVICE_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
Beispiel #8
0
        /// <summary>
        /// 取得电站的日图表数据
        /// </summary>
        /// <param name="pId">电站id</param>
        /// <param name="startTime">开始时间,格式:yyyyMMddhh 2011111105</param>
        /// <param name="endTime">截止时间,格式:yyyyMMddhh 2011111223</param>
        /// <param name="app_key">第三方应用唯一key</param>
        /// <param name="call_id">请求序号</param>
        /// <param name="sig">签名</param>
        /// <param name="v">api版本</param>
        /// <param name="format">返回结果格式,暂时值支持json</param>
        /// <param name="lan">语言环境,暂时只支持中英文</param>
        /// <returns>图表封装的数据</returns>
        public ActionResult plantDayChartData(int pId, string startDate, string endDate, string app_key, string call_id, string sig, string v, string format, string lan)
        {
            setlan(lan);

            string chartType = ChartType.column;

            string reportCode   = string.Empty;
            Plant  plant        = PlantService.GetInstance().GetPlantInfoById(pId);
            string intervalMins = "5,5";

            string[] intervals = intervalMins.Split(',');
            if (plant != null && plant.plantUnits.Count > 0)
            {
                IList <DeviceStuct> devices = new List <DeviceStuct>();
                string   deviceId           = plant.id.ToString();
                string[] chartTypes         = chartType.Split(',');
                devices.Add(new DeviceStuct()
                {
                    deviceId = deviceId, rate = 1.0F, comareObj = plant.name, chartType = chartTypes[0], monitorType = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_POWER_CODE), cVal = ComputeType.Avg, deviceType = ChartDeviceType.PLANT, intervalMins = int.Parse(intervals[0])
                });

                //判断该测点是否有数据,有数据则增加关照对比
                Hashtable dataHash = CollectorDayDataService.GetInstance().GetUnitDaydataList(plant.plantUnits, startDate, endDate, int.Parse(intervals[0]), MonitorType.PLANT_MONITORITEM_POWER_CODE);
                if (dataHash.Count > 0)
                {
                    float       rate = 1F;
                    MonitorType mt   = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_LINGT_CODE);
                    devices.Add(new DeviceStuct()
                    {
                        deviceId = plant.id.ToString(), rate = rate, comareObj = plant.name, name = mt.name, unit = "", chartType = chartTypes[0], monitorType = mt, cVal = ComputeType.Avg, deviceType = ChartDeviceType.PLANT, intervalMins = int.Parse(intervals[1])
                    });
                }
                else
                {
                    return(Content("error:" + Resources.SunResource.NODATA));
                }

                string chartName = LanguageUtil.getDesc("PLANT_CHART_DAY_POWER_SUNLIGHT_COMPARE_CHART");
                //取得用户年度发电量图表数据
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = CompareChartService.GetInstance().compareDayHHMultiDeviceMultiMonitor(chartName, devices, startDate, endDate, int.Parse(intervals[0]));
                reportCode = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            return(Content(reportCode));
        }
Beispiel #9
0
        /// <summary>
        /// 取得设备某个测点的日变化曲线
        /// </summary>
        /// <param name="dId"></param>
        /// <param name="startYYYYMMDDHH"></param>
        /// <param name="endYYYYMMDDHH"></param>
        /// <param name="chartType"></param>
        /// <param name="monitorCode"></param>
        /// <returns></returns>
        public ActionResult MonitorDayChart(int dId, string startYYYYMMDDHH, string endYYYYMMDDHH, string chartType, int monitorCode, int intervalMins)
        {
            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device = DeviceService.GetInstance().get(dId);
            //获得报表js代码
            MonitorType mt         = MonitorType.getMonitorTypeByCode(monitorCode);
            string      unit       = mt.getMonitorFirstUnitByCode();
            string      chartName  = string.Format(LanguageUtil.getDesc("MONITOR_DAY_CHAR_NAME"), mt.name);
            string      reportCode = string.Empty;

            if (device != null)
            {
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().DayChart(device, chartName, startYYYYMMDDHH, endYYYYMMDDHH, chartType, unit, monitorCode, intervalMins);
                reportCode = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            return(Content(reportCode));
        }
Beispiel #10
0
        /// <summary>
        /// 创建多维图表数据
        /// </summary>
        /// <param name="chartName"></param>
        /// <param name="xAxisText"></param>
        /// <param name="datas"></param>
        /// <param name="ynames"></param>
        /// <param name="chartTypes"></param>
        /// <param name="units"></param>
        /// <param name="comareObjs"></param>
        /// <param name="colors"></param>
        /// <param name="isUP">是否进制</param>
        /// <returns></returns>
        public static ChartData createMultiJsonChartXY(string chartName, string[] xAxisText, IList<KeyValuePair<string, float?[]>> datas, string[] ynames, string[] chartTypes, string[] units, string[] comareObjs, string[] colors, bool isUP)
        {
            IDictionary<string, int> unitIndexMap = new Dictionary<string, int>();
            IList<string> unitList = new List<string>();
            IList<string> ynameList = new List<string>();
            for (int i = 0; i < units.Length; i++)
            {
               if (!unitList.Contains(units[i]))
               {
                    unitList.Add(units[i]);
                    ynameList.Add(ynames[i]);
                    unitIndexMap.Add(units[i], unitList.Count - 1);
               }
            }
            string[] aimColors = getColors(datas.Count);

            ChartData chartData = new ChartData();
            chartData.name = chartName;
            chartData.categories = xAxisText;

            chartData.colors = aimColors;
            chartData.units = unitList.ToArray();
            chartData.names = ynameList.ToArray();
            YData yData = null;//单条y轴数据
            YData[] ydatas = new YData[datas.Count];
            string tmpunit, tmpobj = "";
            bool isHasData = false;
            for (int i = 0; i < datas.Count; i++)
            {
                KeyValuePair<string, float?[]> data = datas[i];
                if (data.Value == null)
                {
                    continue;
                }
                yData = new YData();
                //if (data.Key.IndexOf("20") == -1)//除了年度的其他都要按照data.Key+"["+tmpunit+"]-电站"格式输出;
                //{
                tmpunit = units.Length == 1 ? units[0] : units[i];
                if (comareObjs != null)
                    tmpobj = comareObjs.Length == 1 ? "--" + comareObjs[0] : "--" + comareObjs[i];
                //yData.name = data.Key + "[" + tmpunit + "] " + (tmpobj.Equals("--")?"":tmpobj);
                //}
                // else
                // yData.name = data.Key;
                yData.type = chartTypes.Length == 1 ? chartTypes[0] : chartTypes[i];
                yData.data = data.Value;
                int realYAxisIndex = units.Length == 1 ? 0 : unitIndexMap[units[i]];

                //有指定颜色就用指定颜色,否则用从备用色中顺序取得颜色
                if (colors.Length > i && colors[i] != null)
                    yData.color = colors[i];
                else
                    yData.color = aimColors[i];

                yData.yAxis = realYAxisIndex.ToString();
                //取得数据的最大值
                yData.max = getMax(yData.data);
                yData.min = getMin(yData.data);
                if (yData.min > 0) yData.min = 0;
                //进行进制
                if (isUP)
                {
                    float newMax = upUnitData(yData.max, yData.data, i, chartData.units);
                    if (yData.min < 0 && yData.max != newMax)
                    {
                        yData.min = upUnitValue(yData.min);
                    }
                    yData.max = newMax;
                }
                string newUnitstr = units[i].Equals("") ? units[i] : "[" + units[i] + "] ";
                yData.name = data.Key + newUnitstr + (tmpobj.Equals("--") ? "" : tmpobj);
                ydatas[i] = yData;
                isHasData = true;
            }
            chartData.isHasData = isHasData;
            if (isHasData)
            {
                chartData.series = ydatas;
            }
            else
            {
                chartData.errorDesc = LanguageUtil.getDesc("CHART_ERROR_NODATA");
                chartData.series = new YData[] { };
            }
            //产生唯一序号
            chartData.serieNo = DateTime.Now.ToString("ddhhmmss") + new Random().Next(1000);
            TempDataUtil.putChartData(chartData.serieNo, chartData);
            return chartData;
            //return JsonUtil.convertToJson(chartData, typeof(ChartData));
        }
Beispiel #11
0
        /// <summary>
        /// 创建多维图表数据
        /// </summary>
        /// <param name="chartName"></param>
        /// <param name="xAxisText"></param>
        /// <param name="datas"></param>
        /// <param name="ynames"></param>
        /// <param name="chartTypes"></param>
        /// <param name="units"></param>
        /// <param name="comareObjs"></param>
        /// <param name="colors"></param>
        /// <param name="isUP">是否进制</param>
        /// <returns></returns>
        public static ChartData createMultiJsonChartXY(string chartName, string[] xAxisText, IList <KeyValuePair <string, float?[]> > datas, string[] ynames, string[] chartTypes, string[] units, string[] comareObjs, string[] colors, bool isUP)
        {
            IDictionary <string, int> unitIndexMap = new Dictionary <string, int>();
            IList <string>            unitList     = new List <string>();
            IList <string>            ynameList    = new List <string>();

            for (int i = 0; i < units.Length; i++)
            {
                if (!unitList.Contains(units[i]))
                {
                    unitList.Add(units[i]);
                    ynameList.Add(ynames[i]);
                    unitIndexMap.Add(units[i], unitList.Count - 1);
                }
            }
            string[] aimColors = getColors(datas.Count);

            ChartData chartData = new ChartData();

            chartData.name       = chartName;
            chartData.categories = xAxisText;

            chartData.colors = aimColors;
            chartData.units  = unitList.ToArray();
            chartData.names  = ynameList.ToArray();
            YData yData = null;//单条y轴数据

            YData[] ydatas = new YData[datas.Count];
            string  tmpunit, tmpobj = "";
            bool    isHasData = false;

            for (int i = 0; i < datas.Count; i++)
            {
                KeyValuePair <string, float?[]> data = datas[i];
                if (data.Value == null)
                {
                    continue;
                }
                yData = new YData();
                //if (data.Key.IndexOf("20") == -1)//除了年度的其他都要按照data.Key+"["+tmpunit+"]-电站"格式输出;
                //{
                tmpunit = units.Length == 1 ? units[0] : units[i];
                if (comareObjs != null)
                {
                    tmpobj = comareObjs.Length == 1 ? "--" + comareObjs[0] : "--" + comareObjs[i];
                }
                //yData.name = data.Key + "[" + tmpunit + "] " + (tmpobj.Equals("--")?"":tmpobj);
                //}
                // else
                // yData.name = data.Key;
                yData.type = chartTypes.Length == 1 ? chartTypes[0] : chartTypes[i];
                yData.data = data.Value;
                int realYAxisIndex = units.Length == 1 ? 0 : unitIndexMap[units[i]];

                //有指定颜色就用指定颜色,否则用从备用色中顺序取得颜色
                if (colors.Length > i && colors[i] != null)
                {
                    yData.color = colors[i];
                }
                else
                {
                    yData.color = aimColors[i];
                }

                yData.yAxis = realYAxisIndex.ToString();
                //取得数据的最大值
                yData.max = getMax(yData.data);
                yData.min = getMin(yData.data);
                if (yData.min > 0)
                {
                    yData.min = 0;
                }
                //进行进制
                if (isUP)
                {
                    float newMax = upUnitData(yData.max, yData.data, i, chartData.units);
                    if (yData.min < 0 && yData.max != newMax)
                    {
                        yData.min = upUnitValue(yData.min);
                    }
                    yData.max = newMax;
                }
                string newUnitstr = units[i].Equals("") ? units[i] : "[" + units[i] + "] ";
                yData.name = data.Key + newUnitstr + (tmpobj.Equals("--") ? "" : tmpobj);
                ydatas[i]  = yData;
                isHasData  = true;
            }
            chartData.isHasData = isHasData;
            if (isHasData)
            {
                chartData.series = ydatas;
            }
            else
            {
                chartData.errorDesc = LanguageUtil.getDesc("CHART_ERROR_NODATA");
                chartData.series    = new YData[] { };
            }
            //产生唯一序号
            chartData.serieNo = DateTime.Now.ToString("ddhhmmss") + new Random().Next(1000);
            TempDataUtil.putChartData(chartData.serieNo, chartData);
            return(chartData);
            //return JsonUtil.convertToJson(chartData, typeof(ChartData));
        }
        private bool DrawChartImage(ChartData chartData, string chartPath)
        {
            if (chartData == null || chartData.isHasData == false)
                return false;
            int axisXInterval = 1;
            bool multiY = false;

            #region 图表横轴interval

            if (chartData.categories.Length > 0)
            {
                string category = chartData.categories[0];
                if (Regex.IsMatch(category, "^\\d{4}$"))//年统计图表
                    axisXInterval = 1;
                else
                    if (chartData.categories.Length.Equals(12) || chartData.categories.Length.Equals(15))
                        axisXInterval = 1;
                    else
                        if (chartData.categories.Length >= 28 && chartData.categories.Length <= 31 || chartData.categories.Length.Equals(34))
                            axisXInterval = 1;
                        else
                            axisXInterval = 24;
            }

            #endregion

            string chartName = chartData.name;
            multiY = chartData.units.Length > 1 && chartName.Contains("&");
            string unit = string.Empty;
            unit = chartData.units[0];
            JavaScriptSerializer jserializer = new JavaScriptSerializer();
            int seriesCount = 0;
            Chart Chart = new Chart();
            Chart.Width = 1000;
            Chart.Height = 500;
            Title title = new Title(chartName, Docking.Top, new System.Drawing.Font("Trebuchet MS", 12, System.Drawing.FontStyle.Regular), System.Drawing.Color.FromArgb(26, 59, 105));
            Chart.Titles.Add(title);
            Chart.ChartAreas.Add("ChartAreas 1");
            Chart.ChartAreas[0].AxisX.Interval = axisXInterval;
            Chart.ChartAreas[0].AxisY.IntervalAutoMode = IntervalAutoMode.VariableCount;
            Chart.ChartAreas[0].AxisY2.IntervalAutoMode = IntervalAutoMode.VariableCount;
            //Chart.ChartAreas[0].AxisX.MajorTickMark.Interval = 2;//次要辅助线间隔
            Chart.ChartAreas[0].AxisX.IntervalOffset = 0;
            //Chart.ChartAreas[0].AxisX.MinorGrid.LineWidth = 0;
            Chart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
            Chart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 1;
            Chart.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(209, 208, 206);
            Chart.ChartAreas[0].AxisY2.MajorGrid.LineColor = System.Drawing.Color.FromArgb(209, 208, 206);
            Chart.ChartAreas[0].AxisY.Title = string.Format("[{0}]", unit);
            Chart.ChartAreas[0].AxisX.LabelStyle.Angle = -90;//横坐标字符倾斜角度

            #region 图例配置

            Legend legend = new Legend();
            legend.Alignment = StringAlignment.Center;
            legend.Docking = Docking.Bottom;
            legend.Name = string.Format("Legends {0}", 0);
            Chart.Legends.Add(legend);

            #endregion

            Chart.SuppressExceptions = true;
            while (seriesCount++ < chartData.series.Length)
            {

                #region 设置图表类型

                SeriesChartType seriesChartType = SeriesChartType.Column;

                string chartType = chartData.series[seriesCount - 1].type;
                if (chartType.ToLower().Equals("area"))
                    seriesChartType = SeriesChartType.Area;
                if (chartType.ToLower().Equals("line"))
                    seriesChartType = SeriesChartType.Line;
                if (chartType.ToLower().Equals("column"))
                    seriesChartType = SeriesChartType.Column;

                #endregion

                #region 设置图表颜色

                string color = chartData.series[seriesCount - 1].color;
                string r = color.Substring(1, 2);
                string g = color.Substring(3, 2);
                string b = color.Substring(5, 2);

                #endregion

                IList<KeyValuePair<string, float?>> outputData = new List<KeyValuePair<string, float?>>();
                for (int i = 0; i < chartData.categories.Length; i++)
                    outputData.Add(new KeyValuePair<string, float?>(chartData.categories[i], chartData.series[seriesCount - 1].data[i]));
                Chart.Series.Add(string.Format("Series {0}", seriesCount - 1));
                Chart.Series[seriesCount - 1].Points.DataBind(outputData, "key", "value", "");
                Chart.Series[seriesCount - 1].Color = System.Drawing.Color.FromArgb(Convert.ToInt32(r, 16), Convert.ToInt32(g, 16), Convert.ToInt32(b, 16));
                Chart.Series[seriesCount - 1].XValueType = ChartValueType.String;
                Chart.Series[seriesCount - 1].ChartType = seriesChartType;
                #region 图例

                //图例文字
                Chart.Series[seriesCount - 1].LegendText = chartData.series[seriesCount - 1].name;

                #endregion

                if (multiY)
                {
                    Chart.Series[seriesCount - 1].YAxisType = seriesCount % 2 == 1 ? AxisType.Primary : AxisType.Secondary;
                }

            }
            Chart.BorderSkin.SkinStyle = BorderSkinStyle.None;
            Chart.SaveImage(chartPath);
            return true;
        }
Beispiel #13
0
        /// <summary>
        /// 统计某年某个测点各时段内值和
        /// </summary>
        /// <param name="plants"></param>
        /// <param name="chartname"></param>
        /// <param name="YYYYMM"></param>
        /// <param name="chartType"></param>
        /// <param name="unit"></param>
        /// <param name="monitorCode"></param>
        /// <param name="intervalMins"></param>
        /// <param name="weidu"></param>
        /// <returns></returns>
        public ChartData PlantYearSectionCountChart(IList<Plant> plants, string chartname, int YYYY, string chartType, string unit, int monitorCode, int intervalMins, int weidu)
        {
            //ChartData resChartData = null;
            //for (int i = 1; i <= months; i++)
            //{
            //    ChartData chartData = PlantMonthSectionCountChart(plants, chartname, YYYY + i.ToString("00"), chartType, unit, monitorCode, intervalMins, weidu);
            //    if (resChartData == null)
            //    {
            //        resChartData = chartData;
            //    }
            //    else
            //    {
            //        mergeHash(resChartData.series[0].data, chartData.series[0].data);
            //        mergeHash(resChartData.series[1].data, chartData.series[1].data);
            //    }
            //}
            //return resChartData;
            ChartData resChartData = null;
            //电费维度轴
            YData feeyData = new YData();
            YData[] newSeries = new YData[2];
            string[] newCategories = new string[4 + 1] { "峰", "平", "谷", "尖", "合计" };
            ///要进行多个电站累计,因为电站配置的
            float?[] newValues = new float?[5] { 0, 0, 0, 0, 0 };
            float?[] newFeeValues = new float?[5]{0,0,0,0,0};
            foreach (Plant plant in plants)
            {
                if (plant.allFactUnits == null || plant.allFactUnits.Count < 1) continue;
                Hashtable dataHash = CollectorYearDataService.GetInstance().GetYearDatasByUnits(plant.allFactUnits);
                if (dataHash == null || dataHash.Count < 1) continue;

                //取出本月数据
                object v = dataHash[YYYY.ToString()];
                float energy = v == null ? 0 : (float)v;

                //按照既定比率分拆
                ElecPrice[] sections = plant.ElecPriceList.ToArray();

                float rate = 0;
                ElecPrice x = null;
                //float max = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (sections == null || i >= sections.Length)
                    {
                        if (i == 0)
                        {//峰
                            rate = 0.4f;
                            x = new ElecPrice() { fromHm = "08:00", toHm = "12:00", price = "0.6" };
                        }
                        else if (i == 1)
                        {//平
                            rate = 0.45f;
                            x = new ElecPrice() { fromHm = "12:00", toHm = "18:00", price = "0.5" };
                        }
                        else if (i == 2)
                        {//谷
                            rate = 0.1f;
                            x = new ElecPrice() { fromHm = "18:00", toHm = "23:00", price = "0.2" };
                        }
                        else
                        {//尖
                            rate = 0.05f;
                            x = new ElecPrice() { fromHm = "01:00", toHm = "08:00", price = "0.4" };
                        }
                    }
                    else
                    {
                        x = sections[i];
                        if (string.IsNullOrEmpty(x.fromHm))
                        {
                            if (i == 0)
                            {//峰
                                rate = 0.4f;
                                x = new ElecPrice() { fromHm = "08:00", toHm = "12:00", price = "0.6" };
                            }
                            else if (i == 1)
                            {//平
                                rate = 0.45f;
                                x = new ElecPrice() { fromHm = "12:00", toHm = "18:00", price = "0.5" };
                            }
                            else if (i == 2)
                            {//谷
                                rate = 0.1f;
                                x = new ElecPrice() { fromHm = "18:00", toHm = "23:00", price = "0.2" };
                            }
                            else
                            {//尖
                                rate = 0.05f;
                                x = new ElecPrice() { fromHm = "01:00", toHm = "08:00", price = "0.4" };
                            }
                        }
                    }
                    newValues[i] = (newValues[i] == 0 ? 0 : newValues[i]) + energy * rate;
                    if (newValues[i] < 0) newValues[i] = 0;
                }

                //合计总发电量
                float? value = 0;
                for (int k = 0; k < 4; k++)
                {
                    value += newValues[k];
                }

                newValues[4] = value;

                //总=(峰电费+平电费+谷电费+尖电费)+(峰发电量 + 平发电量 + 谷发电量 + 尖发电量)*基础电价
                float? total = 0;
                for (int k = 0; k < 4; k++)
                {
                    newFeeValues[k] = newValues[k] * StringUtil.stringtoFloat(x.price);
                    total += newFeeValues[k];
                }
                //总电费
                newFeeValues[4] = total + value * plant.basePrice;//1是基础电价

                if (resChartData == null)
                {
                    YData yData = null;
                    resChartData = new ChartData();
                    resChartData.name = "年度峰平谷尖发电量和收入";
                    resChartData.isHasData = true;
                    yData = new YData();
                    yData.data = new float?[] { 0, 0, 0, 0, 0 };
                    yData.name = "发电量[kWh]";
                    yData.yAxis = "0";
                    yData.type = chartType;
                    yData.color = "#EF5808";

                    feeyData = new YData();
                    //将新的结果重新放到结果对象中
                    resChartData.categories = newCategories;
                    yData.data = newValues;
                    feeyData.data = newFeeValues;
                    feeyData.name = "收入[元]";
                    feeyData.yAxis = "1";
                    feeyData.type = chartType;
                    feeyData.color = "#4682B4";
                    //feeyData.max = max;
                    newSeries[0] = yData;
                    newSeries[1] = feeyData;
                    resChartData.series = newSeries;
                    resChartData.names = new String[] { "发电量", "收入" };
                    resChartData.units = new String[] { "kWh", "元" };
                    resChartData.colors = new String[] { "#EF5808", "#4682B4" };
                    resChartData.serieNo = DateTime.Now.ToString("ddhhmmss") + new Random().Next(1000);
                    TempDataUtil.putChartData(resChartData.serieNo, resChartData);
                }
                else
                {
                    mergeHash(resChartData.series[0].data, newValues);
                    mergeHash(resChartData.series[1].data, newFeeValues);
                }
            }
            if (resChartData == null) return new ChartData() { isHasData = false };
            //计算最大值
            float max = 0;
            for (int k = 0; k < 5; k++)
            {
                if (resChartData.series[0].data[k] > max) max = resChartData.series[0].data[k].Value;
            }
            resChartData.series[0].max = max * 1.2f;

            max = 0;
            for (int k = 0; k < 5; k++)
            {
                if (resChartData.series[1].data[k] > max) max = resChartData.series[1].data[k].Value;
            }
            resChartData.series[1].max = max * 1.2f;
            return resChartData;
        }