Graph Plotting in C#

 

 

 

 

 

 

 

Plotting a graph from a set of test-related data is a common software-development task. In my experience, the most common approach is to import data into an Excel spreadsheet, then produce the graph manually using the Excel built-in graphing features. This works well in most situations, but if the underlying data changes frequently, creating graphs by hand can quickly become tedious.
You can automate the process using Windows Presentation Foundation (WPF) technology.

Preparing the Project for Graph Plotting 
Launch Visual Studio and create a new C# project using the WPF Application template. Although you can programmatically generate graphs using WPF primitives, I suggest using the convenient Dynamic Data Display (D3) library developed by a Microsoft Research lab.

You can download the library for free from the CodePlex open source hosting site at codeplex.com/dynamicdatadisplay. You should save a copy of this library in the root directory of your project, then add a reference to the DLL in your project by right-clicking on the project name, select the Add Reference option and point to the DLL file in your root directory.

Next you need to double-click on the file Window1.xaml to load the UI definitions for the project. You should add a reference to the graphic library DLL as follows:

xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
Title="Window1" Height="500" Width="800" Background="Wheat">


After that, you can add the key plotting object:

<d3:ChartPlotter Name="plotter" Margin="10,10,20,10">
  <d3:ChartPlotter.HorizontalAxis>
    <d3:HorizontalDateTimeAxis Name="dateAxis"/>
  </d3:ChartPlotter.HorizontalAxis>
  <d3:ChartPlotter.VerticalAxis>
    <d3:VerticalIntegerAxis Name="countAxis"/>
  </d3:ChartPlotter.VerticalAxis>
  <d3:Header FontFamily="Arial" Content="Bug Information"/>
  <d3:VerticalAxisTitle FontFamily="Arial" Content="Count"/>
  <d3:HorizontalAxisTitle FontFamily="Arial" Content="Date"/>
</d3:ChartPlotter>

The techniques that I presented here can be used to programmatically generate graphs. The key to the technique is the Dynamic Data Display (D3) library from Microsoft Research. This approach is very useful if the underlying data changes frequently.

The Model-View-ViewModel Design Pattern

The Model-View-ViewModel (MVVM) pattern helps you to cleanly separate the business and presentation logic of your application from its user interface (UI). Maintaining a clean separation between application logic and UI helps to address numerous development and design issues and can make your application much easier to test, maintain, and evolve. It can also greatly improve code re-use opportunities and allows developers and UI designers to more easily collaborate when developing their respective parts of the application.

Using the MVVM pattern, the UI of the application and the underlying presentation and business logic is separated into three separate classes:

1- The view, which encapsulates the UI and UI logic

2- The view model, which encapsulates presentation logic and state

3- The model, which encapsulates the application’s business logic and data

The MVVM pattern is a close variant of the Presentation Model pattern, optimized to leverage some of the core capabilities of WPF, such as data binding, data templates, commands, and behaviors. In the MVVM pattern, the view interacts with the view model through data binding, commands, and change notification events. The view model queries, observes, and coordinates updates to the model, converting, validating, and aggregating data as necessary for display in the view.

The following illustration shows the three MVVM classes and their interaction.

 

 

 

 

 

 

The View Class

The view’s responsibility is to define the structure and appearance of what the user sees on the screen. Ideally, the code-behind of a view contains only a constructor that calls the InitializeComponent method. The view usually has the following key characteristics:

– The view is a visual element, such as a window, page, user control, or data template.
– The view defines the controls contained in the view and their visual layout and styling.
– The view references the view model through its DataContext property.
– The controls are data bound to properties and commands exposed by the view model.
– The view may customize the data binding behavior between the view and the view model.
– The view defines and handles UI visual behavior, such as animations.
– The view’s code-behind may implement visual behavior that is difficult to express in XAML.

The View Model Class

The view model in the MVVM pattern encapsulates the presentation logic for the view. It has no direct reference to the view or any knowledge about the view’s specific implementation or type. The view model implements properties and commands to which the view can data bind and notifies the view of any state changes through change notification events. The properties and commands that the view model provides define the functionality to be offered by the UI, but the view determines how that functionality is to be rendered.

