欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C# 繪制統(tǒng)計(jì)圖大全(柱狀圖, 折線圖, 扇形圖)

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

統(tǒng)計(jì)圖形種類繁多, 有柱狀圖, 折線圖, 扇形圖等等, 而統(tǒng)計(jì)圖形的繪制方法也有很多, 有Flash制作的統(tǒng)計(jì)圖形, 有水晶報(bào)表生成統(tǒng)計(jì)圖形, 有專門制圖軟件制作, 也有編程語言自己制作的;這里我們用就C# 制作三款最經(jīng)典的統(tǒng)計(jì)圖: 柱狀圖, 折線圖和扇形圖;既然是統(tǒng)計(jì), 當(dāng)然需要數(shù)據(jù), 這里演示的數(shù)據(jù)存于Sql Server2000中, 三款統(tǒng)計(jì)圖形都是動(dòng)態(tài)生成. 其中柱狀圖我會(huì)附上制作步驟, 其他兩款統(tǒng)計(jì)圖直接附源碼.

說明: 需求不一樣, 統(tǒng)計(jì)圖形繪制后的顯示效果也不一樣, 比如這里柱狀圖的主要需求是為了比較每一期報(bào)名人數(shù)與通過人數(shù)的差, 因此會(huì)把兩根柱子放在一起會(huì)使比較結(jié)果一目了然. 因此大家可以根據(jù)需要靈活繪制.

一. 柱狀圖的繪制.

繪制步驟如下:

1. 定義繪圖用到的類.

int height = 500, width = 700;
Bitmap image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);
Pen mypen = new Pen(brush, 1);

2. 繪制圖框.

g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);

3. 繪制橫向坐標(biāo)線

for (int i = 0; i < 14; i++) 
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 40;
} 

4. 繪制縱向坐標(biāo)線

for (int i = 0; i < 9; i++) 
{
g.DrawLine(mypen, 60, y, 620, y);
y = y + 26;
}

5. 繪制橫坐標(biāo)值

String[] n = { "第一期", "第二期", "第三期", "第四期", "全年" };
for (int i = 0; i < 7; i++) 
{
g.DrawString(n[i].ToString(), font, Brushes.Blue, x, 348); 
x = x + 78;
}

6. 繪制縱坐標(biāo)值

String[] m = {"250","225", "200", "175", "150", "125", "100“};
for (int i = 0; i < 10; i++) 
{
g.DrawString(m[i].ToString(), font, Brushes.Blue, 25, y);
y = y + 26;
}

7. 定義數(shù)組存儲(chǔ)數(shù)據(jù)庫中統(tǒng)計(jì)的數(shù)據(jù)

int[] Count1 = new int[7]; //存儲(chǔ)從數(shù)據(jù)庫讀取的報(bào)名人數(shù)
int[] Count2 = new int[7]; //存儲(chǔ)從數(shù)據(jù)庫讀取的通過人數(shù)

8. 從數(shù)據(jù)庫中讀取報(bào)名人數(shù)與通過人數(shù)

SqlConnection Con = new SqlConnection(
"Server=(Local);Database=committeeTraining;");
Con.Open();
string cmdtxt2 = "SELECT * FROM ##Count 
where Company='" + ****+ "'";
SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);
DataSet ds = new DataSet();
da.Fill(ds);

9. 將讀取的數(shù)據(jù)存儲(chǔ)到數(shù)組中

Count1[0] = Convert.ToInt32(ds.Tables[0].Rows[0][“count1”].ToString()); 
Count1[1] = Convert.ToInt32(ds.Tables[0].Rows[0][“count3”].ToString()); 
Count2[0] = Convert.ToInt32(ds.Tables[0].Rows[0][“count2”].ToString()); 
Count2[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count4"].ToString());

10.定義畫筆和畫刷準(zhǔn)備繪圖

x = 80; 
Font font2 = new System.Drawing.Font(
"Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
SolidBrush mybrush2 = new SolidBrush(Color.Green);

11. 根據(jù)數(shù)組中的值繪制柱狀圖

(1)第一期報(bào)名人數(shù)

g.FillRectangle(mybrush, x, 340 - Count1[0], 20, Count1[0]);
g.DrawString(Count1[0].ToString(), font2, 
Brushes.Red, x, 340 - Count1[0] - 15);

(2) 第一期通過人數(shù)

x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[0], 20, Count2[0]);
g.DrawString(Count2[0].ToString(), font2, 
Brushes.Green, x, 340 - Count2[0] - 15);

12. 將圖形輸出到頁面.

System.IO.MemoryStream ms = new 
System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());

最終柱狀圖的效果圖:
柱狀圖的完整代碼:

private void CreateImage()
{
int height = 500, width = 700;
Bitmap image = new Bitmap(width, height);
//創(chuàng)建Graphics類對(duì)象
Graphics g = Graphics.FromImage(image);

try
{
//清空?qǐng)D片背景色
g.Clear(Color.White);

Font font = new Font("Arial", 10, FontStyle.Regular);
Font font1 = new Font("宋體", 20, FontStyle.Bold);

LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), 
Color.Blue, Color.BlueViolet, 1.2f, true);
g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
// Brush brush1 = new SolidBrush(Color.Blue);

g.DrawString(this.ddlTaget.SelectedItem.Text + " " + this.ddlYear.SelectedItem.Text + 
" 成績統(tǒng)計(jì)柱狀圖", font1, brush, new PointF(70, 30));
//畫圖片的邊框線
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);


Pen mypen = new Pen(brush, 1);
//繪制線條
//繪制橫向線條
int x = 100;
for (int i = 0; i < 14; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 40;
}
Pen mypen1 = new Pen(Color.Blue, 2);
x = 60;
g.DrawLine(mypen1, x, 80, x, 340);

//繪制縱向線條
int y = 106;
for (int i = 0; i < 9; i++)
{
g.DrawLine(mypen, 60, y, 620, y);
y = y + 26;
}
g.DrawLine(mypen1, 60, y, 620, y);

//x軸
String[] n = { "第一期", "第二期", "第三期", "第四期", "上半年", "下半年", "全年統(tǒng)計(jì)" };
x = 78;
for (int i = 0; i < 7; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Blue, x, 348); //設(shè)置文字內(nèi)容及輸出位置
x = x + 78;
}

//y軸
String[] m = {"250","225", "200", "175", "150", "125", "100", " 75",
" 50", " 25", " 0"};
y = 72;
for (int i = 0; i < 10; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Blue, 25, y); //設(shè)置文字內(nèi)容及輸出位置
y = y + 26;
}

int[] Count1 = new int[7];
int[] Count2 = new int[7];

SqlConnection Con = new SqlConnection("Server=(Local);Database=committeeTraining;Uid=sa;Pwd=**");
Con.Open();
string cmdtxt2 = "SELECT * FROM ##Count where Company='" + this.ddlTaget.SelectedItem.Text.Trim() + "'";
SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);
DataSet ds = new DataSet();
da.Fill(ds);

