Over a million developers have joined DZone.

How To: Plot Graphs in WPF

· Database Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database. Try it now! Brought to you in partnership with MongoDB.

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:

Title="Window1" WindowState="Normal" 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:HorizontalDateTimeAxis Name="dateAxis"/>
    <d3:VerticalIntegerAxis Name="countAxis"/>

  <d3:Header FontFamily="Arial" Content="Bug Information"/>
  <d3:VerticalAxisTitle FontFamily="Arial" Content="Count"/>
  <d3:HorizontalAxisTitle FontFamily="Arial" Content="Date"/>

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.

dotnet,how-to,microsoft,tools,visual studio,data access,net,graphing

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}