How To: Plot Graphs in WPF
How To: Plot Graphs in WPF
Join the DZone community and get the full member experience.Join For Free
Compliant Database DevOps and the role of DevSecOps DevOps is becoming the new normal in application development, and DevSecOps is now entering the picture. By balancing the desire to release code faster with the need for the same code to be secure, it addresses increasing demands for data privacy. But what about the database? How can databases be included in both DevOps and DevSecOps? What additional measures should be considered to achieve truly compliant database DevOps? This whitepaper provides a valuable insight. Get the whitepaper
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" 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: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>
Opinions expressed by DZone contributors are their own.