使用c#windows窗体在图表中显示大小 [英] display size in chart using c# windows form

查看:48
本文介绍了使用c#windows窗体在图表中显示大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建小代码来查找总空间C和可用空间

并将其显示在标签中



现在我尝试创建图像或图表显示这些值

我该怎么做?

I create small code to find total space C and free space
and display them in labels

now I try to create image or chart to display these values
how can I do that?

推荐答案

例如考虑Microsoft图表:http://msdn.microsoft.com/en-us/library/dd456632.aspx [ ^ ](适用于.NET v.4.0-4.5)。



对于v.3.5,请下载 http ://www.microsoft.com/en-us/download/details.aspx?id = 14422 [ ^ ]。



-SA
For example consider Microsoft Charts: http://msdn.microsoft.com/en-us/library/dd456632.aspx[^] (for .NET v.4.0-4.5).

For v.3.5, download http://www.microsoft.com/en-us/download/details.aspx?id=14422[^].

—SA


试试这个:



Try this:

public void DrawPieChartOnForm()
{
    //100% C volume, 60% free space on it
    int[] myPiePercent = { 40, 60 };
    Color[] myPieColors = { Color.Red, Color.Black };

    using (Graphics myPieGraphic = this.CreateGraphics())
    {
        //Give Location Which Will Display Chart At That Location.
        Point myPieLocation = new Point(10, 10);

        //Set Here Size Of The Chart…
        Size myPieSize = new Size(150, 150);

        //Call Function Which Will Draw Pie of Values.
        DrawPieChart(myPiePercent, myPieColors, myPieGraphic, myPieLocation, myPieSize);
    }
}


// Draws a pie chart.
public void DrawPieChart(int[] myPiePerecents, Color[] myPieColors, Graphics myPieGraphic, Point myPieLocation, Size myPieSize)
{
    int PiePercentTotal = 0;
    for (int PiePercents = 0; PiePercents < myPiePerecents.Length; PiePercents++)
    {
        using (SolidBrush brush = new SolidBrush(myPieColors[PiePercents]))
        {

            //Here it Will Convert Each Value Into 360, So Total Into 360 & Then It Will Draw A Full Pie Chart.
            myPieGraphic.FillPie(brush, new Rectangle(new Point(10, 10), myPieSize), Convert.ToSingle(PiePercentTotal * 360 / 100), Convert.ToSingle(myPiePerecents[PiePercents] * 360 / 100));
        }

        PiePercentTotal += myPiePerecents[PiePercents];
    }
    return;
}


这篇关于使用c#windows窗体在图表中显示大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