using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //绘制坐标轴开始
            Graphics g = this.CreateGraphics();
            g.Clear(Color.White);
            Pen myPen = new Pen(Color.Blue, 3);
            Point oo1 = new Point(30, this.ClientSize.Height - 100);
            Point oo2 = new Point(this.ClientSize.Width - 50, this.ClientSize.Height - 100);
            g.DrawLine(myPen, oo1, oo2);
            Point oo3 = new Point(30, 30);
            g.DrawLine(myPen, oo1, oo3);
            Font f = new Font("宋体", 12, FontStyle.Bold);
            g.DrawString("x", f, myPen.Brush, oo2);
            g.DrawString("y", f, myPen.Brush, 10, 10);
            //绘制正弦曲线
            float x1, x2,y1,y2,a;
            x1 = x2 = 0;
            y1 = 0; y2 = this.ClientSize.Height - 100;
            for (x2 = 0; x2 < this.ClientSize.Width; x2++)
            {
                a = (float)(2 * Math.PI * x2 / (this.ClientSize.Width));
                y2 = (float)Math.Sin(a);
                y2 = (1 - y2) * (this.ClientSize.Height - 100) / 2;
                g.DrawLine(myPen, x1 + 30, (float)y1, x2 + 30, (float)y2);
                x1 = x2;
                y1 = y2;
            }
        }
        /// <summary>
        /// 饼形图绘制方法
        /// </summary>
        /// <param name="percent"></param>
        /// <param name="percolor"></param>
        private void Fill(int[] percent, Color[] percolor)
        {
            Graphics g = this.CreateGraphics();
            Rectangle r = new Rectangle(10, 10, 400, 400);
            Brush b;
            int beginAngle = 0;
            for (int i = 0; i <= percent.GetUpperBound(0); i++)
            {
                b = new SolidBrush(percolor[i]);
                g.FillPie(b, r, beginAngle, percent[i]);
                beginAngle += percent[i];
            }
        }
        /// <summary>
        /// 绘制饼形图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        
        private void button2_Click(object sender, EventArgs e)
        {
            int[] percent = new int[] { 40,100,50,80,70,20};//总数达到360即可
            Color[] percolor = new Color[] { Color.Tan, Color .Orange,Color.Red,Color.Black,Color.Blue,Color.Green};
            Fill(percent, percolor);
        }
    }
}