用 C# 制作图形饼图
我正在尝试编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您看一下 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.
这不是您问题的直接答案,但您为什么不使用 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
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.