This is a migrated thread and some comments may be shown as answers.

[Solved] Dynamically created chart

1 Answer 153 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 19 Jun 2008, 01:22 PM
I was able to create RadCharts dynamically in code in the prior version of the control. I upgraded to the latest version of the RadChart, (install is: RadControls_for_ASP.NET_AJAX_2008_1_415_dev.exe), and now it does not work at all. I get a NullReferenceException when trying to use my chart variable. My code is:

Dim radchart As Telerik.Charting.Chart
Dim chartSeries As New ChartSeries()

chartSeries.Name =

"Count of Answers"
chartSeries.Type = ChartSeriesType.Bar

Dim answersForQuestion As System.Data.DataSet = GetReportDataForQuestion(questionID)

For currentRow = 0 To answersForQuestion.Tables(0).Rows.Count - 1
    
Dim answerCount As Integer = answersForQuestion.Tables(0).Rows(currentRow).Item("CountOfAnswer")
    
Dim answerText As String = answersForQuestion.Tables(0).Rows(currentRow).Item("AnswerText")
    chartSeries.AddItem(answerCount, answerText)
Next

radchart.Series.Add(chartSeries) <--  Exception occurs here.

Could you please tell me how I can dynamically add a Chart using the latest version of the control?

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 19 Jun 2008, 03:29 PM
Hi Mike,

You need to either reference the correct chart instance if you have defined it in the ASPX, or create a new one in the code-behind -- from the sample code snippet it seems you are trying to access the radchart variable prior to initializing it hence you get the NullReferenceException.


Best wishes,
Manuel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Chart (Obsolete)
Asked by
Mike
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or