简体   繁体   English

在 C# 中使用圆环图显示驱动器上的可用空间

[英]Displaying free space on a drive using doughnut chart in C#

I'm writing an application in C# .NET that requires me to display some information regarding a drive and it's capacity/free space.我正在 C# .NET 中编写一个应用程序,它要求我显示有关驱动器及其容量/可用空间的一些信息。 Instead of displaying the information just as text, I wanted to display it as a doughnut chart.我不想将信息显示为文本,而是将其显示为圆环图。 I've sort of got it working, however it does not display it like Windows does.我已经让它工作了,但是它不像 Windows 那样显示它。

My code display it like this:我的代码显示如下: 在此处输入图像描述

Windows displays it like this: Windows 显示如下:

在此处输入图像描述

My source code for this is:我的源代码是:

    private void ECSync_Load(object sender, EventArgs e)
    {
        DriveInfo Driveinformation = new DriveInfo("E");
        ShareDiskPieChart.Series["ShareDiskChart"].Points.AddXY(" ", Driveinformation.TotalSize);
        ShareDiskPieChart.Series["ShareDiskChart"].Points.AddXY(" ", Driveinformation.AvailableFreeSpace);
    }

If someone could tell me how to change the code to make it represent the capacity in a more realistic fashion, it would be greatly appreciated.如果有人能告诉我如何更改代码以使其以更真实的方式表示容量,将不胜感激。

Thanks to @TaW for the answer, here is the code:感谢@TaW 的回答,代码如下:

DriveInfo Driveinformation = new DriveInfo("E");
ShareDiskPieChart.Series[0].Points.Clear();
ShareDiskPieChart.Series["ShareDiskChart"].Points.AddXY(" ", Driveinformation.AvailableFreeSpace - Driveinformation.TotalSize);
ShareDiskPieChart.Series["ShareDiskChart"].Points.AddXY(" ", Driveinformation.AvailableFreeSpace);

And after formatting the E: drive it looks like this which is as expected:格式化 E: 驱动器后,它看起来像预期的那样:

在此处输入图像描述

And after writing some data I get this:在写了一些数据后,我得到了这个:

在此处输入图像描述

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

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