Microsoft now has a chart control, but it requires vs2008 + net framework3.5 SP1. if it is vs2005 now and does not want to use vs2008, a third-party component zedgraph is referenced;
:
Http://www.codeproject.com/KB/graphics/zedgraph.aspx
The following briefly describes how to use it:
1. Reference zedgraph
Download the package, decompress it, and reference it to the web project. The result is as follows:
2. Load zedgraph in the toolbox
3. Use Controls
Create a webpage, drag the zedgraphweb control to the page, and configure renderedimagepath, such as renderedimagepath = "~ /Tempimages /"
The main method of the background code onrendergraph code is as follows:
Code
Private void onrendergraph (zedgraphweb zgw, graphics g, masterpane)
{
Graphpane mypane = masterpane [0];
Mypane. Title. Text = "order sales statistics ";
Mypane. xaxis. Title. Text = "month ";
Mypane. yaxis. Title. Text = "number of deals ";
Pointpairlist list = new pointpairlist ();
String SQL = "select fmonth, ordernum from DBO. ordertj ";
Using (sqlconnection conn = new sqlconnection (configurationmanager. etettings ["conn"]. tostring ()))
{
If (conn. State = connectionstate. Closed)
{
Conn. open ();
}
Sqldataadapter da = new sqldataadapter (SQL, Conn );
Dataset DS = new dataset ();
Da. Fill (DS );
Datatable dt = Ds. Tables [0];
If (Dt. Rows. Count> 0)
{
Mypane. xaxis. Scale. max = DT. Rows. count;
Foreach (datarow DR in DT. Rows)
{
List. Add (double. parse (Dr ["fmonth"]. tostring (), double. parse (Dr ["ordernum"]. tostring ()));
}
}
Conn. Close ();
}
Baritem mycurve = mypane. addbar ("quantity", list, color. Blue );
Mycurve. Bar. Fill = New fill (color. Blue, color. White, color. Blue );
Mypane. Fill = New fill (color. White, color. fromargb (200,200,255), 45.0f );
Masterpane. axischange (g );
Baritem. createbarlabels (mypane, false, "F0 ");
}
Run
The statement for creating a database table for testing is as follows:
Code
Create Table [DBO]. [ordertj] (
[Fmonth] [int] Null,
[Ordernum] [int] Null
) On [primary]
Demo download/files/kevinlzf/demo.rar
Other curves, pie charts, and so on, can only read the document by myself. I just briefly demonstrated his functions and ended.