翻译|使用教程|编辑:凌霄汉|2022-04-07 17:04:15.447|阅读 134 次
概述:此次文章为大家TeeChart Pro .NET使用教程中的图表面板上的自定义绘图。
# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>
相关链接:
TeeChart Pro 将自动为您定义所有 Axis 标签,并提供足够的灵活性来定制您可能有的任何特定要求。 TeeChart Pro 提供真正的多轴。 这些在设计或运行时可用,并为 Axis 定义提供了无数的可能性和灵活性。
使用 TeeChart 的 Canvas 方法时,请记住绘图顺序很重要。 在图表上绘制一条线,然后添加系列数据点将导致该线被透支。
有四个主要的图表绘制事件,按顺序排列:
[C#] private bool afterDraw; private bool beforeDraw; private bool beforeDrawAxis; private bool beforeDrawSeries; private void Form1_Load(object sender, System.EventArgs e) { SetFlags(ref beforeDraw); Bar bar1 = new Bar(tChart1.Chart); bar1.FillSampleValues(20); radioButton1.Checked = true; } private void SetFlags(ref bool Flag) { beforeDraw = false; afterDraw = false; beforeDrawAxis = false; beforeDrawSeries = false; Flag = true; } private void DrawShape(Steema.TeeChart.Drawing.Graphics3D gg) { gg.Brush.Color = Color.Yellow; gg.Pen.Visible = true; gg.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash; gg.Brush.Visible = true; gg.Ellipse(1,1,gg.Chart.Width - 1,gg.Chart.Height - 1); } private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { if(afterDraw) { DrawShape(g); } } private void tChart1_BeforeDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { if(beforeDraw) { DrawShape(g); } } private void tChart1_BeforeDrawAxes(object sender, Steema.TeeChart.Drawing.Graphics3D g) { if(beforeDrawAxis) { DrawShape(g); } } private void tChart1_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g) { if(beforeDrawSeries) { DrawShape(g); } } private void radioButton4_Click(object sender, System.EventArgs e) { SetFlags(ref afterDraw); tChart1.Refresh(); } private void radioButton3_Click(object sender, System.EventArgs e) { SetFlags(ref beforeDrawSeries); tChart1.Refresh(); } private void radioButton2_Click(object sender, System.EventArgs e) { SetFlags(ref beforeDrawAxis); tChart1.Refresh(); } private void radioButton1_Click(object sender, System.EventArgs e) { SetFlags(ref beforeDraw); tChart1.Refresh(); } [VB.Net] Private BeforeDraw As Boolean Private BeforeDrawAxis As Boolean Private BeforeDrawSeries As Boolean Private AfterDraw As Boolean Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetFlags(BeforeDraw) Dim Bar1 As New Steema.TeeChart.Styles.Bar(TChart1.Chart) Bar1.FillSampleValues(20) RadioButton1.Checked = True End Sub Private Sub SetFlags(ByRef Flag As Boolean) BeforeDraw = False BeforeDrawAxis = False BeforeDrawSeries = False AfterDraw = False Flag = True End Sub Private Sub DrawShape(ByVal gg As Steema.TeeChart.Drawing.Graphics3D) gg.Brush.Color = Color.Yellow gg.Pen.Visible = True gg.Pen.Style = Drawing.Drawing2D.DashStyle.Dash gg.Brush.Visible = True gg.Ellipse(1, 1, gg.Chart.Width - 1, gg.Chart.Height - 1) End Sub Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw If AfterDraw = True Then DrawShape(g) End If End Sub Private Sub TChart1_BeforeDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.BeforeDraw If BeforeDraw = True Then DrawShape(g) End If End Sub Private Sub TChart1_BeforeDrawAxes(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.BeforeDrawAxes If BeforeDrawAxis = True Then DrawShape(g) End If End Sub Private Sub TChart1_BeforeDrawSeries(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.BeforeDrawSeries If BeforeDrawSeries = True Then DrawShape(g) End If End Sub Private Sub RadioButton4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton4.Click SetFlags(AfterDraw) TChart1.Refresh() End Sub Private Sub RadioButton3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton3.Click SetFlags(BeforeDrawSeries) TChart1.Refresh() End Sub Private Sub RadioButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton2.Click SetFlags(BeforeDrawAxis) TChart1.Refresh() End Sub Private Sub RadioButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton1.Click SetFlags(BeforeDraw) TChart1.Refresh() End Sub
如果您没有在图表事件之一中调用 Canvas 绘制代码,自定义绘图将不会永久保存到 Canvas 中,因此当应用程序最小化或将另一个窗口置于其上时,任何添加内容都会丢失。 您的代码不需要直接驻留在图表事件中; 如果您将代码放在 BeforeDrawSeries/AfterDraw 中并检查运行时 Draw 方法设置的标志,从而在活动标记为 true 时运行您的绘制代码,则用户绘制的项目可以在图表窗口的整个生命周期内保存,如上例所示。
让我们添加一个画布线:
[C#] private void Form1_Load(object sender, System.EventArgs e) { line1.FillSampleValues(20); line1.VertAxis = VerticalAxis.Both; line1.HorizAxis = HorizontalAxis.Both; tChart1.Aspect.View3D = false; } private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { Point s = new Point(tChart1.Axes.Left.Position, tChart1.Axes.Top.Position); Point e = new Point(tChart1.Axes.Right.Position, tChart1.Axes.Bottom.Position); g.MoveTo(s); g.LineTo(e,0); } [VB.Net] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Line1.FillSampleValues(20) Line1.VertAxis = Steema.TeeChart.VerticalAxis.Both Line1.HorizAxis = Steema.TeeChart.HorizontalAxis.Both TChart1.Aspect.View3D = False End Sub Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw Dim S As New Point(TChart1.Axes.Left.Position, TChart1.Axes.Top.Position) Dim E As New Point(TChart1.Axes.Right.Position, TChart1.Axes.Bottom.Position) g.MoveTo(S) g.LineTo(E, 0) End Sub
在 3D 图表上,由于 3D 正交位移,轴位置从图表区域偏移。 我们可以相应地移动线:
[C#] private void Form1_Load(object sender, System.EventArgs e) { line1.FillSampleValues(20); line1.VertAxis = VerticalAxis.Both; line1.HorizAxis = HorizontalAxis.Both; tChart1.Aspect.Chart3DPercent = 50; } private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g) { Steema.TeeChart.Drawing.Point3D s = new Steema.TeeChart.Drawing.Point3D(); s.X = tChart1.Axes.Left.Position; s.Y = tChart1.Axes.Top.Position; s.Z = 0; Steema.TeeChart.Drawing.Point3D e = new Steema.TeeChart.Drawing.Point3D(); e.X = tChart1.Axes.Right.Position; e.Y = tChart1.Axes.Bottom.Position; e.Z = tChart1.Aspect.Width3D; g.MoveTo(s); g.LineTo(e); } [VB.Net] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Line1.FillSampleValues(20) Line1.VertAxis = Steema.TeeChart.VerticalAxis.Both Line1.HorizAxis = Steema.TeeChart.HorizontalAxis.Both 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 S As New Steema.TeeChart.Drawing.Point3D() S.X = TChart1.Axes.Left.Position S.Y = TChart1.Axes.Top.Position S.Z = 0 Dim E As New Steema.TeeChart.Drawing.Point3D() E.X = TChart1.Axes.Right.Position E.Y = TChart1.Axes.Bottom.Position E.Z = TChart1.Aspect.Width3D g.MoveTo(S) g.LineTo(E) End Sub
如果您想了解TeeChart for .NET正版价格,欢迎咨询
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn