简体   繁体   English

在C#中制作图形饼图

[英]Making A Graphic Pie Chart In C#

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? 绘制馅饼的楔形最简单的方法是什么?

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. 如果您希望示例代码使用GDI实际绘制pieChart,则可以查看本教程。 . It uses FillPie Method of Graphics class. 它使用Graphics类的FillPie方法。

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)

CodeProject.com has several samples. CodeProject.com有几个示例。 Here's one I've used. 这是我用过的。 Also, I would recommend looking into the Google Charts . 另外,我建议您查看Google图表 It will do this for you. 它将为您做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM