private void createStaPie() { DataTable dt = new DataTable(); dt.Columns.Add("序号", typeof(int)); dt.Columns.Add("损失评估类型"); dt.Columns.Add("评估值(元)", typeof(decimal)); dt.Rows.Add(new object[] { 1, "海水养殖业", MainForm.breeding_num }); dt.Rows.Add(new object[] { 2, "滨海旅游业", MainForm.tourism_num }); dt.Rows.Add(new object[] { 3, "赤潮应急监测", MainForm.monitoring_num }); dt.Rows.Add(new object[] { 4, "赤潮处置", MainForm.disposing_num }); Series sr = new Series("评估值", ViewType.Pie); //绑定数据源 sr.DataSource = dt.DefaultView; //newdtb是获取到的数据(可以是数据库中的表,也可以是DataTable) sr.ArgumentDataMember = "损失评估类型"; //绑定的文字信息(名称)(坐标横轴) sr.ValueDataMembers[0] = "评估值(元)"; //绑定的值(数据)(坐标纵轴) sr.ArgumentScaleType = ScaleType.Qualitative; //定性的 sr.ValueScaleType = ScaleType.Numerical; //数字类型 sr.LegendPointOptions.PointView = PointView.Argument; //显示表示的信息和数据 sr.LegendPointOptions.ValueNumericOptions.Format = NumericFormat.Percent; //用百分比表示 sr.LegendText = "图例"; sr.Label.PointOptions.PointView = PointView.ArgumentAndValues; // 设置Label显示方式 //sr.ToolTipPointPattern = "hello world"; // 自定义ToolTip显示 sr.ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True; // 设置鼠标悬浮显示toolTip //sr.Label.PointOptions.ValueNumericOptions.Format = NumericFormat.FixedPoint; //sr.ValueScaleType = ScaleType.Numerical; //sr.Label.PointOptions.ValueNumericOptions.Precision = 2; //样式 //sr.View.Color = Color.Red;//颜色 //添加到统计图上 chartControl2.Series.Add(sr); //图例设置 SimpleDiagram3D diagram = new SimpleDiagram3D(); diagram.RuntimeRotation = true; diagram.RuntimeScrolling = true; diagram.RuntimeZooming = true; //设置图表标题 ChartTitle ct = new ChartTitle(); ct.Text = "赤潮灾害损失评估统计(饼图)"; ct.TextColor = Color.Black; //颜色 ct.Font = new Font("宋体", 15, FontStyle.Bold); //字体 ct.Dock = ChartTitleDockStyle.Top; //停靠在上方 ct.Alignment = StringAlignment.Center; //居中显示 chartControl2.Titles.Add(ct); chartControl2.Legend.Visible = false; //不现实指示图 }
private void CreateChart(DataTable dt, DataTable dt2) { #region Chart control 1 //Assign data source to series series1.DataSource = dt; series2.DataSource = dt; series3.DataSource = dt; series4.DataSource = dt; // Specify data members to bind the series. //series.ArgumentScaleType = ScaleType.Numerical; series1.ArgumentDataMember = "att_date"; series1.ValueScaleType = ScaleType.Numerical; series1.ValueDataMembers.AddRange(new string[] { "total" }); series2.ArgumentDataMember = "att_date"; series2.ValueScaleType = ScaleType.Numerical; series2.ValueDataMembers.AddRange(new string[] { "absent" }); series3.ArgumentDataMember = "att_date"; series3.ValueScaleType = ScaleType.Numerical; series3.ValueDataMembers.AddRange(new string[] { "running_total" }); series4.ArgumentDataMember = "att_date"; series4.ValueScaleType = ScaleType.Numerical; series4.ValueDataMembers.AddRange(new string[] { "absent_rate" }); #endregion #region Chart control 2 chartControl2.Series.Clear(); seriesPie.Points.Clear(); seriesPie.Points.Add(new SeriesPoint("Nghỉ phát sinh( " + dt2.Rows[0]["A02"].ToString() + " )", Convert.ToInt64(dt2.Rows[0]["A02"]))); seriesPie.Points.Add(new SeriesPoint("Nghỉ nửa ngày( " + dt2.Rows[0]["A03"].ToString() + " )", Convert.ToInt64(dt2.Rows[0]["A03"]))); seriesPie.Points.Add(new SeriesPoint("Việc riêng không lương( " + dt2.Rows[0]["A04"].ToString() + " )", Convert.ToInt64(dt2.Rows[0]["A04"]))); seriesPie.Points.Add(new SeriesPoint("Nghỉ thai sản( " + dt2.Rows[0]["A05"].ToString() + " )", Convert.ToInt64(dt2.Rows[0]["A05"]))); seriesPie.Points.Add(new SeriesPoint("Nghỉ phép năm( " + dt2.Rows[0]["A06"].ToString() + " )", Convert.ToInt64(dt2.Rows[0]["A06"]))); seriesPie.Points.Add(new SeriesPoint("Nghỉ đào tạo( " + dt2.Rows[0]["A09"].ToString() + " )", Convert.ToInt64(dt2.Rows[0]["A09"]))); seriesPie.Points.Add(new SeriesPoint("Nghỉ công tác( " + dt2.Rows[0]["A10"].ToString() + " )", Convert.ToInt64(dt2.Rows[0]["A10"]))); // Add the series to the chart. chartControl2.Series.Add(seriesPie); // Adjust the value numeric options of the series. seriesPie.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent; seriesPie.PointOptions.ValueNumericOptions.Precision = 0; // Adjust the view-type-specific options of the series. ((Pie3DSeriesView)seriesPie.View).Depth = 15; ((Pie3DSeriesView)seriesPie.View).ExplodedPoints.Add(seriesPie.Points[PointName(dt2)]); ((Pie3DSeriesView)seriesPie.View).ExplodedDistancePercentage = 30; //// Access the diagram's options. //((SimpleDiagram3D)chartControl2.Diagram).RotationType = RotationType.UseAngles; //((SimpleDiagram3D)chartControl2.Diagram).RotationAngleX = -35; // Cast Diagram to the SimpleDiagram3D type. SimpleDiagram3D diagram3D = chartControl2.Diagram as SimpleDiagram3D; if (diagram3D != null) { diagram3D.RuntimeRotation = true; diagram3D.RuntimeZooming = true; diagram3D.ZoomingOptions.UseMouseWheel = true; } // Control legend & position chartControl2.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True; chartControl2.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center; chartControl2.Legend.AlignmentVertical = LegendAlignmentVertical.BottomOutside; chartControl2.Legend.Direction = LegendDirection.LeftToRight; seriesPie.LegendPointOptions.PointView = PointView.Argument; //chartControl2.Legend.Direction = LegendDirection.LeftToRight; chartControl2.Legend.EquallySpacedItems = true; #endregion }