DevXpress控件: 第二篇--将绘图进行到底: Charter控件(附图)

一. 2D

1. 散点图

  1. 散点图--CreatedBy FQGUO 
  2. this.xtraTabControl1.TabPages.Add("普通散点图");             
  3. ChartControl pointChart = new ChartControl();             
  4. Series series1 = new Series("序列一", ViewType.Point);             
  5. series1.ArgumentScaleType = ScaleType.Numerical;             
  6. ((PointSeriesView)series1.View).PointMarkerOptions.Kind = MarkerKind.Triangle;             
  7. //加点             
  8. series1.Points.Add(new SeriesPoint(1, new double[] { 10 }));             
  9. series1.Points.Add(new SeriesPoint(2, new double[] { 12 }));             
  10. series1.Points.Add(new SeriesPoint(3, new double[] { 14 }));             
  11. series1.Points.Add(new SeriesPoint(4, new double[] { 17 }));             
  12. series1.Points.Add(new SeriesPoint(5, new double[] { 21 }));             
  13. series1.Points.Add(new SeriesPoint(6, new double[] { 26 }));             
  14. series1.Points.Add(new SeriesPoint(7, new double[] { 29 }));             
  15. series1.Points.Add(new SeriesPoint(8, new double[] { 30 }));             
  16. Series series2 = new Series("序列二", ViewType.Point);             
  17. series2.ArgumentScaleType = ScaleType.Numerical;             
  18. ((PointSeriesView)series2.View).PointMarkerOptions.Kind = MarkerKind.Cross;             
  19. //加点             
  20. series2.Points.Add(new SeriesPoint(1, new double[] { 15 }));            
  21. series2.Points.Add(new SeriesPoint(2, new double[] { 18 }));             
  22. series2.Points.Add(new SeriesPoint(3, new double[] { 25 }));             
  23. series2.Points.Add(new SeriesPoint(4, new double[] { 33 }));             
  24. series2.Points.Add(new SeriesPoint(5, new double[] { 35 }));             
  25. series2.Points.Add(new SeriesPoint(6, new double[] { 41 }));             
  26. series2.Points.Add(new SeriesPoint(7, new double[] { 44 }));             
  27. series2.Points.Add(new SeriesPoint(8, new double[] { 50 }));             
  28. pointChart.Series.Add(series1);            pointChart.Series.Add(series2);             
  29. // 显示标签.             
  30. pointChart.Legend.Visible = true;             
  31. // 不允许旋转90度.             
  32. ((XYDiagram)pointChart.Diagram).Rotated = false; ;             
  33. //加入到tab中             
  34. pointChart.Dock = DockStyle.Fill;            pointChart.Size = new System.Drawing.Size(400, 250);                      
  35. int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;             
  36. this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(pointChart);            this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 
  37.   

 

 2. 折线图

Code:

  1. 折线图--CreateByFQGUO
  2. this.xtraTabControl1.TabPages.Add("普通折线图");
  3. ChartControl lineChart = new ChartControl();
  4. Series series1 = new Series("通过人数", ViewType.Line);
  5. series1.ArgumentScaleType = ScaleType.Numerical;
  6. ((LineSeriesView)series1.View).LineMarkerOptions.Kind = MarkerKind.Triangle;
  7. ((LineSeriesView)series1.View).LineStyle.DashStyle = DashStyle.Dash;
  8. series1.Points.Add(new SeriesPoint(1, new double[] { 2 }));
  9. series1.Points.Add(new SeriesPoint(2, new double[] { 3 }));
  10. series1.Points.Add(new SeriesPoint(3, new double[] { 4 }));
  11. series1.Points.Add(new SeriesPoint(4, new double[] { 6 }));
  12. series1.Points.Add(new SeriesPoint(5, new double[] { 8 }));
  13. series1.Points.Add(new SeriesPoint(6, new double[] { 10 }));
  14. series1.Points.Add(new SeriesPoint(7, new double[] { 12 }));
  15. series1.Points.Add(new SeriesPoint(8, new double[] { 15 }));
  16. Series series2 = new Series("报名人数", ViewType.Line);
  17. series2.ArgumentScaleType = ScaleType.Numerical;
  18. ((LineSeriesView)series2.View).LineMarkerOptions.Kind = MarkerKind.Cross;
  19. ((LineSeriesView)series2.View).LineStyle.DashStyle = DashStyle.DashDotDot;
  20. series2.Points.Add(new SeriesPoint(1, new double[] { 3 }));
  21. series2.Points.Add(new SeriesPoint(2, new double[] { 5 }));
  22. series2.Points.Add(new SeriesPoint(3, new double[] { 6 }));
  23. series2.Points.Add(new SeriesPoint(4, new double[] { 7 }));
  24. series2.Points.Add(new SeriesPoint(5, new double[] { 11 }));
  25. series2.Points.Add(new SeriesPoint(6, new double[] { 13 }));
  26. series2.Points.Add(new SeriesPoint(7, new double[] { 15 }));
  27. series2.Points.Add(new SeriesPoint(8, new double[] { 18 }));
  28. lineChart.Series.Add(series1); lineChart.Series.Add(series2); lineChart.Legend.Visible = true;
  29. ((XYDiagram)lineChart.Diagram).Rotated = false;
  30. lineChart.Dock = DockStyle.Fill; lineChart.Size = new System.Drawing.Size(400, 250);
  31. this.Controls.Add(lineChart);
  32. int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;
  33. this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChart); this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;

