XtraCharts

Series Series Series

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;
}
}
}
}

相關詞條

相關搜尋

熱門詞條

聯絡我們