#饼图的绘制
Graphics gd = this.CreateGraphics();
Rectangle rect = new Rectangle(40, 40, 150, 150);//用矩形框框定饼图的位置和大小
float[] iStr = new float[6] { 2,3,5,4,4,3 };//在代码中建立了数组用来模拟数据库导入的数据
int i = 0;
float arc = 0;
while (i < 6)
{
gd.FillPie(new SolidBrush(Color.FromArgb(230,36+40 * i,90)), rect, arc - 90, iStr[i] /iStr.Sum()*360);
arc += iStr[i] / iStr.Sum() * 360;
i++;
}
#摘录一下学习笔记
直线
Graphics gd = this.CreateGraphics();
gd.DrawLine(new Pen(Color.Blue), 40, 20, 190, 20);//直线
矩形
gd.DrawRectangle(new Pen(Color.Blue),40, 40, 150, 150); //矩形框
gd.FillRectangle(new SolidBrush(Color.LightBlue), 200, 40, 150, 150); //填充矩形
椭圆和圆
gd.DrawEllipse(new Pen(Color.Blue), 380, 40, 150, 150);//椭圆形框
gd.FillEllipse(new SolidBrush(Color.LightBlue), 540, 40, 150, 150);//填充椭圆
圆弧和扇形
gd.DrawArc(new Pen(Color.Blue), new Rectangle(40, 220, 150, 150), -90, 60);//一段圆弧
gd.FillPie(new SolidBrush(Color.LightBlue), new Rectangle(200, 220, 150, 150), -90 , 60);//扇形
//刚开始画圆弧不会卡位置,就先用矩形框框一下卡个位置,写完把矩形框删了就好了 ,以下是多个扇形组合图
Rectangle rect = new Rectangle(380, 220, 150, 150);
gd.DrawRectangle(new Pen(Color.Blue),rect);//待删除
gd.FillPie(new SolidBrush(Color.FromArgb(236, 80, 85)), rect, -90, 60);
gd.FillPie(new SolidBrush(Color.FromArgb(200, 120, 100)), rect, 0, 60);
gd.FillPie(new SolidBrush(Color.FromArgb(200, 180, 120)), rect, 90, 60);
gd.FillPie(new SolidBrush(Color.FromArgb(200, 230, 180)), rect, 180, 60);
gd.Dispose();
以上所有图示:
文字:
Font f=SystemFonts.DefaultFont;
gd.DrawString("字符串",f,Brushes.Red,10,10);
f=new Font("隶书",字体大小);