Click here to Skip to main content
15,886,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't show the data on mschart but there is no problem with sql connection. only the title of the chart is appearing. Any Suggestions?

C#
SqlConnection connection = new SqlConnection("Data Source=ccsmsmq01;Initial Catalog=DivaReportTest;User ID=DivaReportDev;Password=****");
       SqlDataAdapter adapter;
       protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               VerileriGetir();
           }
       }

       private void VerileriGetir()
       {
           string selectSQL = " SELECT Period, Total FROM IVR_PROFILE_CALL_PEAKS";

           adapter = new SqlDataAdapter(selectSQL, connection);

           DataTable table = new DataTable();
           adapter.Fill(table);

           DataSet ds = new DataSet();
           adapter.Fill(ds,"Chart1");


           Chart1.DataSource = adapter ;
           Chart1.DataBind();
           Chart1.Titles.Add("Department Wise Employee Count");
           Chart1.Series["Series1"].XValueMember = "Period";
           Chart1.Series["Series1"].YValueMembers = "Total";

       }

ASP.NET
<asp:Chart ID="Chart1" runat="server" >
            <series>
                <asp:Series Name="Series1">
                
            </series>
            <chartareas>
                <asp:ChartArea Name="ChartArea1">
                
            </chartareas>
Posted
Updated 18-Oct-12 8:29am
v2
Comments
Jim Jos 18-Oct-12 2:52am    
Your Datasource should be a datatable or dataset right.. How an adapter could be a datasource?

1 solution

You cannot directly add an adapter as datasource. In datasource you need to mention the table. So try the following,

DataSet ds = new DataSet();
adapter.Fill(ds);
Chart1.DataSource = ds[table_name];


Replace the following portion of the code with the above code:

DataTable table = new DataTable();
adapter.Fill(table);

DataSet ds = new DataSet();
adapter.Fill(ds,"Chart1");

 
Chart1.DataSource = adapter ;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900