用 C# 制作图形饼图

发布于 2024-08-06 18:35:57 字数 1073 浏览 5 评论 0原文

我正在尝试编写一个 Windows 应用程序,显示一个带有七个不等切片(25%、20%、18%、17%、10%、10%、10%)的饼图,所有切片的颜色都不同。

到目前为止,我已经制作了附有颜色的钢笔和画笔并画了一个圆圈。

到目前为止,这就是我

private void Form1_Paint(object sender, PaintEventArgs e)
    {
        this.BackColor = Color.White;
        this.Text = "Pie Chart";
        this.Width = 350;
        this.Height = 350;

        Pen black = new Pen(Color.Black);
        Pen blue = new Pen(Color.Blue);
        Pen green = new Pen(Color.Green);
        Pen red = new Pen(Color.Red);
        Pen orange = new Pen(Color.Orange);
        Pen pink = new Pen(Color.Pink);
        Pen purple = new Pen(Color.Purple);
        Pen magenta = new Pen(Color.Purple);
        Brush brBlue = blue.Brush;
        Brush brGreen = green.Brush;
        Brush brRed = red.Brush;
        Brush brOrange = orange.Brush;
        Brush brPink = pink.Brush;
        Brush brPurple = purple.Brush;
        Brush brMagenta = magenta.Brush;
        Graphics g = e.Graphics;

        g.DrawEllipse(black, 20, 10, 300, 300);

    }

向你提出的问题。绘制饼图最简单的方法是什么?

I'm trying to write a Windows Application that shows a pie chart with seven unequal slices (25%, 20%, 18%, 17%, 10%, 10%, 10%) all of them will be colored differently.

So far I have made Pens and Brushes with colors attached and drawn a circle.

This is what I have so far

private void Form1_Paint(object sender, PaintEventArgs e)
    {
        this.BackColor = Color.White;
        this.Text = "Pie Chart";
        this.Width = 350;
        this.Height = 350;

        Pen black = new Pen(Color.Black);
        Pen blue = new Pen(Color.Blue);
        Pen green = new Pen(Color.Green);
        Pen red = new Pen(Color.Red);
        Pen orange = new Pen(Color.Orange);
        Pen pink = new Pen(Color.Pink);
        Pen purple = new Pen(Color.Purple);
        Pen magenta = new Pen(Color.Purple);
        Brush brBlue = blue.Brush;
        Brush brGreen = green.Brush;
        Brush brRed = red.Brush;
        Brush brOrange = orange.Brush;
        Brush brPink = pink.Brush;
        Brush brPurple = purple.Brush;
        Brush brMagenta = magenta.Brush;
        Graphics g = e.Graphics;

        g.DrawEllipse(black, 20, 10, 300, 300);

    }

My question to you is. What would be the easiest way to draw the wedges of the pie?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

短叹 2024-08-13 18:35:57

我建议您看一下 ZedGraph

如果您想要示例代码来实际使用 GDI 绘制饼图,您可以检查此 教程。。它使用 FillPie< /strong> Graphics 类的方法。

I will advise you to take a look at ZedGraph.

If you want a sample code to actually draw pieChart using GDI you can check this tutorial.. It uses FillPie Method of Graphics class.

愿得七秒忆 2024-08-13 18:35:57

这不是您问题的直接答案,但您为什么不使用 Microsoft 图表控件

Scott Gu 的相关帖子

This isn't a direct answer to you question, but why aren't you using the Microsoft chart controls?

Scott Gu's post about it

暖伴 2024-08-13 18:35:57

CodeProject.com 有几个示例。 这是我使用过的一个。另外,我建议您查看 Google 图表。它会为你做这件事。

CodeProject.com has several samples. Here's one I've used. Also, I would recommend looking into the Google Charts. It will do this for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文