Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Exception in chart control

$
0
0

I created a test application in Visual Studio 2010, .Net framework 4, by the following steps:

1. Create a windows form application in Visual Basic
2. Add a Chart Control to the Form1.
3. Add another three series to chart1, total four series, by clicking the Add button in Series Collection Editor.
4. Set the ChartType property of four series to StackedArea.
5. Add the following code to populate the series data:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim random As Random = New Random
    For pointIndex As Integer = 0 To 9
        Chart1.Series("Series1").Points.AddY(random.Next(75, 170))
        Chart1.Series("Series2").Points.AddY(random.Next(35, 125))
        Chart1.Series("Series3").Points.AddY(random.Next(45, 140))
        Chart1.Series("Series4").Points.AddY(random.Next(25, 110))
    Next
End Sub

6. Press F8 to build the application and debug the code.
7. Add a watch for the collection chart1.Series.

In the watch window, I noticed that there is a System.TypeLoadException exception triggered by the series collection Count property. 

However, if I follow the similar steps with the application created in C Sharp instead of Visual Basic, I did not see that exception again.

Do you have the same exception?  Can anyone help me figure out what causes the exception?

If I try to further manipulate the chart at run-time, in Visual Basic only, like the codes below, I received an error due to that exception:

Dim chartType As SeriesChartType
chartType = [Enum].Parse(GetType(SeriesChartType), "StackedArea100", True)
chart1.Series("Series1").ChartType = chartType
chart1.Series("Series2").ChartType = chartType
chart1.Series("Series3").ChartType = chartType
chart1.Series("Series4").ChartType = chartType


Any idea how to make it right, in Visual Basic?

Thanks in advance!

Jack






Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>