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

Chart databinding in reports

2 Answers 102 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stefan Willebrand
Top achievements
Rank 1
Stefan Willebrand asked on 11 Feb 2009, 09:58 AM
Is there no other way to bind charts in reports to a datasource but to do it in code in the needdatasource event?

I just started with this and it seems as if I have some issues to getting the chart to work correct and displaying any data. Do you have a tutorial that shows this step by step somewhere?

2 Answers, 1 is accepted

Sort by
0
Stefan Willebrand
Top achievements
Rank 1
answered on 11 Feb 2009, 10:11 PM
I got this going now with the following code:

Private

Sub Chart1_NeedDataSource(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chart1.NeedDataSource

 

 

Dim commandText As String = "SELECT TransactionMonth,COUNT(TradeID) AS Trades5 " + _

 

"FROM (SELECT TradeID, DATEPART(year, TradeTime) AS TransactionYear, DATEPART(Month, TradeTime) AS TransactionMonth "

+ _

 

" FROM Trades) AS Q "

+ _

 

"GROUP BY TransactionYear, TransactionMonth "

+ _

 

"ORDER BY TransactionYear, TransactionMonth"

 

Dim chart As Telerik.Reporting.Processing.Chart = TryCast(sender, Telerik.Reporting.Processing.Chart)

 

 

Dim adapter As New SqlClient.SqlDataAdapter(commandText, My.Settings.ProSpreadsConnectionString)

 

 

Dim ds As New DataSet()

 

adapter.Fill(ds)

chart.DataSource = ds

Chart1.PlotArea.XAxis.DataLabelsColumn =

"TransactionMonth"

 

 

End Sub

I still have an issue though because both TransactionMonth and Trades5 show up as series in the chart and I would only like to have Trades5 as the series. I tried writing;

 

Chart1.Series(0).DataYColumn =

"Trades5"

But then the chart crashes and says that the series index is out of range. How could I make this work so I only have 1 series instead of both?

 

0
Massimiliano Bassili
Top achievements
Rank 1
answered on 13 Feb 2009, 09:19 AM
Have you tried clearing the series as first thing in the NeedDataSource event chart.Series.Clear(); ?
Tags
General Discussions
Asked by
Stefan Willebrand
Top achievements
Rank 1
Answers by
Stefan Willebrand
Top achievements
Rank 1
Massimiliano Bassili
Top achievements
Rank 1
Share this question
or