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

Bind chart to a dataset ?

4 Answers 173 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 15 Jun 2009, 07:24 PM
Was wondering if there is an easy way to bind a dataset to a chart programmatically. Would like to use one of my prebuilt stored procedures without using a strongly typed dataset. Would like to do something like the following. The  last line fails however as the chart1 object does not appear to have a datasource property.

 

SqlConnection connSomsys = new SqlConnection(@"Server=cmdivst004\Jason08;Integrated Security=true;Database=QuoteDB");

 

 

SqlCommand selectChartinfo;

 

selectChartinfo =

new SqlCommand("sprocgetinternationalsales", connSomsys);

 

selectChartinfo.CommandType =

CommandType.StoredProcedure;

 

selectChartinfo.Parameters.AddWithValue(

"@year", 2008);

 

 

SqlDataAdapter adapter6 = new SqlDataAdapter(selectChartinfo);

 

 

DataSet dataSet6 = new DataSet();

 

adapter6.Fill(dataSet6);

 

this.chart1.datasource = dataSet6;

 

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 16 Jun 2009, 08:34 AM
Hi Jason,

As explained in the chart item documentation, you should use the NeedDataSource event of the chart and its processing object to bind it:

 private void chart1_NeedDataSource(object  sender, System.EventArgs e)
   {
     Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
     procChart.DataSource = dataSet6;
   }


Best wishes,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jason
Top achievements
Rank 1
answered on 16 Jun 2009, 03:02 PM
Dear Steve,
   Hello and thank you for your response. Now the question becomes how do I make the event fire as currently it does not. (Using sql profiler to see if the sp is firing..it is not) I read the documentation and it seems that this event will only fire at run time so I put it on an aspx and browsed. The chart shows up but there is no relevant data. (sp still does not fire in profiler) . The documentation says it will only fire if the datasource is null. I don't believe I assigned a datasource to the chart in any of my tinkering with the properties window of the chart. Is there a way to see if the datasource is in fact null ?
0
Steve
Telerik team
answered on 17 Jun 2009, 02:41 PM
Hello Jason,

The chart report item would always fire its NeedDataSource event and the remark about no datasource set is relevant only for the report, subreport and table items.
How do you determine that the event does not fire? Have you wired the event from the events tab of the chart properties grid? If this is the case you should have similar line in the InitializeComponent() method:

this.chart1.NeedDataSource += new System.EventHandler(this.chart1_NeedDataSource);

You can hook up the report in question to a ReportViewer control, set a break point in the chart NeedDataSource event handler and it should be fired.

Greetings,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jason
Top achievements
Rank 1
answered on 17 Jun 2009, 08:02 PM
Thanks Steve,
  It turned out the event needed to be wired as that line was somehow missing. Works now. 

Jason
Tags
General Discussions
Asked by
Jason
Top achievements
Rank 1
Answers by
Steve
Telerik team
Jason
Top achievements
Rank 1
Share this question
or