本文介绍了在C#.net Win表单中绘制饼图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用c#在Windows窗体中创建一个饼图,并且数值数据来自SQL Server.有谁知道如何在Windows窗体上创建饼图?我真的很感谢任何回答.
谢谢!

Mequ

I was trying to create a pie chart in windows form using c# and the numerical data is coming from SQL server. Is there any one who know how to create a pie chart on windows form? I really appreciate any answer in this.
Thanks!

Mequ

推荐答案


//for input for pie chart..
            int i1 = int.Parse(textBox1.Text);
            int i2 = int.Parse(textBox2.Text);
            int i3 = int.Parse(textBox3.Text);
            int i4 = int.Parse(textBox4.Text);

            float total = i1 + i2 + i3 + i4;
            float deg1 = (i1 / total) * 360;
            float deg2 = (i2 / total) * 360;
            float deg3 = (i3 / total) * 360;
            float deg4 = (i4 / total) * 360;

            Pen p = new Pen(Color.Black, 2);

            Graphics g = this.CreateGraphics();

            Rectangle rec = new Rectangle(textBox1.Location.X + textBox1.Size.Width + 10, 12, 150, 150);

            Brush b1 = new SolidBrush(Color.Red);
            Brush b2 = new SolidBrush(Color.Blue);
            Brush b3 = new SolidBrush(Color.Black);
            Brush b4 = new SolidBrush(Color.BlueViolet);


            g.Clear(Form1.DefaultBackColor);
            g.DrawPie(p, rec, 0, deg1);
            g.FillPie(b1, rec, 0, deg1);
            g.DrawPie(p, rec, deg1, deg2);
            g.FillPie(b2, rec, deg1, deg2);
            g.DrawPie(p, rec, deg2 + deg1, deg3);
            g.FillPie(b3, rec, deg2 + deg1, deg3);
            g.DrawPie(p, rec, deg3 + deg2 + deg1, deg4);
            g.FillPie(b4, rec, deg3 + deg2 + deg1, deg4);


这篇关于在C#.net Win表单中绘制饼图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 18:04