最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#繪制餅狀圖和柱狀圖的方法

 更新時(shí)間:2022年02月12日 11:55:11   作者:CodingByMe  
這篇文章主要為大家詳細(xì)介紹了C#繪制餅狀圖和柱狀圖的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C#繪制餅狀圖和柱狀圖的具體代碼,供大家參考,具體內(nèi)容如下

#代碼如下:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TEST3._2
{
? ? public partial class Form1 : Form
? ? {
? ? ? ? public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? }

? ? ? ? private void Form1_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? BarMap();
? ? ? ? }
? ? ? ? private void BitMap()//餅狀圖
? ? ? ? {

? ? ? ? ? ? int[] saleNum = { 300, 500, 400 };
? ? ? ? ? ? int sum = 0, threeNum = 0, fourNum = 0, fiveNum = 0;
? ? ? ? ? ? for (int i = 0; i < saleNum.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sum += saleNum[i];
? ? ? ? ? ? ? ? if (i == 0)
? ? ? ? ? ? ? ? ? ? threeNum = saleNum[0];
? ? ? ? ? ? ? ? else if (i == 1)
? ? ? ? ? ? ? ? ? ? fourNum = saleNum[1];
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? fiveNum = saleNum[2];
? ? ? ? ? ? }

? ? ? ? ? ? int height = pictureBox1.Height, width = pictureBox1.Width;
? ? ? ? ? ? Bitmap bitmap = new Bitmap(width, height);
? ? ? ? ? ? Graphics g = Graphics.FromImage(bitmap);
? ? ? ? ? ? g.Clear(Color.White);
? ? ? ? ? ? Pen pen1 = new Pen(Color.Red);
? ? ? ? ? ? Brush brush1 = new SolidBrush(Color.PowderBlue);
? ? ? ? ? ? Brush brush2 = new SolidBrush(Color.Blue);
? ? ? ? ? ? Brush brush3 = new SolidBrush(Color.Wheat);
? ? ? ? ? ? Brush brush4 = new SolidBrush(Color.Orange);

? ? ? ? ? ? Font font1 = new Font("Couriter New", 16, FontStyle.Bold);
? ? ? ? ? ? Font font2 = new Font("Couriter New", 10);
? ? ? ? ? ? g.FillRectangle(brush1, 0, 0, width, height);
? ? ? ? ? ? g.DrawString("每月銷售占比餅狀圖", font1, brush2, new Point(70, 20));
? ? ? ? ? ? int piex = 100, piey = 60, piew = 200, pieh = 200;
? ? ? ? ? ? float angle1 = Convert.ToSingle((360 / Convert.ToSingle(sum)) * Convert.ToSingle(threeNum));
? ? ? ? ? ? float angle2 = Convert.ToSingle((360 / Convert.ToSingle(sum)) * Convert.ToSingle(fourNum));
? ? ? ? ? ? float angle3 = Convert.ToSingle((360 / Convert.ToSingle(sum)) * Convert.ToSingle(fiveNum));
? ? ? ? ? ? g.FillPie(brush2, piex, piey, piew, pieh, 0, angle1);
? ? ? ? ? ? g.FillPie(brush3, piex, piey, piew, pieh, angle1, angle2);
? ? ? ? ? ? g.FillPie(brush4, piex, piey, piew, pieh, angle1 + angle2, angle3);
? ? ? ? ? ? g.DrawRectangle(pen1, 50, 300, 310, 130);


? ? ? ? ? ? g.FillRectangle(brush2, 90, 320, 20, 10);
? ? ? ? ? ? g.DrawString(string.Format("3月份銷量占比:{0:P2}", Convert.ToSingle(threeNum) / Convert.ToSingle(sum)), font2, brush2, 120, 320);
? ? ? ? ? ? g.FillRectangle(brush3, 90, 360, 20, 10);
? ? ? ? ? ? g.DrawString(string.Format("4月份銷量占比:{0:P2}", Convert.ToSingle(fourNum) / Convert.ToSingle(sum)), font2, brush2, 120, 360);
? ? ? ? ? ? g.FillRectangle(brush4, 90, 400, 20, 10);
? ? ? ? ? ? g.DrawString(string.Format("5月份銷量占比:{0:P2}", Convert.ToSingle(fiveNum) / Convert.ToSingle(sum)), font2, brush2, 120, 400);
? ? ? ? ? ?
? ? ? ? ? ? this.groupBox1.Text = "餅狀圖";
? ? ? ? ? ? this.pictureBox1.Width = bitmap.Width;
? ? ? ? ? ? this.pictureBox1.Height = bitmap.Height;
? ? ? ? ? ? this.pictureBox1.BackgroundImage = bitmap;

? ? ? ? }
? ? ? ? private void BarMap()//柱狀圖
? ? ? ? {
? ? ? ? ? ? int[] saleNum = { 300, 500, 400 };
? ? ? ? ? ? int sum = saleNum[0]+ saleNum[1]+ saleNum[2];
? ? ? ? ? ? float[] Y_Num ={ Convert.ToSingle(saleNum[0]) / Convert.ToSingle(sum),Convert.ToSingle(saleNum[1]) / Convert.ToSingle(sum),
? ? ? ? ? ? ? ? ? ? Convert.ToSingle(saleNum[2]) / Convert.ToSingle(sum) };
? ? ? ? ? ? int height = pictureBox1.Height, width = pictureBox1.Width;
? ? ? ? ? ? Bitmap image = new Bitmap(width, height);
? ? ? ? ? ? //創(chuàng)建Graphics類對(duì)象
? ? ? ? ? ? Graphics g = Graphics.FromImage(image);
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //清空圖片背景色
? ? ? ? ? ? ? ? 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);

