日期:2014-05-17  浏览次数:20859 次

C# 绘制柱形图 图形高度和Y轴不一致
private void CreateImage() {

           string[] month = new string[5] { "第一季度", "第二季度", "第三季度", "第四季度", "全年"};
          //  float[] d = new float[12] { 20,30,10,50,25,36,14,70,50.4F,28,31,10};
            Bitmap bMap = new Bitmap(700,700);
            Graphics gph = Graphics.FromImage(bMap);
            gph.Clear(Color.White);

            PointF cpt = new PointF(40, 420);
            //X轴三角形
            PointF[] xpt = new PointF[3] { new PointF(cpt.Y+8, cpt.Y), new PointF(cpt.Y, cpt.Y - 4), new PointF(cpt.Y, cpt.Y + 4) };
            //Y轴三角形
            PointF[] ypt = new PointF[3] { new PointF(cpt.X, cpt.X - 8), new PointF(cpt.X -4, cpt.X), new PointF(cpt.X + 4, cpt.X) };
            gph.DrawString("呼叫统计图", new Font("宋体", 14), Brushes.Black, new PointF(cpt.X + 60, cpt.X));
         
            //画X轴
            gph.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.Y, cpt.Y);
            gph.DrawPolygon(Pens.Black, xpt);
            gph.FillPolygon(new SolidBrush(Color.Black), xpt);
            gph.DrawString("月份",new Font("宋体",12),Brushes.Black,new PointF(cpt.Y+10,cpt.Y+10));
            //画Y轴
            gph.DrawLine(Pens.Black, cpt.X, cpt.Y, cpt.X, cpt.X);
            gph.DrawPolygon(Pens.Black, ypt);
            gph.FillPolygon(new SolidBrush(Color.Black), ypt);