The view model is responsible for coordinating the view’s interaction with any model classes that are required. Typically, there is a one-to many-relationship between the view model and the model classes. The view model may choose to expose model classes directly to the view so that controls in the view can data bind directly to them. The view model may convert or manipulate model data so that it can be easily consumed by the view.

The view model may also define logical states the view can use to provide visual changes in the UI. The view may define layout or styling changes that reflect the state of the view model. For example, the view model may define a state that indicates that data is being submitted asynchronously to a web service. The view can display an animation during this state to provide visual feedback to the user.

Typically, the view model will define commands or actions that can be represented in the UI and that the user can invoke. A common example is when the view model provides a Submit command that allows the user submit data to a web service or to a data repository. The view may choose to represent that command with a button so that the user can click the button to submit the data. Typically, when the command becomes unavailable, its associated UI representation becomes disabled. The view model usually has the following key characteristics:

– The view model is a non-visual class. It encapsulates the presentation logic.
– The view model is testable independently of the view and the model.
– The view model typically does not directly reference the view.
– The view model implements properties and commands to which the view can data bind.
– The view model notifies the view of any state changes via change notification events:
INotifyPropertyChanged and INotifyCollectionChanged
– The view model coordinates the view’s interaction with the model.
– The view model may define logical states that the view can represent visually to the user.

The Model Class

The model in the MVVM pattern encapsulates business logic and data. Business logic is defined as any application logic that is concerned with the retrieval and management of application data and for making sure that any business rules that ensure data consistency and validity are imposed. To maximize re-use opportunities, models should not contain any use case–specific or user task–specific behavior or application logic.

Typically, the model represents the client-side domain model for the application. The model may also include the code to support data access and caching, though typically a separate data repository or service is employed for this. Often, the model and data access layer are generated as part of a data access or service strategy, such as the ADO.NET Entity Framework, WCF Data Services, or WCF RIA Services.

The model implements the facilities that make it easy to bind to the view. This usually means it supports property and collection changed notification through the INotifyPropertyChanged and INotifyCollectionChanged interfaces. Models classes that represent collections of objects typically derive from the ObservableCollection<T> class, which provides an implementation of the INotifyCollectionChanged interface.

The model may also support data validation and error reporting through the IDataErrorInfo (or INotifyDataErrorInfo) interfaces. These interfaces allow WPF data binding to be notified when values change so that the UI can be updated. The model usually has the following key characteristics:

– Model classes are non-visual classes that encapsulate the application’s data.
– The model classes do not directly reference the view or view model classes.
– The model classes have no dependency on how they are implemented.
– The model classes typically provide property and collection change events through:
INotifyPropertyChanged/INotifyCollectionChanged interfaces.
– The Model classes typically derive from the ObservableCollection<T> class.
– The model classes typically provide data validation and error reporting through:
IDataErrorInfo/INotifyDataErrorInfo.
– The model classes are typically used with a service that encapsulates data access.

ZAM 3D for WPF

 

 

 

 

 

 
 

 
What is ZAM 3D?

ZAM 3D is a 3D XAML Tool for Microsoft Windows .NET 3.5+ Application Development. It provides developers and designers with a quick and easy solution for creating 3D elements for Microsoft Expression Blend and Visual Studio projects. It also acts as a 3ds or dxf to XAML converter. Electric Rain ZAM 3D™ is a full-featured 3D modeling application that enables easy creation, customization and animation of 3D interface elements for Windows .NET 3.5+ based applications. Once a 3D scene is created, ZAM 3D automatically generates the XAML (eXtensible Application Markup Language) markup necessary to convert the 3D elements into a Windows Presentation Foundation “WPF” 3D scene. XAML files created with ZAM 3D can be directly integrated into your application development environment to create rich and engaging user experiences never before possible.

ZAM 3D Interface

The ZAM 3D interface is built to be highly approachable, yet very powerful. It supplies all of the basic modeling features such as primitives, materials, lighting, etc., as well as several 2D to 3D tools like the Extrusion Editor and a Lathe Editor. Furthermore, there is a very robust Advanced Modeling environment that allows full mesh manipulation. For more information on the ZAM 3D interface, please visit the Swift 3D portion of our Website as the functionality is very similar.

