2d绘制 c# dx,如何使用C#绘制2D线图?

Hi All,

I am new to C#.Net. I am trying to create a 2D line plot without the use of third party components.

Is there any option in C# to draw the graph and line plot using only .NET controls?

Thanks in advance,

Arun M

解决方案It depends on what UI library you want to use: System.Windows.Forms or WPF.

WPF is much more powerful and easier to use (when it comes to plotting, I don't say in general). There are many approaches. I thing you need to use canvas and put graphical objects on it. In this case, you don't have to care about rendering of graphics, you only support properties of your objects. Quality and performance are very good as it all based on ActiveX, all graphics is anti-aliased, with full support of transparency (alpha channel). You can automatically scale you graphic, fit it with preserved aspect ratio or otherwise, perform affine transformations and a lot more. One can develop plotting components using set of objects composed out of graphical primitives (such as Rectangle, Ellipse, Besier curve, Text, etc.).

In contrast to that, System.Windows.Forms needs rendering you can make in Control's event handler Paint (or overridden method OnPaint). You can create custom control or use Panel or a control derived from Panel. The event argument carries Graphics object used to call its drawing methods. This rendering functionality relies in Windows message WM_PAINT. As in native Windows GDI and GDI+ one needs to define rendering procedure called every time WM_PAINT is sent to a control. The event is not sent until control is invalidated. It's overloaded method Control.Invalidate comes in parameter-less variety used to invalidate a control as well as with a parameters used to invalidate some sub-set of the scene: Region or Rectangle. This way, modification of the graphics is done by modification of some data used in rendering followed by the call to Invalidate. In contrast to WPF, drawing primitives is always done in pixels, however pixel measurements are of the float type: due to (optional) anti-aliasing sub-pixel accuracy of the measurements of graphics primitives is used. This library also provides sufficient capabilities for development of plotting components. It requires more understanding of rendering mechanisms and generally provides lower performance compared to WPF.

Further questions are welcome.

Good luck,

--SA

See here for the MS-Chart control. This is a part of .NET (so no 3rd party) and does everything that you might need:

http://code.msdn.microsoft.com/mschart[^]

Edited:

The controls are part of the .NET framework 4.0 so there is no need to download them. You need to download the controls if using an earlier version of .NET (I think that works down to .NET 2.0). You then need to add a reference to the chart control to your C# project before you are able to use them. Have a look at the examples that are contained in the download or on the link I posted - they give quite a good start.

Edited 2:

See here for an overview of the namespace for the chart control:

http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.aspx[^]

Edited 3:

If you are using .NET 4.0 you don't need to redistribute the dll's to the target machine. If you are using a version < 4.0 you need to copy the dll's to the folder of your applications executable or register the dll's in the gac.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值