コード例 #1
0
ファイル: ReportBuilder.cs プロジェクト: dalinhuang/loosoft
        /// <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));
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: ReportBuilder.cs プロジェクト: codingsf/loosoft
        /// <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));
        }
コード例 #4
0
        /// <summary>
        /// 统计某天某个测点各时段内值和
        /// </summary>
        /// <param name="plants"></param>
        /// <param name="chartname"></param>
        /// <param name="YYYYMMDD"></param>
        /// <param name="chartType"></param>
        /// <param name="unit"></param>
        /// <param name="monitorCode"></param>
        /// <param name="intervalMins"></param>
        /// <param name="sections">时间段集合,需要按照</param>
        /// <returns></returns>
        public ChartData PlantDaySectionCountChart(IList<Plant> plants, string chartname, string YYYYMMDD, string chartType, string unit, int monitorCode, int intervalMins, int weidu)
        {
            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)
            {
                ChartData chartData = PlantDayChart(plant, chartname, YYYYMMDD + "00", YYYYMMDD + "23", chartType, unit, monitorCode, intervalMins);
                //按照时段进行分拆
                int day = int.Parse(YYYYMMDD.Substring(4, 2));
                ElecPrice[] sections = plant.ElecPriceList.ToArray();

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

                    key = getKeyPointWithMid(intervalMins, x.fromHm.Replace(":",""),":");

                    //从数据中取出对应坐标的值
                    int index = getIndexinArr(chartData.categories, key);
                    //通过下标从数据数据中找到数据
                    float? startValue = chartData.isHasData?getValueinArr(chartData.series[0].data, index, false):0;
                    key = getKeyPointWithMid(intervalMins, x.toHm.Replace(":", ""), ":");
                    //从数据中取出对应坐标的值
                    index = getIndexinArr(chartData.categories, key);
                    float? endValue = chartData.isHasData?getValueinArr(chartData.series[0].data, index, true):0;
                    newValues[i] = (newValues[i] == 0 ? 0 : newValues[i]) + (endValue == null ? 0 : endValue) - (startValue == null ? 0 : startValue);
                    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 = chartData;
                    resChartData.name = "日峰平谷尖发电量和收入";
                    if (!chartData.isHasData)
                    {
                        yData = new YData();
                        yData.data = new float?[] {0,0,0,0,0};
                        yData.name = "发电量[kWh]";
                        yData.yAxis = "0";
                        yData.type = chartType;
                    }
                    else {
                        yData = chartData.series[0];
                    }
                    feeyData = new YData();
                    //将新的结果重新放到结果对象中
                    resChartData.categories = newCategories;
                    yData.data = newValues;
                    feeyData.data = newFeeValues;
                    feeyData.name = "收入[元]";
                    feeyData.yAxis = "1";
                    feeyData.type = chartType;
                    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 (chartData.isHasData && !resChartData.isHasData)
                {
                    resChartData.isHasData = true;
                }
            }
            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;
        }