3. 柱状图

4. 饼图

5. 任务进度图

Code:

  1. CreatedBy -FQGUO this.xtraTabControl1.TabPages.Add("任务进度图");
  2. ChartControl ganttChart = new ChartControl();
  3. Series series1 = new Series("计划", ViewType.Gantt);
  4. ganttChart.Series.Add(series1); series1.Label.Visible = false; ((GanttSeriesView)series1.View).BarWidth = 0.6;
  5. series1.ArgumentScaleType = ScaleType.Qualitative;
  6. series1.ValueScaleType = ScaleType.DateTime;
  7. series1.Points.Add(new SeriesPoint("需求分析", new DateTime[] {
  8. new DateTime(2008, 10, 16), new DateTime(2008, 10, 23) }));
  9. series1.Points.Add(new SeriesPoint("工程架构", new DateTime[] {
  10. new DateTime(2008, 10, 23), new DateTime(2008, 10, 28) }));
  11. series1.Points.Add(new SeriesPoint("开发测试", new DateTime[] {
  12. new DateTime(2008, 10, 28), new DateTime(2008, 11, 26) }));
  13. series1.Points.Add(new SeriesPoint("部署上线", new DateTime[] {
  14. new DateTime(2008, 11, 26), new DateTime(2008, 12, 10) }));
  15. ((GanttSeriesView)series1.View).LinkOptions.ArrowHeight = 7;
  16. ((GanttSeriesView)series1.View).LinkOptions.ArrowWidth = 11;
  17. for (int i = 1; i < series1.Points.Count; i++)
  18. {
  19. series1.Points[i].Relations.Add(series1.Points[i - 1]);
  20. }
  21. Series series2 = new Series("执行", ViewType.Gantt);
  22. ganttChart.Series.Add(series2); series2.Label.Visible = false; ((GanttSeriesView)series2.View).BarWidth = 0.3;
  23. series2.ArgumentScaleType = ScaleType.Qualitative;
  24. series2.ValueScaleType = ScaleType.DateTime;
  25. series2.Points.Add(new SeriesPoint("需求分析", new DateTime[] {
  26. new DateTime(2008, 10, 16), new DateTime(2008, 10, 23) }));
  27. series2.Points.Add(new SeriesPoint("工程架构", new DateTime[] {
  28. new DateTime(2008, 10, 23), new DateTime(2008, 10, 26) }));
  29. series2.Points.Add(new SeriesPoint("开发测试", new DateTime[] {
  30. new DateTime(2008, 10, 26), new DateTime(2008, 11, 10) }));
  31. series2.Points.Add(new SeriesPoint("部署上线", new DateTime[] {
  32. new DateTime(2008, 11, 10), new DateTime(2008, 12, 1) }));
  33. ConstantLine progress = new ConstantLine("当前进度", new DateTime(2008, 11,28 ));
  34. progress.ShowInLegend = false; progress.Title.Alignment = ConstantLineTitleAlignment.Far;
  35. ((GanttDiagram)ganttChart.Diagram).AxisY.ConstantLines.Add(progress);
  36. ChartTitle title = new ChartTitle(); title.Text ="任务进度表--Created By fqguo(子逸)";
  37. ganttChart.Titles.Add(title);
  38. ganttChart.Dock = DockStyle.Fill; ganttChart.Size = new System.Drawing.Size(500, 300);
  39. ganttChart.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right; ((GanttDiagram)ganttChart.Diagram).AxisY.Interlaced = true;
  40. ((GanttDiagram)ganttChart.Diagram).AxisY.GridSpacing = 10;
  41. ((GanttDiagram)ganttChart.Diagram).AxisY.Label.Angle = -30;
  42. ((GanttDiagram)ganttChart.Diagram).AxisY.Label.Antialiasing = true;
  43. ((GanttDiagram)ganttChart.Diagram).AxisY.DateTimeOptions.Format = DateTimeFormat.MonthAndDay;
  44. int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;
  45. this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(ganttChart); this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;