Count1[0] = Convert.ToInt32(ds.Tables[0].Rows[0]["count1"].ToString());
Count1[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count3"].ToString());
Count1[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count5"].ToString());
Count1[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count7"].ToString());

Count1[4] = Count1[0] + Count1[1];
Count1[5] = Count1[2] + Count1[3];

Count1[6] = Convert.ToInt32(ds.Tables[0].Rows[0]["count9"].ToString());


Count2[0] = Convert.ToInt32(ds.Tables[0].Rows[0]["count2"].ToString());
Count2[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count4"].ToString());
Count2[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count6"].ToString());
Count2[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count8"].ToString());

Count2[4] = Count2[0] + Count2[1];
Count2[5] = Count2[2] + Count2[3];

Count2[6] = Convert.ToInt32(ds.Tables[0].Rows[0]["count10"].ToString());

//繪制柱狀圖.
x = 80;
Font font2 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
SolidBrush mybrush2 = new SolidBrush(Color.Green);

//第一期
g.FillRectangle(mybrush, x, 340 - Count1[0], 20, Count1[0]);
g.DrawString(Count1[0].ToString(), font2, Brushes.Red, x, 340 - Count1[0] - 15);

x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[0], 20, Count2[0]);
g.DrawString(Count2[0].ToString(), font2, Brushes.Green, x, 340 - Count2[0] - 15);


//第二期
x = x + 60;
g.FillRectangle(mybrush, x, 340 - Count1[1], 20, Count1[1]);
g.DrawString(Count1[1].ToString(), font2, Brushes.Red, x, 340 - Count1[1] - 15);


x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[1], 20, Count2[1]);
g.DrawString(Count2[1].ToString(), font2, Brushes.Green, x, 340 - Count2[1] - 15);


//第三期
x = x + 60;
g.FillRectangle(mybrush, x, 340 - Count1[2], 20, Count1[2]);
g.DrawString(Count1[2].ToString(), font2, Brushes.Red, x, 340 - Count1[2] - 15);

x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[2], 20, Count2[2]);
g.DrawString(Count2[2].ToString(), font2, Brushes.Green, x, 340 - Count2[2] - 15);

//第四期
x = x + 60;
g.FillRectangle(mybrush, x, 340 - Count1[3], 20, Count1[3]);
g.DrawString(Count1[3].ToString(), font2, Brushes.Red, x, 340 - Count1[3] - 15);

x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[3], 20, Count2[3]);
g.DrawString(Count2[3].ToString(), font2, Brushes.Green, x, 340 - Count2[3] - 15);

//上半年
x = x + 60;
g.FillRectangle(mybrush, x, 340 - Count1[4], 20, Count1[4]);
g.DrawString(Count1[4].ToString(), font2, Brushes.Red, x, 340 - Count1[4] - 15);

x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[4], 20, Count2[4]);
g.DrawString(Count2[4].ToString(), font2, Brushes.Green, x, 340 - Count2[4] - 15);

//下半年
x = x + 60;
g.FillRectangle(mybrush, x, 340 - Count1[5], 20, Count1[5]);
g.DrawString(Count1[5].ToString(), font2, Brushes.Red, x, 340 - Count1[5] - 15);

x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[5], 20, Count2[5]);
g.DrawString(Count2[5].ToString(), font2, Brushes.Green, x, 340 - Count2[5] - 15);

//全年
x = x + 60;
g.FillRectangle(mybrush, x, 340 - Count1[6], 20, Count1[6]);
g.DrawString(Count1[6].ToString(), font2, Brushes.Red, x, 340 - Count1[6] - 15);


x = x + 20;
g.FillRectangle(mybrush2, x, 340 - Count2[6], 20, Count2[6]);
g.DrawString(Count2[6].ToString(), font2, Brushes.Green, x, 340 - Count2[6] - 15);


//繪制標(biāo)識(shí)
Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
g.DrawRectangle(new Pen(Brushes.Blue), 170, 400, 250, 50); //繪制范圍框
g.FillRectangle(Brushes.Red, 270, 410, 20, 10); //繪制小矩形
g.DrawString("報(bào)名人數(shù)", font3, Brushes.Red, 292, 408);

g.FillRectangle(Brushes.Green, 270, 430, 20, 10);
g.DrawString("通過人數(shù)", font3, Brushes.Green, 292, 428);

System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}

二. 折線統(tǒng)計(jì)圖的繪制

效果:

折線圖的完整代碼:

private void CreateImage()
{
int height = 480, width = 700;
Bitmap image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);

try
{
//清空?qǐng)D片背景色
g.Clear(Color.White);

Font font = new System.Drawing.Font("Arial", 9, FontStyle.Regular);
Font font1 = new System.Drawing.Font("宋體", 20, FontStyle.Regular);
Font font2 = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
LinearGradientBrush brush = new LinearGradientBrush(
new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.Blue, 1.2f, true);
g.FillRectangle(Brushes.AliceBlue, 0, 0, width, height);
Brush brush1 = new SolidBrush(Color.Blue);
Brush brush2 = new SolidBrush(Color.SaddleBrown);

g.DrawString(this.ddlTaget.SelectedItem.Text + " " + this.ddlYear.SelectedItem.Text + 
" 成績統(tǒng)計(jì)折線圖", font1, brush1, new PointF(85, 30));
//畫圖片的邊框線
g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);

Pen mypen = new Pen(brush, 1);
Pen mypen2 = new Pen(Color.Red, 2);
//繪制線條
//繪制縱向線條
int x = 60;
for (int i = 0; i < 8; i++)
{
g.DrawLine(mypen, x, 80, x, 340);
x = x + 80;
}
Pen mypen1 = new Pen(Color.Blue, 3);
x = 60;
g.DrawLine(mypen1, x, 82, x, 340);

