Chart in .NET



Today, in this blog let's play around with one of the interesting and most useful concept in .NET.

Question: What are charts?


In simple terms "It enables to draw out different graphical charts and choose the appropriate one as per the requirement".

Step 1: Create a new WebForm project


Step 2: The complete code WebForm1.aspx looks like this

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ChartApp.WebForm1" %>


<%@ Register Assembly="System.Web.DataVisualization, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head id="Head1" runat="server">




    <form id="form1" runat="server">


        <asp:Chart ID="Chart1" runat="server">

            <series><asp:Series Name="Series1" IsValueShownAsLabel="true" XValueMember="FirstName" YValueMembers="Age"></asp:Series></series>

            <chartareas><asp:ChartArea Name="ChartArea1"></asp:ChartArea></chartareas>





Step 3: The complete code WebForm1.aspx.cs looks like this

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

namespace ChartApp


    public partial class WebForm1 : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)


            if (!IsPostBack)





        private void getData()


            SqlConnection con = new SqlConnection(@"Data Source=WIN-KV3BO1RQQF7;Initial Catalog=Company;Integrated Security=True");

            SqlDataAdapter da = new SqlDataAdapter("Select FirstName, Age from Employee", con);

            DataSet ds = new DataSet(); da.Fill(ds);

            Chart1.DataSource = ds;





Step 4: The output of application looks like this


Next Recommended Reading .NET Core or Vanilla .NET?

MVC Corporation
MVC Corporation is consulting and IT services based company.