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.
Some of my previous articles
are as follows: How
To Create Dynamic Google Column Chart In an Asp.Net MVC Using C# and Javascript .
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.
string connectionstring = "<--- ---="" connection="" string="" your="">";
ReplyDeletehi can you explain more on this, thank you
Here you need to provide your DB connection string
Delete