C # Implementation pie chart and bar chart

Source: Internet
Author: User
Tags header
Pie chart

Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;

Namespace Xcrm. Module.report
{
<summary>
Summary description of the draw.
</summary>
public class Draw:System.Web.UI.Page
{
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
Draw_imgbar ();
}
Draw a bar chart
void Draw_imgbar () {
Create a bitmap instance with a length of 400 and a broadband of 400
Bitmap bmp = new Bitmap (400,300);
Graphics G;
g = Graphics.fromimage (BMP);
G.clear (Color.snow);
String[] Sitem = {"Very good", "good", "General", "poor"};
int[] num = {1000,69,90,2000};
int cnt,i,len,ibarwidth;
float scale;
Float[] Nflt;
string header;
Header = "";
CNT = 0;
Ibarwidth = 40;
scale = 1;
len = num. Length;
Nflt. Length = Len;
Nflt = new Float[len];
for (i=0;i<len;i++)
{
CNT + + num[i];
}
Flt = Cnt/len;
for (i=0;i<len;i++)
{
Nflt[i] = * NUM[I]/CNT;
Nflt[i] = scale * NUM[I]/CNT;
}

Header = "Survey of statistical results at a glance";
g.DrawString (header, New Font ("Song Body", 12,fontstyle.bold), Brushes.black, New Point (75, 10));
Point Myrec = new Point (300, 40);
Point mydec = new Point (320, 40);


for (i=0;i<len;i++)
{
G.drawrectangle (Pens.black, myrec.x, Myrec.y, 20, 10);
Draw Small Squares
G.fillrectangle (New SolidBrush (Return_color (i)), myrec.x, Myrec.y, 20, 10);
Fill Small Squares
g.DrawString ("" + sitem[i], new Font ("Song Body", 9), Brushes.black, MyDec);
Draw the text on the right side of the small square
Myrec.y + 15;
Mydec.y + 15;

G. DrawRectangle (Pens.black, (i * ibarwidth) +, 290-(nflt[i] * scale), (nflt[i] * scale) + 5);
Draw bar Graph
G. FillRectangle (New SolidBrush (Return_color (i)), (i * ibarwidth) +, 290-(nflt[i] * scale), (nflt[ I] * scale) + 5);
Fills the bar graph with the specified color
G. DrawString (num[i). ToString (), New Font ("Arial", 9), Brushes.black, (i * ibarwidth) +, 275-(nflt[i] * scale));
Show data represented by bar graph

s = s + nflt[i];
}
Pen p = new Pen (color.black, 1);
G. DrawRectangle (P, 1, 1, 398, 298);
Bmp. Save (Response.outputstream, System.Drawing.Imaging.ImageFormat.Jpeg);
Bmp. Dispose ();
}


Gao Map
void Draw_img () {
Bitmap bmp = new Bitmap (400,300);
Create a bitmap instance with a length of 400 and a broadband of 400
Graphics G;
g = Graphics.fromimage (BMP);
G.clear (Color.snow);
String[] Sitem = {"Very good", "good", "General", "poor"};
int[] num = {1000,69,90,20};
int Cnt,i,len;
float S;
Float[] Nflt;
string header;
Header = "";
CNT = 0;
s = 0;
len = num. Length;
Nflt. Length = Len;
Nflt = new Float[len];
for (i=0;i<len;i++) {
CNT + + num[i];
}
Flt = Cnt/len;
for (i=0;i<len;i++) {

Nflt[i] = 360 * NUM[I]/CNT;
}


Header = "Survey of statistical results at a glance";
g.DrawString (header, New Font ("Song Body", 12,fontstyle.bold), Brushes.black, New Point (75, 10));
g.DrawString ("Unit: Times", New Font ("Song Body", 9), brushes. Black, new Point (300, 25));

Point Myrec = new Point (300, 40);
Point mydec = new Point (320, 40);


for (i=0;i<len;i++)
{
if (i==len-1) {
s = 360-s;
Nflt[i] = 360-s;
}

G.drawrectangle (Pens.black, myrec.x, Myrec.y, 20, 10);
Draw Small Squares
G.fillrectangle (New SolidBrush (Return_color (i)), myrec.x, Myrec.y, 20, 10);
Fill Small Squares
g.DrawString ("" + Sitem[i] + "" + num[i], new Font ("Song Body", 9), Brushes.black, MyDec);
Draw the text on the right side of the small square
Myrec.y + 15;
Mydec.y + 15;

G.fillpie (New SolidBrush (Return_color (i)), M, S, Nflt[i]);
G.drawpie (Pens.black, M, S, Nflt[i]);
s = s + nflt[i];
}
Pen p = new Pen (color.black, 1);
G. DrawRectangle (P, 1, 1, 398, 298);
Bmp. Save (Response.outputstream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Public Color return_color (int i) {
switch (i) {
Case 0:
return color.red;
Break
Case 1:
return color.blue;
Break
Case 2:
return color.yellow;
Case 3:
return color.green;
Break
Case 4:
return color.pink;
Break
Case 5:
return color.plum;
Break
Case 6:
return color.gray;
Break
Case 7:
return Color.salmon;
Break
Case 8:
return color.rosybrown;
Break
Case 9:
return color.teal;
Break
Case 10:
return color.orange;
Break
Case 11:
return color.thistle;
Break
Case 12:
return color.maroon;
Break
Default
return color.whitesmoke;
Break

}
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}




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.