C# 如何向我的 winforms 应用程序添加饼图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12250747/
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-09 22:37:29  来源:igfitidea点击:

How can I add a pie chart to my winforms application?

c#winformsvisual-studio-2010.net-4.0charts

提问by AdiB

I am trying to add a pie chart to my winforms application - but the only chart I can find in my toolbox is the regular bar chart.

我正在尝试向我的 winforms 应用程序添加饼图 - 但我在工具箱中唯一能找到的图表是常规条形图。

Is there any way to form this bar chart as a pie chart or add a pie-chart component to my toolbox by using some existing .net 4 framework libraries (without installing any new libraries such as "DevExpress" etc)?

有没有办法通过使用一些现有的 .net 4 框架库(不安装任何新库,如“DevExpress”等)来将此条形图形成为饼图或将饼图组件添加到我的工具箱中?

采纳答案by LukeHennerley

Without third party tools the only way around it would be for you to create a new user control in WPF for this following this tutorial:

如果没有第三方工具,唯一的解决方法是在 WPF 中为此教程创建一个新的用户控件:

http://www.codeproject.com/Articles/28098/A-WPF-Pie-Chart-with-Data-Binding-Support

http://www.codeproject.com/Articles/28098/A-WPF-Pie-Chart-with-Data-Binding-Support

And then hosting this within the windows form project, following this tutorial:

然后按照本教程在 windows 窗体项目中托管它:

http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms

http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms

That way you have created the control yourself without the need of downloading anything, although you may need to context switch to use the WPF tutorial - I hope this is ok :)

这样你就可以自己创建控件而无需下载任何东西,尽管你可能需要上下文切换才能使用 WPF 教程 - 我希望这没问题:)

回答by Delta

In .NET 4 and later I think you have MS Chart in the framework. Read more here: http://code.msdn.microsoft.com/Samples-Environments-for-b01e9c61

在 .NET 4 及更高版本中,我认为您的框架中有 MS Chart。在此处阅读更多信息:http: //code.msdn.microsoft.com/Samples-Environments-for-b01e9c61

回答by Praveenkumar Selvaraj

You can change the chart type by selecting the series in property window or use the following sample code

您可以通过在属性窗口中选择系列或使用以下示例代码来更改图表类型

 chart1.Series["Business"].ChartType =   
       System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;

回答by orrin jones

well actually visual studio does have a pie chart. after dragging out the bar chart. go to your properties panel then under chart click series. a dialog box will appear after which you will select chart type. there is a whole list of different chart types to choose from

事实上,visual studio 确实有一个饼图。拖出条形图后。转到您的属性面板,然后在图表下单击系列。将出现一个对话框,然后您将选择图表类型。有一整套不同的图表类型可供选择