Search code examples
asp.netmicrosoft-chart-controls

How to use Visual Studio chart control 3.5 with SQL Server in ASP.NET?


I am using Visual Studio 3.5 chart control :

<asp:Chart ID="Chart1" runat="server">
   <Series>
      <asp:Series Name="Series1" ChartArea="ChartArea1" ChartType="Bar">
      </asp:Series>
   </Series>
   <ChartAreas>
      <asp:ChartArea Name="ChartArea1">
      </asp:ChartArea>
   </ChartAreas>
</asp:Chart>

and I need to show data in this chart which I will retrieve from SQL Server here what I want to retrieve and show :

select PONumber, CompletionTimeMonths, CreatedOn 
from PurchaseOrder;

Now this is the 1ts time I am using chart control; how can I show this?


Solution

  • answering my own question... i did this ans i am getting a simple decent looking chart at least for the beginning :

    This is the .aspx design part :

    <asp:Chart ID="Chart1" runat="server" Width="920px" Height="130px" >
            <Series>
                <asp:Series Name="Series1" ChartType="Bar">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1" BackColor="Yellow">
                    <AxisY Title="Duration" Interval="Auto">
                    </AxisY>
                    <AxisX Title="PO Number">
                    </AxisX>
                    <%--<Area3DStyle Enable3D="true" />--%>
                </asp:ChartArea>
            </ChartAreas>  
    

    and this is the code part in .cs file :

     public void fill()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select PONumber,CompletionTimeDays,CreatedOn from PurchaseOrder");
        cmd.Connection = con;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        Chart1.DataSource = dt;
        Chart1.Series["Series1"].XValueMember = "PONumber";
        Chart1.Series["Series1"].YValueMembers = "CompletionTimeDays";
        //Chart1.Series["Series1"]["DrawingStyle"] = "Emboss";
        Chart1.DataBind();
        con.Close();
    }
    

    hope this will help who is starting doing this as me