//繪制橫向線條
int y = 106;
for (int i = 0; i < 10; i++)
{
g.DrawLine(mypen, 60, y, 620, y);
y = y + 26;
}
// y = 106;
g.DrawLine(mypen1, 60, y - 26, 620, y - 26);

//x軸
String[] n = { "第一期", "第二期", "第三期", "第四期", "上半年", "下半年", "全年統(tǒng)計(jì)" };
x = 45;
for (int i = 0; i < 7; i++)
{
g.DrawString(n[i].ToString(), font, Brushes.Red, x, 348); //設(shè)置文字內(nèi)容及輸出位置
x = x + 77;
}

//y軸
String[] m = { "220人", " 200人", " 175人", "150人", " 125人", " 100人", " 75人", " 50人",
" 25人"};
y = 100;
for (int i = 0; i < 9; i++)
{
g.DrawString(m[i].ToString(), font, Brushes.Red, 10, y); //設(shè)置文字內(nèi)容及輸出位置
y = y + 26;
}

int[] Count1 = new int[7];
int[] Count2 = new int[7];

SqlConnection Con = new SqlConnection("Server=(Local);Database=committeeTraining;Uid=sa;Pwd=eesoft");
Con.Open();
string cmdtxt2 = "SELECT * FROM ##Count where Company='" + this.ddlTaget.SelectedItem.Text.Trim() + "'";
SqlDataAdapter da = new SqlDataAdapter(cmdtxt2, Con);
DataSet ds = new DataSet();
da.Fill(ds);