? ? ? ? ? ? ? ? Font font2 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
? ? ? ? ? ? ? ? SolidBrush mybrush = new SolidBrush(Color.Red);
? ? ? ? ? ? ? ? SolidBrush mybrush2 = new SolidBrush(Color.Green);
? ? ? ? ? ? ? ? Pen mypen = new Pen(brush, 1);
? ? ? ? ? ? ? ? //繪制線條
? ? ? ? ? ? ? ? //繪制橫向線條
? ? ? ? ? ? ? ? int x = 100;
? ? ? ? ? ? ? ? Pen mypen1 = new Pen(Color.Blue, 2);
? ? ? ? ? ? ? ? x = 60;
? ? ? ? ? ? ? ? g.DrawLine(mypen1, x, 0, x, 300);

? ? ? ? ? ? ? ? //繪制縱向線條
? ? ? ? ? ? ? ? int y = 0;
? ? ? ? ? ? ? ? for (int i = 0; i <11; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? g.DrawLine(mypen, 45, y, 60, y);
? ? ? ? ? ? ? ? ? ? y = y + 30;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ?g.DrawLine(mypen1, 60, y-30, 620, y-30);

? ? ? ? ? ? ? ? //x軸
? ? ? ? ? ? ? ? String[] n = { "3月份", "4月份", "5月份"};
? ? ? ? ? ? ? ? x = 100;
? ? ? ? ? ? ? ? for (int i = 0; i < 3; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? g.DrawString(n[i].ToString(), font, Brushes.Blue, x, 300); //設(shè)置文字內(nèi)容及輸出位置

? ? ? ? ? ? ? ? ? ? Console.WriteLine(300 - Y_Num[i] * 100 * 3);
? ? ? ? ? ? ? ? ? ? g.FillRectangle(mybrush, x, 300 - Y_Num[i] * 100 * 3, 20, Y_Num[i] * 100 * 3);
? ? ? ? ? ? ? ? ? ? g.DrawString(Y_Num[i].ToString(), font2, Brushes.Green, x, 300 - Y_Num[i] * 100 * 3 - 15);

? ? ? ? ? ? ? ? ? ? x = x + 100;
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? //y軸
? ? ? ? ? ? ? ? String[] m = {"0","0.10","0.20", "0.30", "0.40", "0.50", "0.60", "0.70", " 0.80"," 0.90", " 1.00" };
? ? ? ? ? ? ? ? y = 0;
? ? ? ? ? ? ? ? for (int i = 10; i >= 0; i--)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? g.DrawString(m[i].ToString(), font, Brushes.Blue, 20, y); //設(shè)置文字內(nèi)容及輸出位置
? ? ? ? ? ? ? ? ? ? y = y + 30;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? //繪制標(biāo)識(shí)
? ? ? ? ? ? ? ? Font font3 = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
? ? ? ? ? ? ? ? g.DrawRectangle(new Pen(Brushes.Blue), 170, 390, 250, 50); //繪制范圍框
? ? ? ? ? ? ? ? g.FillRectangle(Brushes.Red, 200, 410, 20, 10); //繪制小矩形
? ? ? ? ? ? ? ? g.DrawString("月銷量占比", font3, Brushes.Red, 292, 408);
? ? ? ? ? ? ? ? this.button1.Text = "查看餅狀圖";
? ? ? ? ? ? ? ? this.groupBox1.Text = "柱狀圖";
? ? ? ? ? ? ? ? this.pictureBox1.Width = image.Width;
? ? ? ? ? ? ? ? this.pictureBox1.Height = image.Height;
? ? ? ? ? ? ? ? this.pictureBox1.BackgroundImage = image;?
? ? ? ? ? ? }
? ? ? ? ? ? catch { }
?
? ? ? ? ?}
? ? ? ? private void Button1_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? BitMap();
? ? ? ? ? ? this.button1.Visible =false;//隱藏button
? ? ? ? }
? ? ?
? ? }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#中感嘆號(hào)(!)的一些常見用法小結(jié)

    C#中感嘆號(hào)(!)的一些常見用法小結(jié)

    在C#中,感嘆號(hào)(!)有多種用途,具體取決于上下,文本文主要介紹了C#中感嘆號(hào)(!)的一些常見用法小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-09-09
  • C#?迭代器分部類與索引器詳情

    C#?迭代器分部類與索引器詳情

    這篇文章主要介紹了C#迭代器分部類與索引器詳情,迭代器?迭代器解決的是集合訪問的問題,提供一種方法順序訪問一個(gè)集合對(duì)象中的各個(gè)元素,而不暴露對(duì)象內(nèi)部標(biāo)
    2022-07-07
  • C#圓角窗體簡單實(shí)現(xiàn)方法

    C#圓角窗體簡單實(shí)現(xiàn)方法

    這篇文章主要介紹了C#圓角窗體簡單實(shí)現(xiàn)方法,涉及C#窗體設(shè)置的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • C#通過創(chuàng)建Windows服務(wù)啟動(dòng)程序的方法詳解

    C#通過創(chuàng)建Windows服務(wù)啟動(dòng)程序的方法詳解

    這篇文章主要介紹了C#通過創(chuàng)建Windows服務(wù)啟動(dòng)程序的方法,較為詳細(xì)的分析了C#創(chuàng)建Windows服務(wù)應(yīng)用程序的步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-06-06
  • C#實(shí)現(xiàn)屏幕拷貝的方法

    C#實(shí)現(xiàn)屏幕拷貝的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)屏幕拷貝的方法,實(shí)例分析了兩種常用的屏幕拷貝實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2015-06-06
  • 深入談?wù)凜#9新特性的實(shí)際運(yùn)用

    深入談?wù)凜#9新特性的實(shí)際運(yùn)用

    這篇文章主要給大家介紹了C#9新特性的實(shí)際運(yùn)用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Unity UGUI的ContentSizeFitter內(nèi)容尺寸適應(yīng)器組件使用示例

    Unity UGUI的ContentSizeFitter內(nèi)容尺寸適應(yīng)器組件使用示例

    這篇文章主要為大家介紹了Unity UGUI的ContentSizeFitter內(nèi)容尺寸適應(yīng)器組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • C#模式畫刷HatchBrush用法實(shí)例

    C#模式畫刷HatchBrush用法實(shí)例

    這篇文章主要介紹了C#模式畫刷HatchBrush用法,實(shí)例分析了模式畫刷HatchBrush繪圖的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • C#反射(Reflection)詳解

    C#反射(Reflection)詳解

    本文詳細(xì)講解了C#中的反射(Reflection),文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • C#匿名函數(shù)和匿名方法的使用

    C#匿名函數(shù)和匿名方法的使用

    本文主要介紹了C#匿名函數(shù)和匿名方法的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03

最新評(píng)論

三台县| 台中县| 澄城县| 县级市| 革吉县| 扎赉特旗| 天等县| 石河子市| 永安市| 遂平县| 南川市| 陆良县| 麻江县| 石家庄市| 根河市| 浦东新区| 长丰县| 丰都县| 淅川县| 栾川县| 白城市| 介休市| 乐亭县| 甘谷县| 子长县| 项城市| 五大连池市| 临泉县| 鄄城县| 曲沃县| 贵阳市| 威海市| 伊通| 庄浪县| 施秉县| 福安市| 杭州市| 咸阳市| 襄樊市| 顺义区| 平江县|