翻译|使用教程|编辑:王香|2019-01-08 10:22:18.000|阅读 270 次
概述:以与Canvas Lines类似的方式添加Canvas Shapes。以下示例在图表区域的中心添加一个Rectangle。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
相关链接:
以与Canvas Lines类似的方式添加Canvas Shapes。以下示例在图表区域的中心添加一个Rectangle:
2D图表仅支持2D形状。
[C#]
private void tChart1_AfterDraw(object sender,Steema.TeeChart.Drawing.Graphics3D g){ Size s = new Size(100,100); Point l = new Point(g.ChartXCenter - (s.Width / 2),g.ChartYCenter - (s.Height / 2)); Rectangle r = new Rectangle(l,s); g.Pen.Color = Color.Aquamarine; g.Brush.Color = Color.Blue; g.Rectangle(R); }
[VB.Net]
Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw Dim S As New Size(100, 100) Dim L As New Point(g.ChartXCenter - (S.Width / 2), g.ChartYCenter - (S.Height / 2)) Dim R As New Rectangle(L, S) g.Pen.Color = Color.Aquamarine g.Brush.Color = Color.Blue g.Rectangle(R) End Sub
在3D图表上,您也可以在Z平面中移动矩形。请参阅RectangleWithZ方法。此示例将矩形放置在左侧墙壁上,但将其移向图表后部的中间位置(朝向后墙)。
[C#]
private void Form1_Load(object sender, System.EventArgs e) { point3DSeries1.LinePen.Visible = false; point3DSeries1.FillSampleValues(20); point3DSeries1.VertAxis = VerticalAxis.Both; point3DSeries1.HorizAxis = HorizontalAxis.Both; tChart1.Aspect.Chart3DPercent = 50; tChart1.Axes.Depth.Visible = true; } private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { Size s = new Size(100,100); Point l = new Point(tChart1.Axes.Left.Position, g.ChartYCenter - (s.Height / 2)); Rectangle r = new Rectangle(l,s); g.Pen.Color = Color.Aquamarine; g.Brush.Color = Color.Blue; g.Rectangle(r, tChart1.Aspect.Width3D/2); }
[VB.Net]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Point3DSeries1.LinePen.Visible = False Point3DSeries1.FillSampleValues(20) Point3DSeries1.VertAxis = Steema.TeeChart.VerticalAxis.Both Point3DSeries1.HorizAxis = Steema.TeeChart.HorizontalAxis.Both TChart1.Aspect.Chart3DPercent = 50 TChart1.Axes.Depth.Visible = True End Sub Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw Dim S As New Size(100, 100) Dim L As New Point(TChart1.Axes.Left.Position, g.ChartYCenter - (S.Height / 2)) Dim R As New Rectangle(L, S) g.Pen.Color = Color.Aquamarine g.Brush.Color = Color.Blue g.Rectangle(R, TChart1.Aspect.Width3D / 2) End Sub
您可以将3D形状添加到3D图表中。此示例在Chart矩形的中间绘制一个Cube:
[C#]
private void Form1_Load(object sender, System.EventArgs e) { point3DSeries1.LinePen.Visible = false; point3DSeries1.FillSampleValues(20); tChart1.Aspect.Chart3DPercent = 50; tChart1.Legend.Visible = false; tChart1.Axes.Depth.Visible = true; } private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { Size s = new Size(50,50); Point p = new Point(g.ChartXCenter - (s.Width/2), g.ChartYCenter - (s.Height/2)); Rectangle r = new Rectangle(p,s); g.Cube(r, 0, 20, true); }
[VB.Net]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Point3DSeries1.LinePen.Visible = False Point3DSeries1.FillSampleValues(20) TChart1.Aspect.Chart3DPercent = 50 TChart1.Legend.Visible = False TChart1.Axes.Depth.Visible = True End Sub Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw Dim S As New Size(50, 50) Dim P As New Point(g.ChartXCenter - (S.Width / 2), g.ChartYCenter - (S.Height / 2)) Dim R As New Rectangle(P, S) g.Cube(R, 0, 20, True) End Sub
将文本添加到最后一个矩形:
[C#]
private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { string text = "My Text"; Size s = new Size(150, 50); Point p = new Point(g.ChartXCenter - (s.Width/2), g.ChartYCenter - (s.Height/2)); Rectangle r = new Rectangle(p,s); g.Pen.Color = Color.Blue; g.Rectangle(r); g.TextOut(Convert.ToInt32(g.ChartXCenter - (g.TextWidth(text)/2)), Convert.ToInt32(g.ChartYCenter - (g.TextHeight(text)/2)), text); }
[VB.Net]
Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw Dim Text As String = "My Text" Dim S As New Size(50, 50) Dim P As New Point(g.ChartXCenter - (S.Width / 2), g.ChartYCenter - (S.Height / 2)) Dim R As New Rectangle(P, S) g.Pen.Color = Color.Blue g.Rectangle(R) g.TextOut(Convert.ToInt32(g.ChartXCenter - (g.TextWidth(Text) / 2)), Convert.ToInt32(g.ChartYCenter - (g.TextHeight(Text) / 2)), Text) End Sub
通过使用带有az坐标的TextOut重载,可以将文本放置在不同的3D平面中。
[c#]
private void Form1_Load(object sender, System.EventArgs e) { point3DSeries1.FillSampleValues(20); point3DSeries1.LinePen.Visible = false; tChart1.Aspect.Chart3DPercent = 50; } private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { string text = "My Text"; g.TextOut(g.ChartXCenter, g.ChartYCenter, tChart1.Aspect.Width3D / 2, text); }
[VB.Net]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Point3DSeries1.FillSampleValues(20) Point3DSeries1.LinePen.Visible = False TChart1.Aspect.Chart3DPercent = 50 End Sub Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw Dim Text As String = "My Text" g.TextOut(g.ChartXCenter, g.ChartYCenter, TChart1.Aspect.Width3D / 2, Text) End Sub
此示例获取系列的第3和第10个值,在它们之间绘制一条直线,并告诉我们新线的第一个和最后一个点的值以及它们之间的差异:
[c#]
private void Form1_Load(object sender, System.EventArgs e) { tChart1.Aspect.View3D = false; line1.FillSampleValues(20); } private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { if(tChart1.Series.Count > 0){ if(tChart1.Series[0].Count > 10) { Series s = tChart1.Series[0]; int h = Convert.ToInt32(g.TextHeight("H")); Point p1 = new Point(s.CalcXPos(3), s.CalcYPos(3)); Point p2 = new Point(s.CalcXPos(10), s.CalcYPos(10)); g.Pen.Color = Color.Blue; g.Pen.Width = 2; g.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash; g.MoveTo(p1); g.LineTo(p2, 0); g.TextOut(p1.X, p1.Y - h, "Point value: " + s.YValues[3].ToString()); g.TextOut(p2.X, p2.Y, "Point value: " + s.YValues[10].ToString()); g.TextOut(p2.X, p2.Y + h, "Change is: " + Convert.ToString(s.YValues[3] - s.YValues[10])); } } }
[VB.Net]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TChart1.Aspect.View3D = False Line1.FillSampleValues(20) End Sub Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw If TChart1.Series.Count > 0 Then If TChart1.Series(0).Count > 10 Then Dim S As Steema.TeeChart.Series = TChart1.Series(0) Dim H As Integer = Convert.ToInt32(g.TextHeight("H")) Dim P1 As New Point(S.CalcXPos(3), S.CalcYPos(3)) Dim P2 As New Point(S.CalcXPos(10), S.CalcYPos(10)) g.Pen.Color = Color.Blue g.Pen.Width = 2 g.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash g.MoveTo(P1) g.LineTo(P2, 0) g.TextOut(P1.X, P1.Y - H, "Point value: " & S.YValues(3)) g.TextOut(P2.X, P2.Y, "Point value: " & S.YValues(10)) g.TextOut(P2.X, P2.Y + H, "Change is: " & (S.YValues(3) - S.YValues(10))) End If End If End Sub
购买TeeChart Pro AciveX正版授权,请点击“”哟!
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn