Zedgraph for chart controls

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.