//報(bào)名人數(shù)
Count1[0] = Convert.ToInt32(ds.Tables[0].Rows[0]["count1"].ToString());
Count1[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count3"].ToString());
Count1[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count5"].ToString());
Count1[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count7"].ToString());

Count1[6] = Convert.ToInt32(ds.Tables[0].Rows[0]["count9"].ToString()); //全年

Count1[4] = Count1[0] + Count1[1];
Count1[5] = Count1[2] + Count1[3];


Count2[0] = Convert.ToInt32(ds.Tables[0].Rows[0]["count2"].ToString());
Count2[1] = Convert.ToInt32(ds.Tables[0].Rows[0]["count4"].ToString());
Count2[2] = Convert.ToInt32(ds.Tables[0].Rows[0]["count6"].ToString());
Count2[3] = Convert.ToInt32(ds.Tables[0].Rows[0]["count8"].ToString());

Count2[6] = Convert.ToInt32(ds.Tables[0].Rows[0]["count10"].ToString()); //全年

Count2[4] = Count2[0] + Count2[1];
Count2[5] = Count2[2] + Count2[3];


//顯示折線效果
Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
SolidBrush mybrush = new SolidBrush(Color.Red);
Point[] points1 = new Point[7];
points1[0].X = 60; points1[0].Y = 340 - Count1[0]; //從106縱坐標(biāo)開始, 到(0, 0)坐標(biāo)時(shí)
points1[1].X = 140; points1[1].Y = 340 - Count1[1];
points1[2].X = 220; points1[2].Y = 340 - Count1[2];
points1[3].X = 300; points1[3].Y = 340 - Count1[3];

points1[4].X = 380; points1[4].Y = 340 - Count1[4];
points1[5].X = 460; points1[5].Y = 340 - Count1[5];

points1[6].X = 540; points1[6].Y = 340 - Count1[6];
g.DrawLines(mypen2, points1); //繪制折線

//繪制數(shù)字
g.DrawString(Count1[0].ToString(), font3, Brushes.Red, 58, points1[0].Y - 20);
g.DrawString(Count1[1].ToString(), font3, Brushes.Red, 138, points1[1].Y - 20);
g.DrawString(Count1[2].ToString(), font3, Brushes.Red, 218, points1[2].Y - 20);
g.DrawString(Count1[3].ToString(), font3, Brushes.Red, 298, points1[3].Y - 20);

g.DrawString(Count1[4].ToString(), font3, Brushes.Red, 378, points1[4].Y - 20);
g.DrawString(Count1[5].ToString(), font3, Brushes.Red, 458, points1[5].Y - 20);

g.DrawString(Count1[6].ToString(), font3, Brushes.Red, 538, points1[6].Y - 20);

Pen mypen3 = new Pen(Color.Green, 2);
Point[] points2 = new Point[7];
points2[0].X = 60; points2[0].Y = 340 - Count2[0];
points2[1].X = 140; points2[1].Y = 340 - Count2[1];
points2[2].X = 220; points2[2].Y = 340 - Count2[2];
points2[3].X = 300; points2[3].Y = 340 - Count2[3];

points2[4].X = 380; points2[4].Y = 340 - Count2[4];
points2[5].X = 460; points2[5].Y = 340 - Count2[5];

points2[6].X = 540; points2[6].Y = 340 - Count2[6];
g.DrawLines(mypen3, points2); //繪制折線

//繪制通過人數(shù)
g.DrawString(Count2[0].ToString(), font3, Brushes.Green, 61, points2[0].Y - 15);
g.DrawString(Count2[1].ToString(), font3, Brushes.Green, 131, points2[1].Y - 15);
g.DrawString(Count2[2].ToString(), font3, Brushes.Green, 221, points2[2].Y - 15);
g.DrawString(Count2[3].ToString(), font3, Brushes.Green, 301, points2[3].Y - 15);

g.DrawString(Count2[4].ToString(), font3, Brushes.Green, 381, points2[4].Y - 15);
g.DrawString(Count2[5].ToString(), font3, Brushes.Green, 461, points2[5].Y - 15);

g.DrawString(Count2[6].ToString(), font3, Brushes.Green, 541, points2[6].Y - 15);

//繪制標(biāo)識(shí)
g.DrawRectangle(new Pen(Brushes.Red), 180, 390, 250, 50); //繪制范圍框
g.FillRectangle(Brushes.Red, 270, 402, 20, 10); //繪制小矩形
g.DrawString("報(bào)名人數(shù)", font2, Brushes.Red, 292, 400);

g.FillRectangle(Brushes.Green, 270, 422, 20, 10);
g.DrawString("通過人數(shù)", font2, Brushes.Green, 292, 420);

System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ClearContent();
Response.ContentType = "image/Jpeg";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}

三. 扇形統(tǒng)計(jì)圖的繪制

扇形圖完整代碼:

private void CreateImage()
{
//把連接字串指定為一個(gè)常量
SqlConnection Con = new SqlConnection("Server=(Local);
Database=committeeTraining;Uid=sa;Pwd=**");
Con.Open();
string cmdtxt = selectString; // "select * from ##Count"; //
//SqlCommand Com = new SqlCommand(cmdtxt, Con);
DataSet ds = new DataSet();
SqlDataAdapter Da = new SqlDataAdapter(cmdtxt, Con);
Da.Fill(ds);
Con.Close();
float Total = 0.0f, Tmp;

//轉(zhuǎn)換成單精度。也可寫成Convert.ToInt32
Total = Convert.ToSingle(ds.Tables[0].Rows[0][this.count[0]]);

// Total=Convert.ToSingle(ds.Tables[0].Rows[0][this.count[0]]);
//設(shè)置字體,fonttitle為主標(biāo)題的字體
Font fontlegend = new Font("verdana", 9);
Font fonttitle = new Font("verdana", 10, FontStyle.Bold);

//背景寬
int width = 350;
int bufferspace = 15;
int legendheight = fontlegend.Height * 10 + bufferspace; //高度
int titleheight = fonttitle.Height + bufferspace;
int height = width + legendheight + titleheight + bufferspace;//白色背景高
int pieheight = width;
Rectangle pierect = new Rectangle(0, titleheight, width, pieheight);

//加上各種隨機(jī)色
ArrayList colors = new ArrayList();
Random rnd = new Random();
for (int i = 0; i < 2; i++)
colors.Add(new SolidBrush(Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255))));

//創(chuàng)建一個(gè)bitmap實(shí)例
Bitmap objbitmap = new Bitmap(width, height);
Graphics objgraphics = Graphics.FromImage(objbitmap);

//畫一個(gè)白色背景
objgraphics.FillRectangle(new SolidBrush(Color.White), 0, 0, width, height);

//畫一個(gè)亮黃色背景 
objgraphics.FillRectangle(new SolidBrush(Color.Beige), pierect);

//以下為畫餅圖(有幾行row畫幾個(gè))
float currentdegree = 0.0f;

//畫通過人數(shù)
objgraphics.FillPie((SolidBrush)colors[1], pierect, currentdegree,
Convert.ToSingle(ds.Tables[0].Rows[0][this.count[1]]) / Total * 360);
currentdegree += Convert.ToSingle(ds.Tables[0].Rows[0][this.count[1]]) / Total * 360;

//未通過人數(shù)餅狀圖
objgraphics.FillPie((SolidBrush)colors[0], pierect, currentdegree,
((Convert.ToSingle(ds.Tables[0].Rows[0][this.count[0]]))-(Convert.ToSingle(ds.Tables[0].Rows[0][this.count[1]]))) / Total * 360);
currentdegree += ((Convert.ToSingle(ds.Tables[0].Rows[0][this.count[0]])) - 
(Convert.ToSingle(ds.Tables[0].Rows[0][this.count[1]]))) / Total * 360;


//以下為生成主標(biāo)題
SolidBrush blackbrush = new SolidBrush(Color.Black);
SolidBrush bluebrush = new SolidBrush(Color.Blue);
string title = " 機(jī)關(guān)單位成績統(tǒng)計(jì)餅狀圖: "
+ "\n \n\n";
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;

objgraphics.DrawString(title, fonttitle, blackbrush,
new Rectangle(0, 0, width, titleheight), stringFormat);

//列出各字段與得數(shù)目
objgraphics.DrawRectangle(new Pen(Color.Red, 2), 0, height + 10 - legendheight, width, legendheight + 50);

objgraphics.DrawString("----------------統(tǒng)計(jì)信息------------------", 
fontlegend, bluebrush, 20, height - legendheight + fontlegend.Height * 1 + 1);
objgraphics.DrawString("統(tǒng)計(jì)單位: " + this.ddlTaget.SelectedItem.Text, 
fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * 3 + 1);
objgraphics.DrawString("統(tǒng)計(jì)年份: " + this.ddlYear.SelectedItem.Text, 
fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * 4 + 1);
objgraphics.DrawString("統(tǒng)計(jì)期數(shù): " + this.ddlSpan.SelectedItem.Text, 
fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * 5 + 1);

objgraphics.FillRectangle((SolidBrush)colors[1], 5,height - legendheight + fontlegend.Height * 8 + 1, 10, 10);
objgraphics.DrawString("報(bào)名總?cè)藬?shù): " + Convert.ToString(Convert.ToSingle(ds.Tables[0].Rows[0][this.count[0]])), 
fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * 7 + 1);
objgraphics.FillRectangle((SolidBrush)colors[0], 5, height - legendheight + fontlegend.Height * 9 + 1, 10, 10);
objgraphics.DrawString("通過總?cè)藬?shù): " + Convert.ToString(Convert.ToSingle(ds.Tables[0].Rows[0][this.count[1]])), 
fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * 8 + 1);
objgraphics.DrawString("未通過人數(shù): " + ((Convert.ToSingle(ds.Tables[0].Rows[0][this.count[0]])) - 
(Convert.ToSingle(ds.Tables[0].Rows[0][this.count[1]]))), fontlegend, blackbrush, 20, height - legendheight + fontlegend.Height * 9 + 1);

objgraphics.DrawString("通過率: " + Convert.ToString((Convert.ToSingle(ds.Tables[0].Rows[0][this.count[1]]) / 
Convert.ToSingle(ds.Tables[0].Rows[0][this.count[0]])) * 100)+ " %", fontlegend, 
blackbrush, 20, height - legendheight + fontlegend.Height * 10 + 1);

Response.ContentType = "image/Jpeg";
objbitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
objgraphics.Dispose();
objbitmap.Dispose();

}

 這里的統(tǒng)計(jì)圖直接輸出到網(wǎng)頁,以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C#如何實(shí)現(xiàn)圖片的剪裁并保存

欄    目:C#教程

下一篇:WPF調(diào)用Matlab函數(shù)的方法

本文標(biāo)題:C# 繪制統(tǒng)計(jì)圖大全(柱狀圖, 折線圖, 扇形圖)

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6190.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有