Exemple #1
0
        /// <summary>
        /// 判断是否要转数值
        /// </summary>
        /// <param name="tblReport"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        protected virtual bool CheckConvertNumeric(DataTable tblReport, int index, out double maxValue)
        {
            bool bResult = false;

            maxValue = 0;
            var rows = from r in tblReport.Select("1=1")
                       select r;

            if (rows.Count() > 0)
            {
                if (rows.Where(r => r[index] != null).Count() > 0)
                {
                    maxValue = rows.Where(r => r[index] != System.DBNull.Value).Max(r => Convert.ToDouble(r[index]));
                    if (NumericExtension.ConvertTimes(maxValue) > 1)
                    {
                        bResult = true;
                    }
                }
            }
            return(bResult);
        }
Exemple #2
0
        /// <summary>
        /// 图表数据绑定
        /// </summary>
        protected virtual void ChartDataBind()
        {
            List <ReportingData> tblReport = this.reportData;

            int rowCount = tblReport.Count;

            #region 判断最大值
            double maxValue = 0;
            //bool checkConvertNumeric = this.CheckConvertNumeric(tblReport, 0, out maxValue);
            bool   checkConvertNumeric = false;
            string strUnit             = string.Empty;
            int    maxLength           = NumericExtension.GetValueLength(maxValue);
            if (checkConvertNumeric == true)
            {
                strUnit = NumericExtension.ConvertUnit(maxValue);
                this.chart.ChartAreas[ReportingChart.DefaultChartAreaName].AxisY.Title           = "数量级单位:" + strUnit;
                this.chart.ChartAreas[ReportingChart.DefaultChartAreaName].AxisY.TitleAlignment  = System.Drawing.StringAlignment.Center;
                this.chart.ChartAreas[ReportingChart.DefaultChartAreaName].AxisY.TextOrientation = TextOrientation.Stacked;
            }
            #endregion
            var RowCount = rowCount;

            // var MarkCount = this.reportData.MarkFieldList.Count();
            var    deleteList        = new List <Series>();
            double axisYValueDivisor = 0;//除数
            if (dicPrm.ContainsKey("axisYValueDivisor"))
            {
                double.TryParse(dicPrm["axisYValueDivisor"], out axisYValueDivisor);
            }
            foreach (var curSeries in chart.Series)
            {
                var seriesObj = this.reportingSeries.Where(c => c.name.Trim() == curSeries.Name.Trim()).FirstOrDefault();
                if (seriesObj != null)
                {
                    tblReport = seriesObj.reportingData;
                    //curSeries.ToolTip = "所属名称:  #VALX\n 值: #VALY{C}" + strUnit;
                    if (dicPrm.ContainsKey("toolTip"))
                    {
                        curSeries.ToolTip = dicPrm["toolTip"];
                    }
                    else
                    {
                        curSeries.ToolTip = curSeries.Name + "&" + "#VALX&#VALY";
                    }
                    foreach (var obj in tblReport)
                    {
                        double yVaule = 0;
                        yVaule = obj.statistics;
                        if (axisYValueDivisor != 0)
                        {
                            yVaule = yVaule / axisYValueDivisor;
                        }
                        //yVaule = NumericExtension.ConvertNumeric(yVaule, maxLength);
                        curSeries.Points.AddXY(obj.groupByName, yVaule);
                    }
                }
                else
                {
                    deleteList.Add(curSeries);
                }
            }
            foreach (var delObj in deleteList)
            {
                chart.Series.Remove(delObj);
            }

            //是否分离饼图的分块
            if (this.dicPrm.ContainsKey("isExplodedAllPoint"))
            {
                bool isExplodedAllPoint = false;
                bool.TryParse(dicPrm["isExplodedAllPoint"], out isExplodedAllPoint);
                foreach (var serie in chart.Series)
                {
                    int explodeDistance = 5;//默认分离5个像素
                    if (dicPrm.ContainsKey("explodedDistance"))
                    {
                        int.TryParse(dicPrm["explodedDistance"], out explodeDistance);
                    }
                    if (serie.Points.Count > 1)
                    {
                        serie.BorderColor     = chart.ChartAreas.FirstOrDefault().BackColor;
                        serie.BorderDashStyle = ChartDashStyle.Solid;
                        serie.BorderWidth     = explodeDistance;
                    }
                }
                //当Point的数目大于4时,将label放到图外面;
            }

            //更改横坐标的角度
            if (this.dicPrm.ContainsKey("axisXLabelAngle"))
            {
                int axisXLabelAngle = 0;
                int.TryParse(dicPrm["axisXLabelAngle"], out axisXLabelAngle);
                foreach (var chartArea in chart.ChartAreas)
                {
                    chartArea.AxisX.IsLabelAutoFit   = false;
                    chartArea.AxisX.LabelStyle.Angle = axisXLabelAngle;
                }
            }

            //添加单位
            if (dicPrm.ContainsKey("axisYUnit"))
            {
                string axisXUnit = dicPrm["axisYUnit"];
                var    chartArea = chart.ChartAreas.FirstOrDefault();
                if (chartArea != null)
                {
                    chartArea.AxisY.Title           = axisXUnit;
                    chartArea.AxisY.TextOrientation = TextOrientation.Rotated270;
                }
            }
            //设置Y轴间隔
            if (dicPrm.ContainsKey("axisYInterval"))
            {
                double axisYInterval = 1;
                var    chartArea     = chart.ChartAreas.FirstOrDefault();
                if (chartArea != null && double.TryParse(dicPrm["axisYInterval"], out axisYInterval))
                {
                    chartArea.AxisY.Interval = axisYInterval;
                }
            }

            //去除无用的legend
            if (chart.Series.Count == 1 &&//只有一个Series
                (chart.Series[0].ChartType != SeriesChartType.Pie && chart.Series[0].ChartType != SeriesChartType.Doughnut) &&//不为饼图
                chart.Series[0].Name == ReportingChart.DefaultSerieName && chart.Legends.Count > 0)   //名字为DefaultSeries,不显示legend;
            {
                chart.Series[0].IsVisibleInLegend = false;
            }

            //设置饼图或甜甜圈的颜色
            if (chart.Series.Count == 1 && (chart.Series[0].ChartType == SeriesChartType.Pie || chart.Series[0].ChartType == SeriesChartType.Doughnut))//设置饼图的颜色
            {
                double invalidValue = 0;
                if (dicPrm.ContainsKey("collectedPercentage"))
                {
                    double.TryParse(dicPrm["collectedPercentage"], out invalidValue);
                }
                //去除无效数据
                foreach (var serie in chart.Series)
                {
                    List <DataPoint> voidPoints = serie.Points.Where(c => c.YValues.FirstOrDefault() <= invalidValue).ToList();
                    foreach (var voidPoint in voidPoints)
                    {
                        serie.Points.Remove(voidPoint);
                    }
                }
                chart.FilterPieChartColor();//更改饼图中的颜色
            }

            //设置曲线图中值为0的显示
            foreach (var serie in chart.Series)
            {
                if (serie.ChartType == SeriesChartType.Line || serie.ChartType == SeriesChartType.Spline || serie.ChartType == SeriesChartType.StepLine)
                {
                    var emptyPoints = serie.Points.Where(c => c.YValues.FirstOrDefault() == 0).ToList();
                    foreach (var emptypoint in emptyPoints)
                    {
                        emptypoint.IsEmpty = true;
                    }
                }
            }

            //不显示值为0的点的label
            var points = from s in chart.Series
                         from p in s.Points
                         where p.YValues[0] <= 0
                         select p;
            foreach (var point in points)
            {
                point.IsEmpty = true;
            }

            //调整柱状图的每个柱体的宽度
            if (chart.Series.Count > 0 && chart.Series.All(c => c.ChartType == SeriesChartType.Column))
            {
                chart.FilterSeriesWidth();
            }

            //合并饼图中较小的值
            if (chart.Series.All(c => c.ChartType == SeriesChartType.Pie || c.ChartType == SeriesChartType.Doughnut) && dicPrm.ContainsKey("CollectedThreshold"))
            {
                double collectedThreshold = 1.0;
                double.TryParse(dicPrm["CollectedThreshold"], out collectedThreshold);
                chart.CollectPieSlices(collectedThreshold);
            }

            if (dicPrm.ContainsKey("PieLabelLineLiminalValue"))
            {
                double liminalValue = 100.0;
                double.TryParse(dicPrm["PieLabelLineLiminalValue"], out liminalValue);
                chart.FilterPieLabelLine(liminalValue);
            }
        }