Asp. NET Paint full Introduction (Next)

Source: Internet
Author: User
Asp.net| Introduction We've finished the custom class for pie and bar graphs, and we're going to apply these classes here.
Use Vs.net to create a new Web application called Insight_cs and add it to the Insight project just now. Delete the default WebForm1.aspx file, and create a new file named Saleschart.aspx. Open this file and in code mode, replace the first line with the following:
<%@ Page contenttype= "Image/gif" language= "C #" autoeventwireup= "false" codebehind= "SalesChart.aspx.cs" inherits= " Insight_cs. Saleschart "%>
Open the file SalesChart.aspx.cs, where the code looks like this:
Using System;
Using System.Data;
Using System.Web;
Using System.IO;
Using System.Data.SqlClient;
Using Insight_cs. webcharts;//This is a custom name space.
Namespace Insight_cs
{
public class SalesChart:System.Web.UI.Page
{
Public Saleschart ()
{
Page.Init + = new System.EventHandler (Page_Init);
}
private void Page_Load (object sender, System.EventArgs e)
{
Get data from a database for drawing
String sql = "Select" + "year (sa.ord_date) as [year]," + "SUM (sa.qty) as [qty]" + "" + "sales sa" + "INNER JOIN stores St On (sa.stor_id = st.stor_id) "+" GROUP by "+" Year (sa.ord_date) "+" ORDER By "+" [year] ";
String connectstring = "Password=ben;" User Id=sa; Database=pubs;data Source=localhost ";
SqlDataAdapter da = new SqlDataAdapter (sql,connectstring);
DataSet ds = new DataSet ();
int rows = da. Fill (ds, "ChartData");
Set the type of the production graph (pie or bar)
String type = "";
if (null==request["type"])
{
Type = "PIE";
}
Else
{
Type = request["type"]. ToString (). ToUpper ();
}
Set Diagram size
int width = 0;
if (null==request["width"])
{
width = 400;
}
Else
{
width = Convert.ToInt32 (request["width"]);
}
int height = 0;
if (null==request["height"])
{
Height = 400;
}
Else
{
Height = Convert.ToInt32 (request["height"]);
}
Set Chart title
string title = "";
if (null!=request["title"])
{
title = request["title"]. ToString ();
}
String subtitle = "";
if (null!=request["subtitle"])
{
subtitle = request["subtitle"]. ToString ();
}
if (0<rows)
{
Switch (type)
{
Case "PIE":
Piechart pc = new Piechart ();
Pc. Render (Title,subtitle,width,height,ds,response.outputstream);
Break
Case "BAR":
Barchart BC = new Barchart ();
Bc. Render (Title,subtitle,width,height,ds,response.outputstream);
Break
Default

Break
}
}
}
private void Page_Init (object sender, EventArgs e)
{
//
Codegen:this the call are required by the ASP.net Web Form Designer.
//
InitializeComponent ();
}
#region Web Form Designer generated code
<summary>
Required to Designer support-do not modify
The contents is with the Code Editor.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}
The above code does not have any difficulty, here does not do the analysis.
In Vs.net, open Insight_cs solution, right-click References, add references, Insight_cs component files. WebCharts.dll joined to make it a namespace in the project.
Below we can browse the results.
First create a demochart.aspx file, and in its code, add the content:
Src= "saleschart.aspx?type=pie&width=300&height=30
0&title=sales+by+year&subtitle=books ">
Src= "saleschart.aspx?type=bar&width=300&height=30
0&title=sales+by+year&subtitle=books ">
Type indicates whether the shape is displayed, pie pie, or bar bar.
Width,height represents the size of the graphic.
Title represents the banner text.
Subtitle represents a small caption text.
The results are shown in Figure 1 (picture in the article "ASP.") NET Paint all introduction (ON)).

Thus, we have completed the process of drawing using asp.net technology.
Together, we can sum up the following points: 1. Using asp.net technology, you can draw an ideal graphic without using a third-party component. 2. The drawing core is the construction of a bitmap (bitmap) object that provides the memory space for the graphic to be created. The graph is then drawn using the classes and methods provided by the namespace. You can finally call the bitmap object's "Save" method and send it to any. NET, this is where the content of the graphic is sent directly to the browser without saving it to disk.

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.