How to create chart by programmatically in asp.net?

How to create chart by programmatically in asp.net?, someone asked me to explain?

In this article we will discuss, to create chart by programmatically in asp.net. Before preceding this refer part1.

Step 1: create a drowpdownlist and bind chart type name on it and set AutoPostBack to true. We can change chart type as our wish.

Step 2: Copy and paste the following code.


    <table style="border: 1px solid #e2e2e2; font-family: Arial">
                <b>Select Chart Type:</b>
                <asp:DropDownList ID="ChartType" AutoPostBack="true" runat="server"
            <td colspan="2">
                <asp:Chart ID="Chart1" runat="server" Width="450px">
                       <asp:Title Text="website visitors">
                       <asp:Series Name="Series1" ChartArea="ChartArea1" ChartType="point">
                                <asp:DataPoint AxisLabel="sun" YValues="800" />
                                <asp:DataPoint AxisLabel="mon" YValues="900" />
                                <asp:DataPoint AxisLabel="tue" YValues="700" />
                                <asp:DataPoint AxisLabel="wed" YValues="900" />
                                <asp:DataPoint AxisLabel="thr" YValues="600" />
                                <asp:DataPoint AxisLabel="fri" YValues="750" />
                                <asp:DataPoint AxisLabel="sat" YValues="950" />
                       <asp:ChartArea Name="ChartArea1">
                            <AxisX Title="week">
                            <AxisY Title="visitors per day">


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;

public partial class _Flowchart : Page
        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)

        private void GetChartData()
            // Retrieve the Series to which we want to addDataPoints
            Series series = Chart1.Series["Series1"];
            // Add X and Y values usingAddXY() method

        private void GetChartTypes()
            foreach (int chartType in Enum.GetValues(typeof(SeriesChartType)))
                ListItem li = new ListItem(Enum.GetName(typeof(SeriesChartType),
                   chartType), chartType.ToString());

        protected void ChartType_SelectedIndexChanged(object sender, EventArgs e)
            this.Chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(
                typeof(SeriesChartType), ChartType.SelectedValue);


create chart by programmatically in asp.net

Post your comments / questions