ASP.NET - Bind Chart control from database - Asked By Nitish Gupta on 13-Sep-12 08:53 AM

hello,
 I am using chart control in asp.net 4.0 and i want to bind data to chart control from database table.
I want to show performance (good,average,excellent) on Y-axis and Test topic(test1,test2) in X-axis from table.
tell me the source code.
Danasegarane Arunachalam replied to Nitish Gupta on 13-Sep-12 10:39 AM
Refer Using Microsoft's Chart Controls from  www.4guysfromrolla.com/articles/072209-1.aspx
Jitendra Faye replied to Nitish Gupta on 14-Sep-12 12:06 AM
http://www.eggheadcafe.com/community/aspnet/14/10302932/how-to-use-a-variable-in-charts-in-vbnet.aspx

Follow this code-

using System.Data.OleDb;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
...

// Resolve the address to the Access database. We assume database is
// in Bin folder.
string fileNameString = "chartdata.mdb";

// Initialize a connection string.
string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

// Define the database query.
string mySelectQuery="SELECT * FROM SALESCOUNTS;";

// Create a database connection object using the connection string.
OleDbConnection myConnection = new OleDbConnection(myConnectionString);

// Create a database command on the connection using query.
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

// Open the connection.
myCommand.Connection.Open();

// Create a database reader.
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Specify the Name column to be used for point's X values.
chart1.DataBindTable(myReader,"SalesRep");


// Close the connection.
myConnection.Close();

//  This is a loop to set all created charts appearance with custom attribute.
foreach (Series series in chart1.Series)
{
    series.CustomAttributes = "DrawingStyle=LightToDark";
}


FOLLOW THIS LINK ALSO-

http://msdn.microsoft.com/en-us/library/dd456766.aspx