词条 | XtraCharts |
释义 | XtraCharts是Dev控件包一大重要控件,涵盖了一个画图控件的所有需要输出的效果,并提供了一些特色功能,并直接从流输出不需要产生临时图片文件。本文介绍一些常用的属性以及方法。 命名空间引用添加 using DevExpress.XtraCharts; using DevExpress.XtraCharts.Web; using DevExpress.XtraCharts.Native; 数据绑定 private void ChartBinding(object sender) { string Str_SQL = "select top 7 UnitPrice,UnitsInStock,ReorderLevel,ProductID from Products order by ProductID "; DataSet DS = DataHandle.ExecuteSQL(Str_SQL); WebChartControl1.Series.Clear(); //定义线型,名称 Series S1 = new Series("线条图测试", ViewType.Line); //定义X轴的数据的类型。质量,数字,时间 S1.ArgumentScaleType = ScaleType.Numerical; //定义线条上点的标识形状 ((LineSeriesView)S1.View).LineMarkerOptions.Kind = MarkerKind.Circle; //线条的类型,虚线,实线 ((LineSeriesView)S1.View).LineStyle.DashStyle = DashStyle.Solid; //S1绑定数据源 S1.DataSource = DS.Tables[0].DefaultView; //S1的X轴数据源字段 S1.ArgumentDataMember = "UnitPrice"; //S2的Y轴数据源字段 S1.ValueDataMembers[0] = "UnitsInStock"; //柱状图演示 Series S2 = new Series("柱状图测试", ViewType.Bar); S2.ArgumentScaleType = ScaleType.Numerical; S2.DataSource = DS.Tables[0].DefaultView; S2.ArgumentDataMember = "UnitPrice"; S2.ValueDataMembers[0] = "ReorderLevel"; //光滑线条演示 Series S3 = new Series("弧度曲线测试", ViewType.Spline); S3.ArgumentScaleType = ScaleType.Numerical; S3.DataSource = DS.Tables[0].DefaultView; S3.ArgumentDataMember = "UnitPrice"; S3.ValueDataMembers[0] = "UnitsInStock"; //加入chartcontrol WebChartControl1.Series.Add(S1); WebChartControl1.Series.Add(S2); WebChartControl1.Series.Add(S3); //定义chart标题 ChartTitle CT1 = new ChartTitle(); CT1.Text = "这是第一个DEMO"; ChartTitle CT2 = new ChartTitle(); CT2.Text = "CopyRight By BJYD"; CT2.TextColor = System.Drawing.Color.Black; CT2.Font = new Font("Tahoma", 8); //标题对齐方式 CT2.Dock = ChartTitleDockStyle.Bottom; CT2.Alignment = StringAlignment.Far; WebChartControl1.Titles.Clear(); WebChartControl1.Titles.Add(CT1); WebChartControl1.Titles.Add(CT2); CT2.Indent = 1; //坐标标题的定义 //坐标值说明的字体尺寸,颜色定义 ((XYDiagram)WebChartControl1.Diagram).AxisY.Title.Font = new Font("Tahoma", 10); ((XYDiagram)WebChartControl1.Diagram).AxisY.Title.TextColor = System.Drawing.Color.Red; ((XYDiagram)WebChartControl1.Diagram).AxisY.Title.Text = "这是测试的纵坐标"; ((XYDiagram)WebChartControl1.Diagram).AxisY.Title.Visible = true; ((XYDiagram)WebChartControl1.Diagram).AxisX.Title.Text = "这是测试的横坐标"; ((XYDiagram)WebChartControl1.Diagram).AxisX.Title.Visible = true; DiagramOwn = (XYDiagram)WebChartControl1.Diagram; //图例的位置定义 WebChartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right; WebChartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top; } 显示图标中的数据 private void PerformShowLablesAction() { foreach (Series serie in WebChartControl1.Series) { serie.Label.Visible = cbShowData.Checked; } } 线形为Bar的时候Label属性 private void PerformBarLabelPosition() { foreach (Series serie in WebChartControl1.Series) { if (serie.Label is SideBySideBarSeriesLabel) { if (rbbarlabelpostion.SelectedIndex == 0) { ((SideBySideBarSeriesLabel)serie.Label).Position = BarSeriesLabelPosition.Top; } else { ((SideBySideBarSeriesLabel)serie.Label).Position = BarSeriesLabelPosition.Center; } } } } |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。