Use of zedgraph on the Web

Source: Internet
Author: User

PreviousSQL grouping statistics query (grouping by month and hour)This section describes how to implement grouping queries by month and hour. In this article, the results of the preceding queries are displayed on the page as charts. There are many solutions for displaying icons on the page, including building the Office owc, writing code by yourself, or third-party controls. This article uses the zedgraph control. There are two reasons to select zedgraph:

1. The control is open-source and can be modified as needed;

2. The image displayed by the control is painted, not the generated image.

: Http://sourceforge.net/project/showfiles.php? Group_id = 114675

1. reference the control to the project. In this example, version 5.1.5 is used.

Right-click the blank area at the bottom of the toolbar-> Add tab and name it zedgraph.

On the zedgraph tab, right-click and choose items ..., In the displayed window, select the downloaded zedgraph. Web. dll file.

2. Create An ASPX page in the project and name it year. aspx. Drag the newly added zedgraph control to the page and add a text box and a button to the page. The text box is used to select a year.

3. Switch to the Code view and add the following code:

Namespace zedgraphdemo {public partial class year: system. web. UI. page {protected void page_load (Object sender, eventargs e) {This. zgwyear. rendergraph ++ = new zedgraphwebcontroleventhandler (zgwyear_rendergraph);} void zgwyear_rendergraph (zedgraphweb webobject, system. drawing. graphics g, masterpane pane) {graphpane mypane = pane [0]; // Title mypane. title. TEXT = "annual analysis (month)"; mypane. xaxis. title. text = "Time"; mypane. yaxis. title. TEXT = "traffic"; // coordinate pair set pointpairlist list = new pointpairlist (); // pointpairlist list1 = new pointpairlist (); // pointpairlist list2 = new pointpairlist (); // obtain the dataset able dtyear = getdata () from the database; If (dtyear = NULL) return; For (INT I = 0; I <dtyear. rows. count; I ++) {list. add (convert. todouble (I), convert. todouble (dtyear. rows [I] ["count"]); // If there are multiple types, you can add multiple // list1.ad D (convert. todouble (I), convert. todouble (dtyear. rows [I] ["count1"]); // list2.add (convert. todouble (I), convert. todouble (dtyear. rows [I] ["count2"]);} baritem mybar = mypane. addbar ("page access", list, color. blue); // baritem mybar1 = mypane. addbar ("", list1, color. red); // baritem mybar2 = mypane. addbar ("", list2, color. yellow); mybar. bar. fill = New fill (color. blue, color. white, color. blue); // mybar1.bar. fil L = New fill (color. red, color. white, color. red); // mybar2.bar. fill = New fill (color. yellow, color. white, color. yellow); mypane. xaxis. majortic. isbetweenlabels = true; // X axis label string [] labels = new string [] {"January", "February", "March", "April", "May ", "April", "April"}; // set the X axis scale mypane. xaxis. scale. textlabels = labels; mypane. xaxis. type = axistype. text; // color fill mypane. fill = new fil L (color. white, color. fromargb (200,200,255), 45.0f); mypane. chart. fill = New fill (color. white, color. lightgoldenrodyellow, 45.0f); pane. axischange (g); mypane. yaxis. scale. max + = mypane. yaxis. scale. majorstep; baritem. createbarlabels (mypane, false, "F0"); // display the number of statistics above the bar chart} protected void btnquerys_click (Object sender, eventargs e) {getdata ();} private datatable getdata () {sqlhelper. connectionstring = Configurationmanager. appsettings ["connectionstring"]. tostring (); sqlparameter [] parameters = new sqlparameter [1]; Parameters [0] = new sqlparameter ("@ Year", sqldbtype. int, 4); Parameters [0]. value = this.txt year. value. trim (). length = 0? Datetime. Now. Year: Convert. toint32 (txtyear. value. Trim (); dataset DS = sqlhelper. executedataset ("counter_counteryear", parameters); If (Ds! = NULL & Ds. tables. count> 0 & Ds. tables [0]. rows. count> 0) {return Ds. tables [0] ;}else {return NULL ;}}}}

4. Create a folder named zedgraphimages under the root directory of the project. It is only used as a temporary directory for zedgraph plotting and does not generate images in the folder. If it is not found, an exception is reported.

Code download

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.