WPF Data Charting
WPF Data Charting
Written by David Conrad   
Tuesday, 13 July 2010
Article Index
WPF Data Charting
Constructing a chart
A XAML approach

Scaling the axes

The resulting chart is fairly good but the default axes are scaled to just fit the data. A better presentation is obtained by specifying max and min values for both x and y:

NumericXAxis myXAxis = new NumericXAxis()
MaximumValue = 30,
MinimumValue = 0
NumericYAxis myYAxis = new NumericYAxis()
MaximumValue = 40,
MinimumValue = 0

With these changes the result is a very acceptable first attempt at a chart:




A XAML alternative

Of course you can achieve the same results by specifying the axes and series using nothing but XAML. All you have to do is write the XAML tags that create the same objects. The only complication is that as the data set is defined in code we have to set the DataContext in code as well - it is difficult to refer to object created in code within XAML. 

We start off with the opening XAML tag for the component itself:

<ig:XamDataChart HorizontalAlignment="Left" 
Height="218" Width="317" >

Next we need to define the axes within the Axes property of the control:

<ig:NumericXAxis Name="myXAxis"
<ig:NumericYAxis Name="myYAxis"

Finally we define the series and close the opening tag:

<ig:ScatterSeries  Name="scat"
XAxis="{Binding ElementName=myXAxis}"
YAxis="{Binding ElementName=myYAxis}">

Now all we have to do in code is set the DataContext and the Series ItemSource:

xamDataChart1.DataContext = data;
scat.ItemsSource = data;

The result is the same as the previous code-generated chart. Of course you can generate the data in XAML as well as the chart, but this isn't particularly realistic. Most data charting projects work best with some XAML and some code.

You can also create charts using Expression Blend. But the point is that now you understand the way data interacts with the DataChart component you can quickly graduate to the sort of impressive examples you can see on the Infragistics website, no matter what method you use.



Accessing Salesforce Data from Angular.js

In this tutorial we show you how to sign up for a Salseforce developer account and build a connected app that gets contacts from the user’s Force.com account and shows them using twitter bootstrap.

 [ ... ]

SNTP time class

SNTP is a network protocol for obtaining an accurate time and it is an interesting exercise to build an SNTP client. In this article the language used is C# but it is easy enough to generalise to a la [ ... ]

Other Projects





Last Updated ( Thursday, 19 August 2010 )

RSS feed of all content
I Programmer - full contents
Copyright © 2017 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.