在 C# 中制作图形饼图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1494252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:05:13  来源:igfitidea点击:

Making A Graphic Pie Chart In C#

c#graphicspie-chartslice

提问by Cistoran

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.

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

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?

我对你的问题是。绘制馅饼楔形的最简单方法是什么?

采纳答案by MRG

I will advise you to take a look at ZedGraph.

我会建议你看看ZedGraph

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

如果您想要使用 GDI 实际绘制饼图的示例代码,您可以查看本教程。. 它使用Graphics 类的FillPie方法。

回答by y0mbo

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

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

Scott Gu's post about it

Scott Gu 关于它的帖子

回答by David

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

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