二. 3D

1. 堆叠立柱体

Code:

  1. 堆叠立柱体--CreatedByFQGUO this.xtraTabControl1.TabPages.Add("堆叠立柱体");
  2. ChartControl barChart = new ChartControl();
  3. Series series1 = new Series("通过人数", ViewType.StackedBar3D);
  4. series1.Points.Add(new SeriesPoint("I", new double[] { 10 }));
  5. series1.Points.Add(new SeriesPoint("II", new double[] { 20 }));
  6. series1.Points.Add(new SeriesPoint("III", new double[] { 40 }));
  7. series1.Points.Add(new SeriesPoint("IV", new double[] { 60 }));
  8. Series series2 = new Series("报名人数", ViewType.StackedBar3D);
  9. series2.Points.Add(new SeriesPoint("I", new double[] { 15 }));
  10. series2.Points.Add(new SeriesPoint("II", new double[] { 25 }));
  11. series2.Points.Add(new SeriesPoint("III", new double[] { 35 }));
  12. series2.Points.Add(new SeriesPoint("IV", new double[] { 45 }));
  13. barChart.Series.Add(series2); barChart.Series.Add(series1); barChart.Legend.Visible = true;
  14. barChart.Dock = DockStyle.Fill;
  15. barChart.Size = new System.Drawing.Size(400, 250);
  16. int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;
  17. this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(barChart); this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;

2. 饼形3D图

3. 分层区图

4. 堆叠区图

5. 曼哈顿三维

Code:

  1. 曼哈顿三维--CreateByFQUOthis.xtraTabControl1.TabPages.Add(" 曼哈顿三维");
  2. ChartControl mhtChart = new ChartControl();
  3. Series series1 = new Series("2007", ViewType.ManhattanBar); series1.ArgumentScaleType = ScaleType.Numerical;
  4. series1.Points.Add(new SeriesPoint(1, new double[] { 2 }));
  5. series1.Points.Add(new SeriesPoint(2, new double[] { 5 }));
  6. series1.Points.Add(new SeriesPoint(3, new double[] { 6 }));
  7. series1.Points.Add(new SeriesPoint(4, new double[] { 7 }));
  8. series1.Points.Add(new SeriesPoint(5, new double[] { 7 }));
  9. Series series2 = new Series("2008", ViewType.ManhattanBar); series2.ArgumentScaleType = ScaleType.Numerical;
  10. series2.Points.Add(new SeriesPoint(1, new double[] { 4 }));
  11. series2.Points.Add(new SeriesPoint(2, new double[] { 6 }));
  12. series2.Points.Add(new SeriesPoint(3, new double[] { 7 }));
  13. series2.Points.Add(new SeriesPoint(4, new double[] { 8 }));
  14. series2.Points.Add(new SeriesPoint(5, new double[] { 9 }));
  15. Series series3 = new Series("2008", ViewType.ManhattanBar); series3.ArgumentScaleType = ScaleType.Numerical;
  16. series3.Points.Add(new SeriesPoint(1, new double[] { 1 }));
  17. series3.Points.Add(new SeriesPoint(2, new double[] { 2 }));
  18. series3.Points.Add(new SeriesPoint(3, new double[] { 3 }));
  19. series3.Points.Add(new SeriesPoint(4, new double[] { 4 }));
  20. series3.Points.Add(new SeriesPoint(5, new double[] { 5 }));
  21. mhtChart.Series.Add(series2); mhtChart.Series.Add(series1); mhtChart.Series.Add(series3); mhtChart.Legend.Visible = true;
  22. ((XYDiagram3D)mhtChart.Diagram).RuntimeRotation = true;
  23. mhtChart.Dock = DockStyle.Fill;
  24. mhtChart.Size = new System.Drawing.Size(400, 250);
  25. int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;
  26. this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(mhtChart); this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;

6.梯线体

posted @ 2012-08-23 11:28  许海彪  阅读(2031)  评论(1编辑  收藏  举报