Solved

Error assigning series chart area in vb.net

Posted on 2010-08-22
1
661 Views
Last Modified: 2012-05-10
Hello,
I'm developing a vb.net application that includes a graphing module.  I keep getting a error on line
  series.ChartArea = "Default"

The error reads
A chart element with the name of 'Default' could not be found in the chart collection'.5
All I am doing is assigning a name to that series chart area.  I've used this code previously with no problem so I am not sure what is going on.

For Each g As GraphReport In graphs



                If MatchingMetricUnits(g) = Nothing Then

                    MessageBox.Show(g.DataVersionIdOne.ToString & " and " & g.DataVersionIdTwo.ToString & " do not have corresponding units!", "Erro")

                    Exit Sub

                Else

                    strUnits = MatchingMetricUnits(g)

                End If



                Dim ds As New DataTable

                ds = ReportDB.GetDeltaSeriesData(g.DataVersionIdOne, g.DataVersionIdTwo, g.MetricName)



                Dim dtgv As New DataTable

                dtgv = ReportDB.GetDeltaReportData(g.DataVersionIdOne, g.DataVersionIdTwo, g.MetricName)







                Dim newtable As New DataTable



                dset.Tables.Add(dtgv)

                For Each table As DataTable In dset.Tables

                    newtable.Merge(table)

                Next

                dgvGraphResults.DataSource = newtable







                Dim strSeriesName As String = g.DataVersionIdOne.ToString & " - " & g.DataVersionIdTwo.ToString



                RemoveDuplicateSeries(Chart1.Series, strSeriesName)

                Dim series As Series = Chart1.Series.Add(strSeriesName)

                series.Tag = g.DataVersionIdOne & "-" & g.DataVersionIdTwo

                If g.GraphType = 0 Then

                    series.ChartType = SeriesChartType.Spline

                ElseIf g.GraphType = 1 Then

                    series.ChartType = SeriesChartType.Column

                ElseIf g.GraphType = 2 Then

                    series.ChartType = SeriesChartType.StackedArea

                ElseIf g.GraphType = 3 Then

                    series.ChartType = SeriesChartType.StackedColumn

                End If



                strTitleName = g.GraphTitle.ToString

                'MetricName = g.GraphTitle.ToString



                series.ChartArea = "Default"

                Dim xfield As String = "ForecastYear"

                Dim xval As New ArrayList



                For Each r As DataRow In ds.Rows

                    xval.Add(r.Item(xfield))

                Next



                Dim yfield As String = "MetricValue"

                Dim yval As New ArrayList



                For Each r As DataRow In ds.Rows

                    yval.Add(r.Item(yfield))

                Next



                ' Bind the double array to the Y axis points of the Default data series

                Chart1.Series(strSeriesName).Points.DataBindXY(xval, yval)



                series.BorderWidth = 2

                Chart1.DataBind()



            Next

Open in new window

0
Comment
Question by:chtullu135
1 Comment
 
LVL 17

Accepted Solution

by:
calacuccia earned 500 total points
ID: 33496916
In my opinion, ChartArea should be assign to the Chart object, not the Series object.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now