Jump to content
Software FX Community

Re-draw of simple annotated chart throws TargetInvocationException, WHY?

User (Legacy)

Recommended Posts

Hi, could someone shed some light on why i am getting a

TargetInvocationException (full error text below)

from my winform app? All it does is draw a simple chart and add two lines to

it as annotations, i provide the full code below.

That much works fine.

HOWEVER, if i hit the Go button to run the chart again it throws the error.

I tried clearing the chart using "AllData",

it didn't help. Something is not being re-set properly, but what!!??




======== ERROR

An unhandled exception of type 'System.Reflection.TargetInvocationException'

occurred in system.windows.forms.dll

Additional information: Exception has been thrown by the target of an



======== CODE

Imports System.Math

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()


'This call is required by the Windows Form Designer.


'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then


End If

End If


End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents Chart1 As SoftwareFX.ChartFX.Chart

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.Button1 = New System.Windows.Forms.Button

Me.Chart1 = New SoftwareFX.ChartFX.Chart





Me.Button1.Location = New System.Drawing.Point(56, 16)

Me.Button1.Name = "Button1"

Me.Button1.TabIndex = 0

Me.Button1.Text = "Go"




Me.Chart1.AxisX.LabelsFormat.Format = SoftwareFX.ChartFX.AxisFormat.None

Me.Chart1.AxisX.MinorTickMark = SoftwareFX.ChartFX.TickMark.Inside

Me.Chart1.AxisX.TickMark = SoftwareFX.ChartFX.TickMark.Outside

Me.Chart1.AxisY.LabelsFormat.Format = SoftwareFX.ChartFX.AxisFormat.None

Me.Chart1.AxisY.LogBase = 10

Me.Chart1.AxisY.MinorTickMark = SoftwareFX.ChartFX.TickMark.Inside

Me.Chart1.AxisY.TickMark = SoftwareFX.ChartFX.TickMark.Outside

Me.Chart1.AxisY2.LabelsFormat.Format = SoftwareFX.ChartFX.AxisFormat.None

Me.Chart1.AxisY2.MinorTickMark = SoftwareFX.ChartFX.TickMark.Inside

Me.Chart1.AxisY2.TickMark = SoftwareFX.ChartFX.TickMark.Outside

Me.Chart1.DataEditorObj.Alignment = SoftwareFX.ChartFX.ToolAlignment.Spread

Me.Chart1.DataEditorObj.Docked = SoftwareFX.ChartFX.Docked.Bottom

Me.Chart1.DataEditorObj.Interlaced = SoftwareFX.ChartFX.Interlaced.None

Me.Chart1.DataEditorObj.ToolBorder = SoftwareFX.ChartFX.ToolBorder.None

Me.Chart1.DesignTimeData = "D:\Program


Me.Chart1.Gallery = SoftwareFX.ChartFX.Gallery.Curve

Me.Chart1.GalleryObj.Native = True

Me.Chart1.LegendBoxObj.Alignment = SoftwareFX.ChartFX.ToolAlignment.Center

Me.Chart1.LegendBoxObj.Docked = SoftwareFX.ChartFX.Docked.Right

Me.Chart1.LegendBoxObj.Flags = SoftwareFX.ChartFX.LegendBoxFlag.Default

Me.Chart1.LegendBoxObj.ToolBorder = SoftwareFX.ChartFX.ToolBorder.None

Me.Chart1.LineWidth = 4

Me.Chart1.Location = New System.Drawing.Point(40, 72)

Me.Chart1.MarkerShape = SoftwareFX.ChartFX.MarkerShape.None

Me.Chart1.Name = "Chart1"

Me.Chart1.NValues = 15

Me.Chart1.SerLegBoxObj.Alignment = SoftwareFX.ChartFX.ToolAlignment.Center

Me.Chart1.SerLegBoxObj.Docked = SoftwareFX.ChartFX.Docked.Right

Me.Chart1.SerLegBoxObj.Flags = SoftwareFX.ChartFX.LegendBoxFlag.Default

Me.Chart1.SerLegBoxObj.ToolBorder = SoftwareFX.ChartFX.ToolBorder.None

Me.Chart1.Size = New System.Drawing.Size(512, 392)

Me.Chart1.TabIndex = 1

Me.Chart1.UserLegendBoxObj.Alignment =


Me.Chart1.UserLegendBoxObj.Docked = SoftwareFX.ChartFX.Docked.Right

Me.Chart1.UserLegendBoxObj.Flags = SoftwareFX.ChartFX.LegendBoxFlag.Default

Me.Chart1.UserLegendBoxObj.ToolBorder = SoftwareFX.ChartFX.ToolBorder.None




Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(608, 524)



Me.Name = "Form1"

Me.Text = "Form1"


End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click


End Sub



Sub buildchart()

Dim ChannelPts(3, 25) As Double

Dim NumChannelPts, StartingPt, NumBasePoints As Integer


NumBasePoints = 20

Dim intJ As Integer


Chart1.Gallery = SoftwareFX.ChartFX.Gallery.Lines

Chart1.OpenData(SoftwareFX.ChartFX.COD.Values, 1, NumBasePoints)

For intJ = 0 To NumBasePoints - 1

Chart1.Value(0, intJ) = intJ * intJ



Chart1.AxisY.AutoScale = True

Chart1.Titles(0).Text = "Quadratic?"


'' now add the trend/support/resistance lines


Dim annot As SoftwareFX.ChartFX.Annotation.AnnotationX

annot = New SoftwareFX.ChartFX.Annotation.AnnotationX


AddLine(annot, 1, 3, 3, 5, 1)

AddLine(annot, 1, 3, 16, 25, 1)


End Sub



Sub AddLine(ByRef annot As SoftwareFX.ChartFX.Annotation.AnnotationX, _

ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As

Double, _

ByVal ColorIdx As Integer)


Dim arrow As SoftwareFX.ChartFX.Annotation.AnnotationArrow

arrow = New SoftwareFX.ChartFX.Annotation.AnnotationArrow

arrow.Attach(x1, y1, x2, y2)

arrow.Color = System.Drawing.Color.SaddleBrown

arrow.Border.Color = System.Drawing.Color.SaddleBrown

'' this doesn't seem to do anything...

arrow.Width = 3


'' watch the end caps, they turn off the arrow but can turn off the whole


'' if you are displaying vertical & horizontal lines

If x1 = x2 Then

'arrow.EndCap.Width = 0

arrow.EndCap.Height = 0


If Abs((y1 - y2) / y2) < 0.01 Then

arrow.EndCap.Width = 0

'arrow.EndCap.Height = 0


arrow.EndCap.Width = 0

arrow.EndCap.Height = 0

End If

End If



End Sub

End Class

Link to comment
Share on other sites

But, did you press the "Go" button a 2nd time, right after the first. That

is when it dies....

I upgraded my version to v6.2 SP that is on the web site, so that

ChartFX.dll is

file last modified 3/19/04

assembly version 6.2.1342.0

file version 6.2.1539.21391

Same problem still exists.....on the 2nd click it dies every time with

An unhandled exception of type

'System.Reflection.TargetInvocationException' occurred in


Additional information: Exception has been thrown by the target

of an invocation.

Link to comment
Share on other sites

Ah ! ok. Now I get the crash. It wasn't clear to me in the first posting

that I had to press the GO button twice.

There is a bug in ClearData. We will fix this problem in the next SP.

Workaround, avoid calling ClearData with AllData. Instead, include the flags

that you need only but DO NOT include Extensions.

For example:






Software FX

Link to comment
Share on other sites

  • 5 years later...
  • 3 years later...


This topic is now archived and is closed to further replies.

  • Create New...