C# DEV Express Chart(二)

ChartControl staticsChart = new ChartControl();//create the chart control
        Series series1 = null;
        Series series2 = null;
        Series series3 = null;
        Series series4 = null;
/// <summary>
        /// config the format for doughnut3D
        /// </summary>
        private void AddDoughnut3D() 
        {
            series1= new Series("Doughnut Sereis 1", ViewType.Doughnut3D);//add series1
            ChangeTheDouguntData();
            staticsChart.Series.Add(series1);
            series1.Label.TextPattern = "{A}{VP:0%}";
            ((Doughnut3DSeriesView)series1.View).HoleRadiusPercent=45;
            //((Doughnut3DSeriesView)series1.View).ExplodedPoints.Add(series1.Points[0]);export diagram
            ((SimpleDiagram3D)staticsChart.Diagram).RotationType = RotationType.UseAngles;
            ((SimpleDiagram3D)staticsChart.Diagram).RotationAngleX = -35;
            SetChartFormat();
        }
  private void SetChartFormat() 
        {
            staticsChart.CrosshairOptions.ShowArgumentLabels = true;
            staticsChart.CrosshairOptions.ShowArgumentLine = true;
            staticsChart.CrosshairOptions.ShowCrosshairLabels = true;
            staticsChart.BackColor = Color.Transparent;
            staticsChart.PaletteBaseColorNumber = 1;
            staticsChart.PaletteName = "Green";
            staticsChart.Titles.Clear();
            ChartTitle chartTitle1 = new ChartTitle();
            staticsChart.Text = "Data Graphics";
            staticsChart.Titles.Add(chartTitle1);
            staticsChart.Legend.UseCheckBoxes = false;
            staticsChart.Legend.Direction = LegendDirection.LeftToRight;
            staticsChart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center;
            staticsChart.Dock = DockStyle.Fill;
            this.pnlAddDiagram.Controls.Add(staticsChart);
        }
 private void ChangeTheDouguntData()
        {
            DataTable diagramData = GetAllEmployeeDaySummary();
            int attendanceNumber = 0;
            int delaysNumber = 0;
            int absencesNumber = 0;
            int exceptionNumber = 0;
            if (diagramData.Rows.Count > 0)
            {
                attendanceNumber = diagramData.Select("pc_code=2" + " and pc_results>0").Length;
                delaysNumber = diagramData.Select("pc_code=6" + " and pc_results>0").Length;
                absencesNumber = diagramData.Select("pc_code=8" + " and pc_results>0").Length;
                exceptionNumber = diagramData.Select("pc_code in(11,12) " + " and pc_results>0").Length;
            }
            series1.Points.AddRange(new SeriesPoint[]{
            new SeriesPoint("Attendance",attendanceNumber),
            new SeriesPoint("Delays",delaysNumber),
            new SeriesPoint("Absences",absencesNumber),
            new SeriesPoint("Exception",exceptionNumber)});
        }

第二部分是柱状图,思路和饼状图差不多,series设置的不一样。

private void AddBar3DChart() 
        {
            series1 = new Series("Attendance", ViewType.Bar3D);
            series2 = new Series("Delays", ViewType.Bar3D);
            series3 = new Series("Absences", ViewType.Bar3D);
            series4 = new Series("Exception", ViewType.Bar3D);
            if (cmbType.SelectedIndex == 1)
            {
                ChangeEmployeeBarData();
            }
            else if (cmbType.SelectedIndex == 2) 
            {
                ChangeDepartmentBarData();
            }
            staticsChart.Series.AddRange(new Series[] { series1, series2, series3, series4 });
            //series1.Label.ResolveOverlappingMode = ResolveOverlappingMode.Default;

            #region set the series view's value
            Bar3DSeriesView myView1 = (Bar3DSeriesView)series1.View;
            myView1.BarDepthAuto = false;
            myView1.BarDepth = 0.2;
            myView1.BarWidth = 0.5;
            Bar3DSeriesView myView2 = (Bar3DSeriesView)series2.View;
            
            myView2.BarDepthAuto = false;
            myView2.BarDepth = 0.2;
            myView2.BarWidth = 0.5;
            Bar3DSeriesView myView3 = (Bar3DSeriesView)series3.View;
            myView3.BarDepthAuto = false;
            myView3.BarDepth = 0.2;
            myView3.BarWidth = 0.5;
            Bar3DSeriesView myView4 = (Bar3DSeriesView)series4.View;
            myView4.BarDepthAuto = false;
            myView4.BarDepth = 0.2;
            myView4.BarWidth = 0.5;
            #endregion

            XYDiagram3D myDiagram = (XYDiagram3D)staticsChart.Diagram;
            myDiagram.RotationType = RotationType.UseAngles;
            myDiagram.RotationOrder = RotationOrder.XYZ;
            myDiagram.RotationAngleX = 0;
            myDiagram.RotationAngleY = 0;
            myDiagram.RotationAngleZ = 270;
            myDiagram.RuntimeScrolling = true;
            SetChartFormat();
        }


private void ChangeDepartmentBarData() 
        {
            List<Employee> empList = treeModule.CheckedEmps;
            List<Department> depList = treeModule.CheckedDepartment;
            DateTime fromDate = dteFromDate.DateTime;
            DateTime endDate = dteEndDate.DateTime;
            List<DaySummary> dsList = new DaySummaryBLL().GetEmployeesDailySummary(empList, fromDate, endDate);
            List<Paycode> paycodeList = new PaycodeBLL().GetMainFields();
            var dsPaycodeList = from ds in dsList
                                join p in paycodeList on ds.paycode.id equals p.id
                                where ds.pc_results > 0
                                orderby ds.employee.id ascending, ds.att_date descending
                                select new { ID = ds.employee.id, Minutes = ds.pc_results, Date = ds.att_date, Paycode = p.pc_code };
            foreach (Department dep in depList) 
            {
                int attendanceDay = 0;
                int delaysDay = 0;
                int absencesDay = 0;
                int ExceptionDay = 0;
                List<Employee> depEmpList = new EmployeeBLL().GetMainFields(string.Format("where e.department.id={0}", dep.id));
                foreach (Employee employee in depEmpList)
                {
                    attendanceDay += dsPaycodeList.Count(dspaycode => dspaycode.ID == employee.id && dspaycode.Paycode == 2);
                    delaysDay += dsPaycodeList.Count(dspaycode => dspaycode.ID == employee.id && dspaycode.Paycode == 6);
                    absencesDay += dsPaycodeList.Count(dspaycode => dspaycode.ID == employee.id && dspaycode.Paycode == 8);
                    ExceptionDay += dsPaycodeList.Count(dspaycode => dspaycode.ID == employee.id && dspaycode.Paycode == 11) +
                        dsPaycodeList.Count(dspaycode => dspaycode.ID == employee.id && dspaycode.Paycode == 12);
                }
                series1.Points.Add(new SeriesPoint(dep.dept_name.ToString(), attendanceDay));
                series2.Points.Add(new SeriesPoint(dep.dept_name.ToString(), delaysDay));
                series3.Points.Add(new SeriesPoint(dep.dept_name.ToString(), absencesDay));
                series4.Points.Add(new SeriesPoint(dep.dept_name.ToString(), ExceptionDay));
            }
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值