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

Bind chart at Runtime

5 Answers 226 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Raakesh
Top achievements
Rank 1
Raakesh asked on 25 Jan 2009, 03:21 AM
I am trying to bind a basic chart at runtime as a proof of concept. I have tried everything without any luck. Help! Are there any explicit instructions? Any help would be apprieciated.
Thanks,

 using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;
    using System.Collections; 
    using Processing = Telerik.Reporting.Processing; 
    using System.Text;
    using System.Data;
    using System.Data.OleDb;
    using Oracle.DataAccess;
    using Oracle.DataAccess.Client;
    using System.Configuration;


    /// <summary>
    /// Summary description for UtilDcpType.
    /// </summary>
    public partial class UtilDcpType : Telerik.Reporting.Report
    {
        public UtilDcpType()
        {
            /// <summary>
            /// Required for telerik Reporting designer support
            /// </summary>
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            // TODO: This line of code loads data into the 'appDcpDataSet.appDcpDataSetTable' table. You can move, or remove it, as needed.
            try
            {
                //this.appDcpDataSetTableAdapter1.Fill(this.appDcpDataSet.appDcpDataSetTable);   

                string m_connString = ConfigurationManager.ConnectionStrings["ProdOle"].ConnectionString;
                OleDbConnection conn = new OleDbConnection(m_connString);
                string selectCommand = @"SELECT * FROM (
                SELECT UTIL_DCP_TYPE, COUNT(UTIL_DCP_TYPE) AS cnt
                                FROM APP_DCP
                                GROUP BY UTIL_DCP_TYPE) CNT
                WHERE CNT.CNT > 1000";

                OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommand, conn);

                //SqlConnection conn = new SqlConnection(
                //@"Server=(local)\SQLEXPRESS;Integrated Security=true;Database=AdventureWorksT");
                //string selectCommand = "SELECT * FROM Production.Product";
                //SqlDataAdapter adapter = new SqlDataAdapter(selectCommand, conn);
               
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                this.DataSource = dataSet;
                this.DataMember = "Table";



            }
            catch (System.Exception ex)
            {
                // An error has occurred while filling the data set. Please check the exception for more information.
                System.Diagnostics.Debug.WriteLine(ex.Message);            }

          
        }


       
        private void chart1_NeedDataSource(object sender, System.EventArgs e)
        {
           

            Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;                    
            string m_connString = ConfigurationManager.ConnectionStrings["Prod"].ConnectionString;
            OleDbConnection  conn = new OleDbConnection(m_connString);

            //OracleConnection conn = new OracleConnection(m_connString);

            string cmdText =  @"SELECT * FROM (
                                SELECT UTIL_DCP_TYPE, COUNT(UTIL_DCP_TYPE) AS cnt
                                FROM APP_DCP
                                GROUP BY UTIL_DCP_TYPE) CNT
                                WHERE CNT.CNT > 1000";

            OleDbDataAdapter adapter = new OleDbDataAdapter(cmdText, conn);
            
           // OracleDataAdapter adapter = new OracleDataAdapter(cmdText, conn);        
           
     

            DataSet ds = new DataSet();
            //adapter.SelectCommand = cmd;
            adapter.Fill(ds);
            MessageBox.Show("got here!");

            DataView view = ds.Tables[0].DefaultView;
            view.Sort = "Rank DESC";

            chart.DataSource = view;
        }
    

    }

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 26 Jan 2009, 03:40 PM
Hello Raakesh,

As your question is too general, and your usage of the NeedDataSource event and processing chart item is correct - can you share what is the problem you have encountered? You can see charts bound at runtime in the same way in our Product Line Sales example. You can see the code used from the Visual Studio local examples.

All the best,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Raakesh
Top achievements
Rank 1
answered on 26 Jan 2009, 05:16 PM
My apologies as I forgot to state my specific problem. The chart displays "There is no or empty series" when I use the code to bind the chart data at runtime. In the same report, I bind the report data with a query at runtime and it works fine. My chart is named chart1 and as you can see from the code I am calling chart1_NeedDataSource() method...... Is there something else I should be setting?
Thanks,
0
Steve
Telerik team
answered on 27 Jan 2009, 11:03 AM
Hello Raakesh,

Same code with different query works properly in our ProductLineSales catalog:

   private void chart2_NeedDataSource(object sender, System.EventArgs e) 
        { 
            string commandText = @"SELECT  TOP 10 S.Name AS StoreName
        , SUM(SOH.SubTotal)/1000.0 AS SaleAmount
        , PS.ProductCategoryID
        , DENSE_RANK() OVER (ORDER BY SUM(SOH.SubTotal) DESC) as Rank
FROM         Production.Product AS P INNER JOIN
                      Production.ProductSubcategory AS PS ON P.ProductSubcategoryID = PS.ProductSubcategoryID INNER JOIN
                      Sales.SalesOrderDetail AS SOD ON P.ProductID = SOD.ProductID INNER JOIN
                      Sales.Customer AS CU INNER JOIN
                      Sales.SalesOrderHeader AS SOH ON CU.CustomerID = SOH.CustomerID INNER JOIN
                      Sales.Store AS S ON CU.CustomerID = S.CustomerID ON SOD.SalesOrderID = SOH.SalesOrderID
WHERE PS.Name IN (" + FormatParam((ArrayList)this.ReportParameters["ProductSubcategory"].Value) + ") " + 
"GROUP BY S.Name, PS.ProductCategoryID"
 
            Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart; 
            //DataRowView dataItem = (DataRowView)chart.DataItem; 
 
            SqlDataAdapter adapter = new SqlDataAdapter(commandText, Properties.Settings.Default.TelerikConnectionString); 
            //adapter.SelectCommand.Parameters.AddWithValue("@subcategories", FormatArray((ArrayList)this.ReportParameters["ProductSubcategory"].Value)); 
 
            DataSet ds = new DataSet(); 
            adapter.Fill(ds); 
 
            DataView view = ds.Tables[0].DefaultView; 
            view.Sort = "Rank DESC"
 
            chart.DataSource = view; 
        } 

It would seem like there is a problem with your data - please verify that there is indeed data bound to the chart by debugging.

Sincerely yours,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Raakesh
Top achievements
Rank 1
answered on 27 Jan 2009, 04:42 PM
So is the key thing to use SqlDataAdapter?

        Ex)
            SqlDataAdapter adapter = new SqlDataAdapter(commandText, Properties.Settings.Default.TelerikConnectionString);
            DataSet ds = new DataSet();
            adapter.Fill(ds);



Does Telerik Reports support using standard oracle Oracle.Access library for managing connections to Oracle and returning the dataset for report binding?   Do you have an example?
0
Steve
Telerik team
answered on 27 Jan 2009, 05:55 PM
Hello Raakesh,

Telerik Reporting does not provide its own data layer and depends on the existing .NET objects (DataSet, Data Table, DataView, ADO.NET (dataproviders) - so Telerik Reporting is basically not aware of where and how the data is being passed through and neither does it matter to it.

Best wishes,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Raakesh
Top achievements
Rank 1
Answers by
Steve
Telerik team
Raakesh
Top achievements
Rank 1
Share this question
or