Click here to Skip to main content
15,921,774 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Posted
Updated 10-Sep-18 1:10am
v2
Comments
Sandeep Mewara 25-Jan-11 0:15am    
Posting all in CAPS is considered shouting. I am sure you did not intend to do it. So, please avoid so from next time.
arunmj 25-Jan-11 0:17am    
ok ,,, fine,, im new to this..

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
 
Share this answer
 
Comments
JF2015 25-Jan-11 0:43am    
Good and very detailed answer.
arunmj 25-Jan-11 0:50am    
Thanks for the detailed explanation,,,,
Espen Harlinn 6-Feb-11 14:46pm    
Good answer :)
Sergey Alexandrovich Kryukov 6-Feb-11 18:18pm    
Thank you, Espen. It goes back to the many repeating questions on rendering vs. objects.
Would be good to have a single overview to reference to make an answer faster and more accurate...
--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.
 
Share this answer
 
v4
Comments
arunmj 25-Jan-11 0:24am    
thanks a lot buddy :)
Sergey Alexandrovich Kryukov 25-Jan-11 0:33am    
OP asked about options without 3rd-party. I depicted what's involved.
JF2015 25-Jan-11 0:37am    
MS Chart control is part of .NET since version 3.5. So this in deed is an original .NET control and no 3rd party!
arunmj 25-Jan-11 0:59am    
hi jf2015,,
can u explain a little more in this ??
do i have to download the Add-Ons from the mentioned website to get the controls ??...
arunmj 25-Jan-11 1:00am    
explain a little more on the procedure to be don plz ..?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900