NetAdvantage 2006/UltraChart图表基础属性及数据绑定
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
Infragistics.Win.UltraWinChart.UltraChart chart=new Infragistics.Win.UltraWinChart.UltraChart();;
2
if (Cds.Tables.Count > 0)
3![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
4
chart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
5
| System.Windows.Forms.AnchorStyles.Right)));
6![](/Images/OutliningIndicators/InBlock.gif)
7![](/Images/OutliningIndicators/ContractedSubBlock.gif)
chart 属性#region chart 属性
8
chart.Axis.X.Extent = 45;
9
chart.Axis.X.Labels.Flip = false;
10
chart.Axis.X.Labels.HorizontalAlign = System.Drawing.StringAlignment.Near;
11
chart.Axis.X.Labels.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.Horizontal;
12
chart.Axis.X.Labels.OrientationAngle = 0;
13
chart.Axis.X.Labels.SeriesLabels.Flip = false;
14
chart.Axis.X.Labels.SeriesLabels.FormatString = DateTime.Now.ToLongTimeString();
15
chart.Axis.X.Labels.SeriesLabels.HorizontalAlign = System.Drawing.StringAlignment.Center;
16
chart.Axis.X.Labels.SeriesLabels.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.VerticalLeftFacing;
17
chart.Axis.X.Labels.SeriesLabels.OrientationAngle = 0;
18
chart.Axis.X.Labels.SeriesLabels.VerticalAlign = System.Drawing.StringAlignment.Center;
19
chart.Axis.X.Labels.VerticalAlign = System.Drawing.StringAlignment.Center;
20
chart.Axis.X.LineThickness = 1;
21
chart.Axis.X.MajorGridLines.AlphaLevel = ((byte)(255));
22
chart.Axis.X.MajorGridLines.Color = System.Drawing.Color.Gainsboro;
23
chart.Axis.X.MajorGridLines.DrawStyle = Infragistics.UltraChart.Shared.Styles.LineDrawStyle.Dot;
24
chart.Axis.X.MajorGridLines.Thickness = 1;
25
chart.Axis.X.MajorGridLines.Visible = true;
26
chart.Axis.X.MinorGridLines.AlphaLevel = ((byte)(255));
27
chart.Axis.X.MinorGridLines.Color = System.Drawing.Color.LightGray;
28
chart.Axis.X.MinorGridLines.DrawStyle = Infragistics.UltraChart.Shared.Styles.LineDrawStyle.Dot;
29
chart.Axis.X.MinorGridLines.Thickness = 1;
30
chart.Axis.X.MinorGridLines.Visible = false;
31
chart.Axis.X.ScrollScale.Height = 10;
32
chart.Axis.X.ScrollScale.Visible = false;
33
chart.Axis.X.ScrollScale.Width = 15;
34
chart.Axis.X.TickmarkInterval = 0;
35
chart.Axis.X.Visible = true;
36![](/Images/OutliningIndicators/InBlock.gif)
37
chart.Axis.Y.Extent = 30;
38
chart.Axis.Y.Labels.Flip = false;
39
chart.Axis.Y.Labels.HorizontalAlign = System.Drawing.StringAlignment.Far;
40
chart.Axis.Y.Labels.ItemFormatString = "<DATA_VALUE:00.##>";
41
chart.Axis.Y.Labels.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.Horizontal;
42
chart.Axis.Y.Labels.OrientationAngle = 0;
43
chart.Axis.Y.Labels.SeriesLabels.Flip = false;
44
chart.Axis.Y.Labels.SeriesLabels.FormatString = "";
45
chart.Axis.Y.Labels.SeriesLabels.HorizontalAlign = System.Drawing.StringAlignment.Far;
46
chart.Axis.Y.Labels.SeriesLabels.Orientation = Infragistics.UltraChart.Shared.Styles.TextOrientation.Horizontal;
47
chart.Axis.Y.Labels.SeriesLabels.OrientationAngle = 0;
48
chart.Axis.Y.Labels.SeriesLabels.VerticalAlign = System.Drawing.StringAlignment.Center;
49
chart.Axis.Y.Labels.VerticalAlign = System.Drawing.StringAlignment.Center;
50
chart.Axis.Y.LineThickness = 1;
51
chart.Axis.Y.RangeMax = 1000;
52
chart.Axis.Y.RangeType = Infragistics.UltraChart.Shared.Styles.AxisRangeType.Automatic;//Y轴最大值设置为自动
53
chart.Axis.Y.MajorGridLines.AlphaLevel = ((byte)(255));
54
chart.Axis.Y.MajorGridLines.Color = System.Drawing.Color.Gainsboro;
55
chart.Axis.Y.MajorGridLines.DrawStyle = Infragistics.UltraChart.Shared.Styles.LineDrawStyle.Dot;
56
chart.Axis.Y.MajorGridLines.Thickness = 1;
57
chart.Axis.Y.MajorGridLines.Visible = true;
58
chart.Axis.Y.MinorGridLines.AlphaLevel = ((byte)(255));
59
chart.Axis.Y.MinorGridLines.Color = System.Drawing.Color.LightGray;
60
chart.Axis.Y.MinorGridLines.DrawStyle = Infragistics.UltraChart.Shared.Styles.LineDrawStyle.Dot;
61
chart.Axis.Y.MinorGridLines.Thickness = 1;
62
chart.Axis.Y.MinorGridLines.Visible = true;
63
chart.Axis.Y.ScrollScale.Height = 10;
64
chart.Axis.Y.ScrollScale.Visible = false;
65
chart.Axis.Y.ScrollScale.Width = 15;
66
chart.Axis.Y.TickmarkInterval = 0;
67
chart.Axis.Y.Visible = true;
68
chart.Border.Color = System.Drawing.Color.Silver;
69
chart.Border.CornerRadius = 5;
70
chart.Border.Raised = true;
71![](/Images/OutliningIndicators/InBlock.gif)
72
chart.ColorModel.AlphaLevel = ((byte)(150));
73
chart.ColorModel.ColorBegin = System.Drawing.Color.LimeGreen;
74
chart.ColorModel.ColorEnd = System.Drawing.Color.Gold;
75
chart.ColorModel.ModelStyle = Infragistics.UltraChart.Shared.Styles.ColorModels.LinearRange;
76
chart.ColorModel.Scaling = Infragistics.UltraChart.Shared.Styles.ColorScaling.Increasing;
77![](/Images/OutliningIndicators/InBlock.gif)
78
chart.Data.EmptyStyle.LineStyle.DrawStyle = Infragistics.UltraChart.Shared.Styles.LineDrawStyle.Dash;
79
chart.Data.EmptyStyle.LineStyle.EndStyle = Infragistics.UltraChart.Shared.Styles.LineCapStyle.NoAnchor;
80
chart.Data.EmptyStyle.LineStyle.MidPointAnchors = false;
81
chart.Data.EmptyStyle.LineStyle.StartStyle = Infragistics.UltraChart.Shared.Styles.LineCapStyle.NoAnchor;
82
chart.Data.MaxValue = 500;
83
chart.Data.MinValue = 0;
84
chart.Data.SwapRowsAndColumns = true;
85![](/Images/OutliningIndicators/InBlock.gif)
86
chart.Legend.BackgroundColor = System.Drawing.Color.LemonChiffon;
87
chart.Legend.BorderColor = System.Drawing.Color.DimGray;
88
chart.Legend.DataAssociation = Infragistics.UltraChart.Shared.Styles.ChartTypeData.ColumnData;
89
chart.Legend.Location = Infragistics.UltraChart.Shared.Styles.LegendLocation.Bottom;
90
chart.Legend.SpanPercentage = 5;
91
chart.Legend.Visible = true;
92![](/Images/OutliningIndicators/InBlock.gif)
93
chart.TitleBottom.Visible = false;
94
chart.TitleTop.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold);
95
chart.TitleTop.FontColor = System.Drawing.Color.Red;
96
chart.TitleTop.VerticalAlign = System.Drawing.StringAlignment.Center;
97
chart.TitleTop.Text = "标题";
98![](/Images/OutliningIndicators/InBlock.gif)
99
chart.Tooltips.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F);
100
chart.Tooltips.TooltipControl = null;
101
chart.Tooltips.UseControl = false;
102![](/Images/OutliningIndicators/InBlock.gif)
103
chart.ForeColor = System.Drawing.SystemColors.ControlText;
104
chart.TabIndex = 10;
105
chart.Name = item.Text.ToString();
106
chart.Size = new System.Drawing.Size(400, 295);//图表的大小设置
107
chart.Location = new System.Drawing.Point(5, 300);//设置画图表的位置
108
#endregion
109![](/Images/OutliningIndicators/InBlock.gif)
110
chart.ChartType = Infragistics.UltraChart.Shared.Styles.ChartType.ColumnChart;//图表的显示样式
111![](/Images/OutliningIndicators/InBlock.gif)
112
此为简单的双向(X,Y)坐标图表,绘制多维图表可增加相应的坐标参数,如(X2,Y2,Z,Z2。。。)
113![](/Images/OutliningIndicators/InBlock.gif)
114![](/Images/OutliningIndicators/InBlock.gif)
115![](/Images/OutliningIndicators/InBlock.gif)
116
绑定到数据源
117![](/Images/OutliningIndicators/InBlock.gif)
118
1.创建一个DataTable
119![](/Images/OutliningIndicators/InBlock.gif)
120
DataTable table = new DataTable();
121
table.Columns.AddRange(
122
new DataColumn[]
123![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
124
new DataColumn("Day", Type.GetType("System.String")),
125
new DataColumn("inMaxValue", Type.GetType("System.Double")),
126
new DataColumn("inAVGValue", Type.GetType("System.Double")),
127
new DataColumn("OutMaxValue", Type.GetType("System.Double")),
128
new DataColumn("OutAVGValue", Type.GetType("System.Double"))
129
});//创建5列
130
DataRow dr = table.NewRow();//创建行如DataSet关联
131
for (int i = 0; i < Dataset.Tables[0].Rows.Count; i++)
132![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
133
if (Dataset.Tables[0].Rows[i][0].ToString().Split(Convert.ToChar(':'))[1] == item.Text)
134![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
135
dr["Day"] = Dataset.Tables[0].Rows[i][0].ToString();
136
dr["inMaxValue"] = Dataset.Tables[0].Rows[i][1].ToString();
137
dr["inAVGValue"] = Dataset.Tables[0].Rows[i][2].ToString();
138
dr["OutMaxValue"] = Dataset.Tables[0].Rows[i][3].ToString();
139
dr["OutAVGValue"] = Dataset.Tables[0].Rows[i][4].ToString();
140
}
141![](/Images/OutliningIndicators/InBlock.gif)
142
} table.Rows.Add(dr);
143
chart.DataSource = table;//绑定
144![](/Images/OutliningIndicators/None.gif)