Chart FX for WPF

 

 

 

 

 

Chart FX for WPF makes the application experience more enjoyable and intuitive to the user. Chart FX 7 integrates seamlessly into Visual Studio 2010, 2008 and 2005, providing developers with unprecedented data visualization capabilities. Chart FX 7 takes full advantage of the .NET Framework and cutting-edge technologies such as AJAX to create visually-rich, lightweight and secure charts that will enhance your enterprise application’s display layer.

Features:

Chart FX for WPF’s cutting-edge features will unleash new ways of exploring and analyzing your enterprise data.

1-Stylish Visual Attributes
With it’s impressive chart types, animations, motifs, layouts, palettes, borders, markers and multiple axes, Chart FX for WPF allows you to create visually-appealing charts in minutes.
2-Full XAML Support
For the first time ever, both developers and designers will be able to fully “style” chart elements and tightly couple Chart FX for WPF to their application and user interface guidelines.
3-Powerful 3D Engine
Chart FX leverages WPF’s 3D engine to allow users to manipulate any of the chart’s elements and also provide a compelling UI to make analyzing data more intuitive.
4-Innovative User Interactivity
Users can select any of the chart elements they would like to manipulate and provide compelling user interfaces to make the process of analyzing data more powerful and intuitive.
5-Flexible Data Binding
Through the magic of WPF data binding, LINQ and Chart FX, you can easily populate a chart based on other controls, XML files, databases and other underlying data.
6-Seamless IDE Integration
Chart FX for WPF maintains programmability, developer productivity and IDE integration with both Visual Studio 2008 and Expression Blend.

WPF Useful Links

The Windows Presentation Foundation (WPF) is a graphical display system for Windows. WPF is designed for .NET, influenced by modern display technologies such as HTML and Flash, and hardware-accelerated. It is also the most radical change to hit Windows user interfaces since Windows 95. It allows you to build advanced user interfaces (UIs) that incorporate documents, media, two-dimensional (2D) and three-dimensional (3D) graphics, animations, and weblike characteristics.

In a pre-WPF world, developing a Windows application would have required the use of several different technologies. For instance, in order to add forms and user controls to your application, you needed to use the Windows Forms included in the .NET Framework. You had to use GDI+ to create images and 2D graphics. To add 3D graphics, you would have needed to use Direct3D or OpenGL.

WPF is designed to be a unified solution for application development, providing a seamless integration of different technologies. With WPF, you can create vector graphics or complex animations and incorporate media into your applications to address all of the areas just listed.

The following links are useful to learn the WPF programing model:

1-    WPF Official Website

http://windowsclient.net/wpf/

2-    Pete Brown’s Blog

http://10rem.net/blog

3-    Welcome to the Windows Presentation Foundation Resource Guide

http://www.wpfpedia.com/

More »

Windows Presentation Foundation

WPF or Windows Presentation Foundation is a new graphical display framework for Windows. This new system is designed to be used by .NET applications and allows the creation of dynamic, interactive graphical user interfaces. One of the most important features of WPF is the integration of DirectX. DirectX provides WPF with the ability to take advantage of the hardware acceleration on today’s graphics cards (GPUs). This allows the graphics load on the CPU to be greatly reduced, while at the same time, expanding the capabilities of the graphical display.

What WPF is and What XAML is

WPF provides a collection of controls such as buttons and grids, which are written in the Extensible Application Markup Language (XAML). XAML is an XML-based markup language created by Microsoft to separate the graphical and interactive elements of application from the main operations in the application, which are written in C# or Visual Basic. The beauty of WPF is how it is able to take advantage of the robustness of C# or Visual Basic, while at the same time using a simple XAML file to create the interface for the application.

The typical way that WPF creates and displays content goes like this:

1. XAML describes how the controls, images, video, and other assets are shown.
2. C# gives these assets their functionality.
3. The compiler then puts the XAML UI and functionality together into an executable (EXE) file for a Windows application or a XAML browser application (XBAP) executable for online applications.
4. The browser or Windows then displays the application.

Copyright © All Rights Reserved - C# Learners