Wednesday, 16 July 2014

How to Create Column Chart in Windows Application Using C#.Net

7/16/2014 - By Pranav Singh 2

This article will explain your how you can create a column chart in windows application using chart control in windows application and C#.Net  from database table value.


Here is the table data which we will use for generating the chart.


So for this article first we will create a new windows application. Now add a new form and in this form add a windows chart control. After adding all the controls we will create the series name for the chart control.


Now click on button open the series windows. Now we will rename the series name as shown.


After this generate the form load event to add the code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.Data.SqlClient;

namespace DemoWindowsApplication
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            DataTable _objdt = new DataTable();
            _objdt = GetStudentRecord();
            chart1.DataSource = _objdt;
            chart1.Series["Marksheet"].XValueMember = "Name";
            chart1.Series["Marksheet"].YValueMembers = "Marks";
            chart1.Series["Marksheet"].ChartType = SeriesChartType.Column;
            chart1.Titles.Add("Student Report Graph");
            chart1.DataBind();
        }
        public DataTable GetStudentRecord()
        {
            string connectionstring = "<--- ---="" connection="" string="" your="">";
            DataTable _objdt = new DataTable();
            string querystring = "select * from Student;";
            SqlConnection _objcon = new SqlConnection(connectionstring);
            SqlDataAdapter _objda = new SqlDataAdapter(querystring, _objcon);
            _objcon.Open();
            _objda.Fill(_objdt);
            return _objdt;
        }
    }
}


In above code x-coordinate field and y-coordinate field. After that we have defined chart type and title of chart. Now run the application to view the output.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

2 comments:

  1. string connectionstring = "<--- ---="" connection="" string="" your="">";

    hi can you explain more on this, thank you

    ReplyDelete
    Replies
    1. Here you need to provide your DB connection string

      Delete

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top