Quantcast
Channel: WPF – C# Learners
Viewing all articles
Browse latest Browse all 12

Graph Plotting in C#

$
0
0

 

 

 

 

 

 

 

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.


Viewing all articles
Browse latest Browse all 12

Latest Images

Trending Articles





Latest Images