<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Colin Eberhardt&#039;s Adventures in .NET &#187; charts</title>
	<atom:link href="http://www.scottlogic.co.uk/blog/colin/tag/charts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scottlogic.co.uk/blog/colin</link>
	<description>Colin Eberhardt&#039;s Adventures in .NET</description>
	<lastBuildDate>Thu, 09 Feb 2012 10:21:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Adding Error Bars to Visiblox Silverlight Charts</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2011/10/adding-error-bars-to-visiblox-silverlight-charts/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2011/10/adding-error-bars-to-visiblox-silverlight-charts/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 15:11:17 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[codeproject]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[databinding]]></category>
		<category><![CDATA[visiblox]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1766</guid>
		<description><![CDATA[Having spent a number of years studying Physics at university, I have had the importance of error bars well and truly drummed into me! Within physics, or any experimental science, there are always going to be errors in the measurements you make. The more repeat measurements you make, the more confident you can be in [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2011%252F10%252Fadding-error-bars-to-visiblox-silverlight-charts%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Adding%20Error%20Bars%20to%20Visiblox%20Silverlight%20Charts%20%23%22%20%7D);"></div>
<p>Having spent a number of years studying Physics at university, I have had the importance of error bars well and truly drummed into me! Within physics, or any experimental science, there are always going to be errors in the measurements you make. The more repeat measurements you make, the more confident you can be in the mean value, however you cannot remove the errors altogether. Error bars provide a way to represent the spread of experimental observations graphically, without them, it is hard to have any confidence in the conclusions drawn from the observations!</p>
<p>In this blog post I will show how to implement a custom <a href="http://www.visiblox.com/">Visiblox</a> chart series to render error bars:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/10/VisibloxErrorBars.png" alt="" title="VisibloxErrorBars" width="499" height="240" class="aligncenter size-full wp-image-1767" /></p>
<p>(The data in the above chart is from a page which details how to calculate the <a href="http://www.ncsu.edu/labwrite/res/gt/gt-stat-home.html">standard error from experimental results</a>).</p>
<h2>Creating a Custom Series</h2>
<p>As described in my previous blog post on <a href="http://www.scottlogic.co.uk/blog/colin/2010/11/adding-a-smoothed-line-series-bezier-curve-to-a-visiblox-chart/" title="Adding a Smoothed Line Series (Bézier curve) to a Visiblox Chart">creating a spline series</a>, to create a new series type, you sub-class one of the Visiblox base-classes, in this case <code>MultiValueSeriesBase </code>is a suitable starting point:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ErrorBarSeries <span style="color: #008000;">:</span> MultiValueSeriesBase
<span style="color: #008000;">&#123;</span> 
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> FrameworkElement CreatePoint<span style="color: #008000;">&#40;</span>IDataPoint dataPoint<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderDataLabels<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>I don&#8217;t want data labels, so the only method I need to implement is <code>CreatePoint</code>, which takes the (multi-valued) point to be rendered as its only argument. The lifecycle of point creating and destruction is taken care of by the base-class.</p>
<p>The <code>IDataPoint </code>has a string indexer which is used to retrieve multiple Y values for multi-valued series. It is a good idea to define these in a single place, here we define the three y-values required for an error-bar series:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> ErrorUp <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ErrorUp&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> ErrorDown <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ErrorDown&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> <span style="color: #6666cc; font-weight: bold;">string</span> Value <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Value&quot;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <code>CreatePoint</code> implementation for this series creates a Path as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> FrameworkElement CreatePoint<span style="color: #008000;">&#40;</span>IDataPoint dataPoint<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var lineGeometry <span style="color: #008000;">=</span> BuildGeometry<span style="color: #008000;">&#40;</span>dataPoint<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  Path line <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Path<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">Stroke</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">Fill</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Gray</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">StrokeThickness</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">1.0</span><span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">StrokeLineJoin</span> <span style="color: #008000;">=</span> PenLineJoin<span style="color: #008000;">.</span><span style="color: #0000FF;">Bevel</span><span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> lineGeometry<span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>ZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">IsScaledPathProperty</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">return</span> line<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The <code>BuildGeometry</code> method does most of the work, extracting the values from the IDataPoint, transforming them (via the axis) to the required coordinate system, then creating a suitable geometry:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Creates the geometry for the given datapoint</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> PathGeometry BuildGeometry<span style="color: #008000;">&#40;</span>IDataPoint dataPoint<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var halfWidth <span style="color: #008000;">=</span> SuggestedPointWidth <span style="color: #008000;">*</span> WidthFactor<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// obtain the data values</span>
  var topDataValue <span style="color: #008000;">=</span> dataPoint<span style="color: #008000;">&#91;</span>ErrorUp<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> IComparable<span style="color: #008000;">;</span>
  var middleDataValue <span style="color: #008000;">=</span> dataPoint<span style="color: #008000;">&#91;</span>Value<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> IComparable<span style="color: #008000;">;</span>
  var bottomDataValue <span style="color: #008000;">=</span> dataPoint<span style="color: #008000;">&#91;</span>ErrorDown<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> IComparable<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// convert to a the required render coordinates</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> topRenderPos <span style="color: #008000;">=</span> YAxis<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataValueAsRenderPositionWithoutZoom</span><span style="color: #008000;">&#40;</span>topDataValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> middleRenderPos <span style="color: #008000;">=</span> YAxis<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataValueAsRenderPositionWithoutZoom</span><span style="color: #008000;">&#40;</span>middleDataValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> bottomRenderPos <span style="color: #008000;">=</span> YAxis<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataValueAsRenderPositionWithoutZoom</span><span style="color: #008000;">&#40;</span>bottomDataValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #6666cc; font-weight: bold;">double</span> xMiddleRenderPos <span style="color: #008000;">=</span> XAxis<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataValueAsRenderPositionWithoutZoom</span><span style="color: #008000;">&#40;</span>dataPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> xRightRenderPos <span style="color: #008000;">=</span> xMiddleRenderPos <span style="color: #008000;">-</span> halfWidth<span style="color: #008000;">;</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> xLeftRenderPos <span style="color: #008000;">=</span> xMiddleRenderPos <span style="color: #008000;">+</span> halfWidth<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// build a suitable gemoetry</span>
  PathGeometry lineGeometry <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathGeometry<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  PathFigure upperVerticalLine <span style="color: #008000;">=</span> CreateLineFigure<span style="color: #008000;">&#40;</span>
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos, middleRenderPos <span style="color: #008000;">-</span> halfWidth<span style="color: #008000;">&#41;</span>,
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos, topRenderPos<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  lineGeometry<span style="color: #008000;">.</span><span style="color: #0000FF;">Figures</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>upperVerticalLine<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  PathFigure lowerVerticalLine <span style="color: #008000;">=</span> CreateLineFigure<span style="color: #008000;">&#40;</span>
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos, bottomRenderPos<span style="color: #008000;">&#41;</span>,
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos, middleRenderPos <span style="color: #008000;">+</span> halfWidth<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  lineGeometry<span style="color: #008000;">.</span><span style="color: #0000FF;">Figures</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>lowerVerticalLine<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  PathFigure upperBar <span style="color: #008000;">=</span> CreateLineFigure<span style="color: #008000;">&#40;</span>
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xLeftRenderPos, topRenderPos<span style="color: #008000;">&#41;</span>,
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xRightRenderPos, topRenderPos<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  lineGeometry<span style="color: #008000;">.</span><span style="color: #0000FF;">Figures</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>upperBar<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  PathFigure lowerBar <span style="color: #008000;">=</span> CreateLineFigure<span style="color: #008000;">&#40;</span>
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xLeftRenderPos, bottomRenderPos<span style="color: #008000;">&#41;</span>,
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xRightRenderPos, bottomRenderPos<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  lineGeometry<span style="color: #008000;">.</span><span style="color: #0000FF;">Figures</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>lowerBar<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  PathFigure center <span style="color: #008000;">=</span> CreateLineFigure<span style="color: #008000;">&#40;</span>
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos <span style="color: #008000;">-</span> halfWidth, middleRenderPos<span style="color: #008000;">&#41;</span>,
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos, middleRenderPos <span style="color: #008000;">+</span> halfWidth<span style="color: #008000;">&#41;</span>,
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos <span style="color: #008000;">+</span> halfWidth, middleRenderPos<span style="color: #008000;">&#41;</span>,
    <span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xMiddleRenderPos, middleRenderPos <span style="color: #008000;">-</span> halfWidth<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  lineGeometry<span style="color: #008000;">.</span><span style="color: #0000FF;">Figures</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>center<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">return</span> lineGeometry<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Create a line figure that connects the given points</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> PathFigure CreateLineFigure<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">params</span> Point<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> points<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// add all the points (except the first)</span>
  var pointCollection <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PointCollection<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var point <span style="color: #0600FF; font-weight: bold;">in</span> points<span style="color: #008000;">.</span><span style="color: #0000FF;">Skip</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    pointCollection<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>point<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create a figure, using the first point as the StartPoint.</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> PathFigure<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    IsClosed <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span>,
    StartPoint <span style="color: #008000;">=</span> points<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,
    Segments <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathSegmentCollection<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008000;">new</span> PolyLineSegment
      <span style="color: #008000;">&#123;</span>
        Points <span style="color: #008000;">=</span> pointCollection
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>We can now create an instance of this series in XAML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vis:Chart</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chart&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vis:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:ErrorBarSeries</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vis:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vis:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Supplying data to the chart via <code>MultiValuedDataPoint</code> as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> MainPage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  var data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataSeries<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreatePoint<span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">195</span>, <span style="color: #FF0000;">1.4</span>, <span style="color: #FF0000;">0.2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreatePoint<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">62.2</span>, <span style="color: #FF0000;">9.3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreatePoint<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20</span>, <span style="color: #FF0000;">70.4</span>, <span style="color: #FF0000;">6.5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreatePoint<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">77.4</span>, <span style="color: #FF0000;">1.9</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> MultiValuedDataPoint<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span> CreatePoint<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> x, <span style="color: #6666cc; font-weight: bold;">double</span> y, <span style="color: #6666cc; font-weight: bold;">double</span> error<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var point <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MultiValuedDataPoint<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>x,
    <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">object</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      <span style="color: #008000;">&#123;</span> ErrorBarSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorUp</span>, y <span style="color: #008000;">+</span> error <span style="color: #008000;">&#125;</span>,
      <span style="color: #008000;">&#123;</span> ErrorBarSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">ErrorDown</span>, y <span style="color: #008000;">-</span> error <span style="color: #008000;">&#125;</span>,
      <span style="color: #008000;">&#123;</span> ErrorBarSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>, y <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> point<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This results in the following chart:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/10/VisibloxErrorBars2.png" alt="" title="VisibloxErrorBars2" width="476" height="293" class="aligncenter size-full wp-image-1772" /></p>
<h2>Binding to a Multi-valued Series</h2>
<p>In the previous example we created instances of <code>MultiValuedDataPoint</code>, a Visiblox type for representing multi-valued points. As an alternative, we can create model objects to represent each point, rendering them in the chart via databinding.</p>
<p>We first modify the code to create a collection of <code>Measurement</code> instances (a simple model object that implements <code>INotifyPropertyChanged</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> MainPage<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  var data <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ObservableCollection<span style="color: #008000;">&lt;</span>Measurement<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreateMeasurement<span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">195</span>, <span style="color: #FF0000;">1.4</span>, <span style="color: #FF0000;">0.2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreateMeasurement<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">62.2</span>, <span style="color: #FF0000;">9.3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreateMeasurement<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20</span>, <span style="color: #FF0000;">70.4</span>, <span style="color: #FF0000;">6.5</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>CreateMeasurement<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">100</span>, <span style="color: #FF0000;">77.4</span>, <span style="color: #FF0000;">1.9</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataContext</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">;</span>    
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> Measurement CreateMeasurement<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> x, <span style="color: #6666cc; font-weight: bold;">double</span> y, <span style="color: #6666cc; font-weight: bold;">double</span> error<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> Measurement<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      XValue <span style="color: #008000;">=</span> x,
      YValue <span style="color: #008000;">=</span> y,
      YValueErrorUp <span style="color: #008000;">=</span> y <span style="color: #008000;">+</span> error,
      YValueErrorDown <span style="color: #008000;">=</span> y <span style="color: #008000;">-</span> error
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The markup for the chart is modified to use a <code>BindableDataSeries</code>, with bindings specified for the various component of the error bar series. Also, the <code>ItemsSource </code>of the <code>BindableDataSeries</code> is bound to the inherited <code>DataContext</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>local<span style="color: #008000;">:</span>ErrorBarSeries<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>local<span style="color: #008000;">:</span>ErrorBarSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>vis<span style="color: #008000;">:</span>BindableDataSeries ItemsSource<span style="color: #008000;">=</span><span style="color: #666666;">&quot;{Binding}&quot;</span>
                            XValueBinding<span style="color: #008000;">=</span><span style="color: #666666;">&quot;{Binding XValue}&quot;</span><span style="color: #008000;">&gt;</span>
      <span style="color: #008000;">&lt;</span>vis<span style="color: #008000;">:</span>BindableDataSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">YValueBindings</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>vis<span style="color: #008000;">:</span>YValueBinding YValueKey<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Value&quot;</span> Binding<span style="color: #008000;">=</span><span style="color: #666666;">&quot;{Binding YValue}&quot;</span><span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;</span>vis<span style="color: #008000;">:</span>YValueBinding YValueKey<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ErrorUp&quot;</span> Binding<span style="color: #008000;">=</span><span style="color: #666666;">&quot;{Binding YValueErrorUp}&quot;</span><span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;</span>vis<span style="color: #008000;">:</span>YValueBinding YValueKey<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ErrorDown&quot;</span>  Binding<span style="color: #008000;">=</span><span style="color: #666666;">&quot;{Binding YValueErrorDown}&quot;</span><span style="color: #008000;">/&gt;</span>
      <span style="color: #008000;">&lt;/</span>vis<span style="color: #008000;">:</span>BindableDataSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">YValueBindings</span><span style="color: #008000;">&gt;</span>              
    <span style="color: #008000;">&lt;/</span>vis<span style="color: #008000;">:</span>BindableDataSeries<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;/</span>local<span style="color: #008000;">:</span>ErrorBarSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>local<span style="color: #008000;">:</span>ErrorBarSeries<span style="color: #008000;">&gt;</span></pre></div></div>

<p>We can also display our data in a DataGrid, allowing us to manipulate the values (not that I condone manipulation of scientific data!), with the changes being reflected in the chart:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk:DataGrid</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;grid&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>This gives us the following application:</p>
<div style="text-align: center;"><object width="500" height="400" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/10/VisibloxErrorBarSeries.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<p>You can edit the values, with the changes reflected immediately in the chart above.</p>
<p>You can download the sourcecode for the above example here:  <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2011/10/VisibloxErrorBarSeries.zip'>VisibloxErrorBarSeries.zip</a></p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2011/10/adding-error-bars-to-visiblox-silverlight-charts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>#uksnow #silverlight The Movie! &#8211; Happy Christmas.</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2010/12/uksnow-silverlight-the-movie-happy-christmas/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2010/12/uksnow-silverlight-the-movie-happy-christmas/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 14:42:07 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[uksnow]]></category>
		<category><![CDATA[visiblox]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=1061</guid>
		<description><![CDATA[It&#8217;s Christmas Eve and time for some fun! A few weeks back I published an article on Reactive Extensions where I created a Bing Maps / Twitter mashup that plotted the geolocation of #uksnow twitter tags. This twitter hashtag was popularised by Ben Marsh and is used by us weather obsessed brits to give a [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2010%252F12%252Fuksnow-silverlight-the-movie-happy-christmas%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22%23uksnow%20%23silverlight%20The%20Movie%21%20-%20Happy%20Christmas.%20%23%22%20%7D);"></div>
<p>It&#8217;s Christmas Eve and time for some fun! A few weeks back <a href="http://www.scottlogic.co.uk/blog/colin/2010/11/uksnow-silverlight-an-rx-powered-twitter-bing-maps-mashup/">I published an article on Reactive Extensions</a> where I created a Bing Maps / Twitter mashup that plotted the geolocation of #uksnow twitter tags. This twitter hashtag was popularised by <a href="http://uksnowmap.com/">Ben Marsh</a> and is used by us weather obsessed brits to give a realtime update of snowfall. To use this hashtag tweet #uksnow with your postcode and the amount of snowfall out of ten (e.g. 7/10).</p>
<p>The snow has continued to fall in record quantities across the uk, so I thought it might be fun to create &#8220;#uksnow The Movie&#8221;, where you can replay the snowfall across the UK. You can see the finished app below. Hit the &#8216;play&#8217; button, or drag the time indicator on the chart to replay the snowfall and re-live the fun! You can also mouse-over the snowflakes to see the original #uksnow tweet.</p>
<div style="text-align: center;margin: 0 0 40px 0 "><object width="500" height="600" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/UKSnowTheMovie1.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<p>To create this application I modified my original app to extract as many #uksnow tweets from twitter as possible. Unfortunately the public search API only server tweets from the last ~ 7 days. If anyone knows of a free historic service, please let me know!</p>
<p>The application above contains an XML file with all the historic tweets. When it starts up, it parses the XML file.The chart displays the tweets &#8216;binned&#8217; in 30 minute intervals, which is achieved via a simple <code>GroupBy</code> query:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// parse the XML file</span>
_tweets <span style="color: #008000;">=</span> doc<span style="color: #008000;">.</span><span style="color: #0000FF;">Descendants</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;tweet&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>el <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">new</span> GeoCodedUKSnowTweet<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                                  <span style="color: #008000;">&#123;</span>
                                    Author <span style="color: #008000;">=</span> el<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;author&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>,
                                    Title <span style="color: #008000;">=</span> el<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;title&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>,
                                    ProfileImageUrl <span style="color: #008000;">=</span> el<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;profile&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span>,
                                    Location <span style="color: #008000;">=</span> StringToPoint<span style="color: #008000;">&#40;</span>el<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;loc&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span>,
                                    SnowFactor <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>el<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;snowfactor&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span>,
                                    Timestamp <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>el<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;timestamp&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span>
                                  <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span>
                                  <span style="color: #008000;">.</span><span style="color: #0000FF;">OrderBy</span><span style="color: #008000;">&#40;</span>t <span style="color: #008000;">=&gt;</span> t<span style="color: #008000;">.</span><span style="color: #0000FF;">Timestamp</span><span style="color: #008000;">&#41;</span>                                        
                                  <span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// total the tweets per 30 minute interval</span>
var groupedByHour <span style="color: #008000;">=</span> _tweets<span style="color: #008000;">.</span><span style="color: #0000FF;">GroupBy</span><span style="color: #008000;">&#40;</span>t <span style="color: #008000;">=&gt;</span> RoundDateToMinutes<span style="color: #008000;">&#40;</span>t<span style="color: #008000;">.</span><span style="color: #0000FF;">Timestamp</span>, <span style="color: #FF0000;">30</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                          <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>group <span style="color: #008000;">=&gt;</span> 
                            <span style="color: #008000;">new</span> TweetsPerHour<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
                              Hour <span style="color: #008000;">=</span> group<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>,
                              Tweets <span style="color: #008000;">=</span> group<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
                            <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// associate the above with the chart</span>
chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">YAxis</span> <span style="color: #008000;">=</span> chart<span style="color: #008000;">.</span><span style="color: #0000FF;">SecondaryYAxis</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>BindableDataSeries<span style="color: #008000;">&#41;</span>chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> groupedByHour<span style="color: #008000;">;</span></pre></div></div>

<p>I used the <a href="http://www.visiblox.com/">free Visiblox chart</a> to display the tweet frequency. A <code>LineSeries</code> with a <code>BindableDataSeries</code> is used to render the results of the query above using databinding.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vis:LineSeries.DataSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vis:BindableDataSeries</span></span>
<span style="color: #009900;">         <span style="color: #000066;">XValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Path=Hour}&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">YValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Path=Tweets}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vis:LineSeries.DataSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The Visiblox chart has a pluggable behaviour concept which allows you to add interactivity to the chart. The vertical line that indicates the current time uses this behaviour framework. When the user interacts with the chart via mouse movements, these interactions are directed to any active behaviours, which can then update their state, possibly interacting with the chart or its axes. For example, when the code which updates the date as the user drags the line is shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> MouseLeftButtonDown<span style="color: #008000;">&#40;</span>Point position<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MouseLeftButtonDown</span><span style="color: #008000;">&#40;</span>position<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _mouseDown <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> MouseLeftButtonUp<span style="color: #008000;">&#40;</span>Point position<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MouseLeftButtonUp</span><span style="color: #008000;">&#40;</span>position<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _mouseDown <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> MouseMove<span style="color: #008000;">&#40;</span>Point position<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>_mouseDown<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    CurrentDate <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">&#41;</span>Chart<span style="color: #008000;">.</span><span style="color: #0000FF;">XAxis</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetRenderPositionAsDataValueWithZoom</span><span style="color: #008000;">&#40;</span>position<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>For the sake of simplicity, the calendar and clock controls are implemented as UserControls, for example the calendar has the following markup:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">CornerRadius</span>=<span style="color: #ff0000;">&quot;8&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;White&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border.Effect<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DropShadowEffect</span> <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;LightGray&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">Opacity</span>=<span style="color: #ff0000;">&quot;0.8&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">ShadowDepth</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border.Effect<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid.RowDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;15&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RowDefinition</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid.RowDefinitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">CornerRadius</span>=<span style="color: #ff0000;">&quot;8,8,0,0&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border.Background<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearGradientBrush</span> <span style="color: #000066;">StartPoint</span>=<span style="color: #ff0000;">&quot;0,0&quot;</span></span>
<span style="color: #009900;">                                <span style="color: #000066;">EndPoint</span>=<span style="color: #ff0000;">&quot;0,1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;GradientStop</span> <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;White&quot;</span> <span style="color: #000066;">Offset</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;GradientStop</span> <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;Red&quot;</span> <span style="color: #000066;">Offset</span>=<span style="color: #ff0000;">&quot;0.9&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;GradientStop</span> <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;DarkRed&quot;</span> <span style="color: #000066;">Offset</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearGradientBrush<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border.Background<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Friday&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;DayOfWeek&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">FontWeight</span>=<span style="color: #ff0000;">&quot;Bold&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;8&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;28&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;Day&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">FontWeight</span>=<span style="color: #ff0000;">&quot;Bold&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;20&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">HorizontalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">VerticalAlignment</span>=<span style="color: #ff0000;">&quot;Center&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>    
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And the following minimal code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> CalendarControl <span style="color: #008000;">:</span> UserControl
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> CalendarControl<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> SetDate<span style="color: #008000;">&#40;</span>DateTime date<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    DayOfWeek<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> date<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ddd&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Day<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> date<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;dd&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The clock control is very similar, using a few concepts that I wrote abut in my <a href="http://www.scottlogic.co.uk/blog/colin/2010/08/developing-a-very-lookless-silverlight-radial-gauge-control/">gauge control blog post</a> a few weeks back. It is good to see that Silverlight allows quick and direct implementations of controls, you do not always have to use MVVM, lookless controls and dependency properties. If it is Christmas Eve, and you are itching to get home and grab a drink, anything goes <img src='http://www.scottlogic.co.uk/blog/colin/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>You can download the full sourcecode here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/UKSnowTheMovie.zip'>UKSnowTheMovie.zip</a></p>
<p>Right &#8230; I&#8217;m off home.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2010/12/uksnow-silverlight-the-movie-happy-christmas/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Visiblox, Visifire, DynamicDataDisplay &#8211; Charting Performance Comparison</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2010/12/visiblox-visifire-dynamicdatadisplay-charting-performance-comparison/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2010/12/visiblox-visifire-dynamicdatadisplay-charting-performance-comparison/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 12:00:57 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[D3]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[toolkit]]></category>
		<category><![CDATA[visiblox]]></category>
		<category><![CDATA[visifire]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=979</guid>
		<description><![CDATA[A few weeks ago I published a blog post which compared the performance of the Visiblox charts and the Silverlight Toolkit charts. The results indicated that the Visblox charts are considerably faster than the Toolkit charts, however Microsoft&#8217;s David Anson did point out that the Toolkit charts were not designed with performance in mind, and [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2010%252F12%252Fvisiblox-visifire-dynamicdatadisplay-charting-performance-comparison%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Visiblox%2C%20Visifire%2C%20DynamicDataDisplay%20-%20Charting%20Performance%20Comparison%20%23%22%20%7D);"></div>
<p>A few weeks ago I <a href="http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/">published a blog post</a> which compared the performance of the <a href="http://www.visiblox.com/">Visiblox</a> charts and the <a href="http://silverlight.codeplex.com/">Silverlight Toolkit</a> charts. The results indicated that the Visblox charts are considerably faster than the Toolkit charts, however Microsoft&#8217;s David Anson did point out that the Toolkit charts were not designed <a href="http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/#comment-25026">with performance in mind</a>, and that a comparison would be more fair if the &#8216;FastLineSeries&#8217; series that has been on the TODO list for a while were implemented.</p>
<p>I have been asked by a few people to extend the performance test to include a few other Silverlight charts to see how they compare. I have refactored the test code so that different charts can be plugged in more easily. This not only makes it easier to test the performance of other charting components, but has also allowed me to compare the different charting APIs more easily. </p>
<p>This blog post compares the performance of <a href="http://www.visiblox.com/">Visiblox</a>, <a href="http://www.visifire.com/">Visifire</a>, <a href="http://silverlight.codeplex.com/">Silverlight Toolkit</a> and <a href="http://dynamicdatadisplay.codeplex.com/">Dynamic Data Display</a> (D<sub>3</sub>) charts. I also compared a few other charting components, however the terms of their trial license prohibit me from publishing the results.</p>
<p>A summary of the performance measurement is given below, where each chart is used to plot rapidly changing data, with the framerate being used as a measure of performance.</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/performance.png" alt="" title="performance" width="520" height="313" class="aligncenter size-full wp-image-1026" /></p>
<p>The test clients running with each of the different charts are shown below:</p>
<table>
<tr>
<th style="text-align: center; ">
Visiblox Chart
</th>
<th style="text-align: center; ">
Visifire Chart
</th>
</tr>
<tr>
<td>
<div style="text-align: center;margin: 0 0 40px 0 "><object width="300" height="430" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/HistogramVisiblox.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
</td>
<td>
<div style="text-align: center;margin: 0 0 40px 0 "><object width="300" height="430" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/HistogramVisifire.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
</td>
</tr>
<tr>
<th style="text-align: center; ">
Silverlight Toolkit Chart
</th>
<th style="text-align: center; ">
D<sub>3</sub> Chart
</th>
</tr>
<tr>
<td>
<div style="text-align: center; margin: 0 0 20px 0 "><object width="300" height="430" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/HistogramToolkit.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
</td>
<td>
<div style="text-align: center; margin: 0 0 20px 0 "><object width="300" height="430" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/HistogramDDD.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
</td>
</tr>
</table>
<p><small>[cheetah image courtesy of <a href="http://www.flickr.com/photos/38485387@N02/3580728177/sizes/m/in/photostream/">flickrfavorites</a>, snail image courtesy of <a href="http://www.flickr.com/photos/powi/749366522/sizes/m/in/photostream/">Per Ola Wiberg</a>, tortoise image courtesy of <a href="http://www.flickr.com/photos/wwarby/4011400171/sizes/m/in/photostream/">wwarby</a>, horse image courtesy of <a href="http://www.flickr.com/photos/greendalen/1428399622/sizes/m/in/photostream/">Linnéa Gröndalen</a>]</small></p>
<p>We&#8217;ll look at the XAML markup for each chart and the code-behind used to add data to each chart in the following sections:</p>
<h2>Visiblox</h2>
<p>The XAML markup for the Visiblox charts is reasonably concise, with the X &#038; Y axes configured and styled and the three LineSeries added to the chart:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UserControl.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;Line&quot;</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;GridLineStyle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Stroke&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;#dddddd&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;StrokeThickness&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/UserControl.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;White&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chart&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">LegendVisibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5,0,5,5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart.XAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #808080; font-style: italic;">&lt;!-- a 'hidden' X axis --&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LinearAxis</span> <span style="color: #000066;">ShowAxis</span>=<span style="color: #ff0000;">&quot;False&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">GridlineStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource GridLineStyle}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart.XAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart.YAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #808080; font-style: italic;">&lt;!-- A Y axis with labels within the chart area --&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LinearAxis</span> <span style="color: #000066;">ShowLabels</span>=<span style="color: #ff0000;">&quot;True&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">LabelsPosition</span>=<span style="color: #ff0000;">&quot;Inside&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">GridlineStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource GridLineStyle}&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">ShowMajorTicks</span>=<span style="color: #ff0000;">&quot;False&quot;</span></span>
<span style="color: #009900;">                            <span style="color: #000066;">ShowMinorTicks</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart.YAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #808080; font-style: italic;">&lt;!-- the series used to render the RGB components --&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LineSeries</span> <span style="color: #000066;">LineStroke</span>=<span style="color: #ff0000;">&quot;#A00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LineSeries</span> <span style="color: #000066;">LineStroke</span>=<span style="color: #ff0000;">&quot;#0A0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LineSeries</span> <span style="color: #000066;">LineStroke</span>=<span style="color: #ff0000;">&quot;#00A&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The code-behind is also reasonably concise with the list of <code>DataPoint</code> objects returned by the test-harness converted into Visiblox <code>DataSeries</code> via a Linq <code>Select</code> projection.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderDataToChart<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span>Histogram<span style="color: #008000;">.</span><span style="color: #0000FF;">DataPoint</span><span style="color: #008000;">&gt;&gt;</span> rgbData<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  _chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span> <span style="color: #008000;">=</span> ListToSeries<span style="color: #008000;">&#40;</span>rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span> <span style="color: #008000;">=</span> ListToSeries<span style="color: #008000;">&#40;</span>rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span> <span style="color: #008000;">=</span> ListToSeries<span style="color: #008000;">&#40;</span>rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> DataSeries<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span> ListToSeries<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>Histogram<span style="color: #008000;">.</span><span style="color: #0000FF;">DataPoint</span><span style="color: #008000;">&gt;</span> data<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> DataSeries<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>data<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>pt <span style="color: #008000;">=&gt;</span> 
    <span style="color: #008000;">new</span> DataPoint<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>pt<span style="color: #008000;">.</span><span style="color: #0000FF;">Location</span>, pt<span style="color: #008000;">.</span><span style="color: #0000FF;">Intensity</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Visifire</h2>
<p>Visifire also has a reasonably concise XAML markup, however in order to provide maximum performance, there are a number of chart features that need to be disabled. The Visifire charts have a Line series which could be used for this comparison, however they recently released a <a href="http://www.visifire.com/documentation/Visifire_Documentation/Chart_Types/QuickLine_Chart.htm">QuickLine</a> series type which removes certain features to provide better performance.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;White&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Chart</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chart&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">AnimationEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">ScrollingEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Chart.Legends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Legend</span> <span style="color: #000066;">Enabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vc:Chart.Legends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- the series used to render the RGB components --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:DataSeries</span> <span style="color: #000066;">RenderAs</span>=<span style="color: #ff0000;">&quot;QuickLine&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;#A00&quot;</span> <span style="color: #000066;">LineThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">MarkerEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000066;">ShadowEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:DataSeries</span> <span style="color: #000066;">RenderAs</span>=<span style="color: #ff0000;">&quot;QuickLine&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;#0A0&quot;</span> <span style="color: #000066;">LineThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">MarkerEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000066;">ShadowEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:DataSeries</span> <span style="color: #000066;">RenderAs</span>=<span style="color: #ff0000;">&quot;QuickLine&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">Color</span>=<span style="color: #ff0000;">&quot;#00A&quot;</span> <span style="color: #000066;">LineThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">                      <span style="color: #000066;">MarkerEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000066;">ShadowEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vc:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- a 'hidden' X axis --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Chart.AxesX<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Axis</span> <span style="color: #000066;">Enabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Axis.Grids<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:ChartGrid</span> <span style="color: #000066;">Enabled</span>=<span style="color: #ff0000;">&quot;True&quot;</span></span>
<span style="color: #009900;">                        <span style="color: #000066;">LineColor</span>=<span style="color: #ff0000;">&quot;#ddd&quot;</span> <span style="color: #000066;">LineThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vc:Axis.Grids<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vc:Axis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vc:Chart.AxesX<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:Chart.PlotArea<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vc:PlotArea</span> <span style="color: #000066;">ShadowEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vc:Chart.PlotArea<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vc:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The code-behind required to add data to the chart is straightforward. However, you cannot simply create a new <code>DataPointCollection</code> and replace the current <code>Series.DataPoints</code>, instead you have to <a href="http://www.visifire.com/forums/index.php?showtopic=2315">clear the existing collection, then rebuild it</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderDataToChart<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span>Histogram<span style="color: #008000;">.</span><span style="color: #0000FF;">DataPoint</span><span style="color: #008000;">&gt;&gt;</span> rgbData<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  AddDataToSeries<span style="color: #008000;">&#40;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>, rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  AddDataToSeries<span style="color: #008000;">&#40;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span>, rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  AddDataToSeries<span style="color: #008000;">&#40;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span>, rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> AddDataToSeries<span style="color: #008000;">&#40;</span>DataSeries series, List<span style="color: #008000;">&lt;</span>Histogram<span style="color: #008000;">.</span><span style="color: #0000FF;">DataPoint</span><span style="color: #008000;">&gt;</span> list<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  series<span style="color: #008000;">.</span><span style="color: #0000FF;">DataPoints</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var pt <span style="color: #0600FF; font-weight: bold;">in</span> list<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    series<span style="color: #008000;">.</span><span style="color: #0000FF;">DataPoints</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Visifire<span style="color: #008000;">.</span><span style="color: #0000FF;">Charts</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataPoint</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      XValue <span style="color: #008000;">=</span> pt<span style="color: #008000;">.</span><span style="color: #0000FF;">Location</span>,
      YValue <span style="color: #008000;">=</span> pt<span style="color: #008000;">.</span><span style="color: #0000FF;">Intensity</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Silverlight Toolkit</h2>
<p>The Silverlight Toolkit XAML is quite verbose, mostly due to the performance enhancements described in my <a href="http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/">previous blog post</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UserControl.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;dataVis:Legend&quot;</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;CollapsedLegendStyle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Width&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;Control&quot;</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;CollapsedStyle&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;SimplifiedDataPoint&quot;</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/UserControl.Resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;White&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:Chart</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chart&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">LegendStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource CollapsedLegendStyle}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">TitleStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource CollapsedStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- define the line series --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span>   </span>
<span style="color: #009900;">                <span style="color: #000066;">TransitionDuration</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">DependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Intensity}&quot;</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">IndependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Location}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{StaticResource SimplifiedDataPoint}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;#A00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span>   </span>
<span style="color: #009900;">                <span style="color: #000066;">TransitionDuration</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">DependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Intensity}&quot;</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">IndependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Location}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{StaticResource SimplifiedDataPoint}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;#0A0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span>   </span>
<span style="color: #009900;">                <span style="color: #000066;">TransitionDuration</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">DependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Intensity}&quot;</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">IndependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Location}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{StaticResource SimplifiedDataPoint}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;#00A&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- configure the axes --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:Chart.Axes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LinearAxis</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;X&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LinearAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:Chart.Axes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>However, the code-behind is the most concise of all the charts I tested because the chart databinds directly to the properties of the <code>DataPoint</code> business objects.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderDataToChart<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span>DataPoint<span style="color: #008000;">&gt;&gt;</span> rgbData<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">&#41;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">&#41;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">&#41;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Chart</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Dynamic Data Display</h2>
<p>The D<sub>3</sub> charts are quite different to the others which I have tested. These charts were developed by a Microsoft team based in Russia and are released on codeplex. They claim outstanding performance with large volumes of data, and are often recommended on sites such as stackoverflow when questions relating to <a href="http://stackoverflow.com/questions/428425/recommendation-for-high-performance-wpf-chart">charting performance arise</a>.</p>
<p>The XAML markup for the D<sub>3</sub> charts is pretty minimal!</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;White&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;d3:ChartPlotter</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;plotter&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/d3:ChartPlotter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>However, this is because the D<sub>3</sub> charts do not support configuration via markup. It took me quite a while to work out how to configure the charts in code-behind, the  D<sub>3</sub> APIs are not very intuitive. I am not the only one to have noticed this; Lee Campbell, in his &#8220;<a href="http://leecampbell.blogspot.com/2010/01/my-wpf-charting-comparisons.html">WPF Charting Comparisons</a>&#8221; blog post stated &#8221; &#8230; it took me hours of reading forums, looking at samples and coding to just get my Model showing on the screen&#8221;. Oh dear!</p>
<p>I had to resort to navigating the visual tree (using<a href="http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/"> Linq to VisualTree</a>) to locate the pan and zoom controls which are added to the chart by default, and remove them.</p>
<p>However, in fairness, the <a href="http://dynamicdatadisplay.codeplex.com/wikipage?title=DynamicDataDisplay%20Silverlight&#038;referringTitle=Home">Silverlight version of D<sub>3</sub> charts</a> is a partial port of the WPF version, but both share a similar programmatic style of usage. </p>
<p>The following code is used to configure the chart in code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> DDDChart<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Loaded</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> RoutedEventHandler<span style="color: #008000;">&#40;</span>DDDChart_Loaded<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> LineGraph InitGraph<span style="color: #008000;">&#40;</span>Color color<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var animatedX <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  var animatedY <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// add some points, otherwise we get some layout-related exception</span>
  animatedX<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  animatedY<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create the X &amp; Y sources</span>
  _xSource <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> EnumerableDataSource<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>animatedX<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _xSource<span style="color: #008000;">.</span><span style="color: #0000FF;">SetXMapping</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _ySource <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> EnumerableDataSource<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>animatedY<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _ySource<span style="color: #008000;">.</span><span style="color: #0000FF;">SetYMapping</span><span style="color: #008000;">&#40;</span>y <span style="color: #008000;">=&gt;</span> y<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// Adding graph to plotter</span>
  var graph <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> LineGraph<span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> CompositeDataSource<span style="color: #008000;">&#40;</span>_xSource, _ySource<span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  graph<span style="color: #008000;">.</span><span style="color: #0000FF;">LineColor</span> <span style="color: #008000;">=</span> color<span style="color: #008000;">;</span>
  graph<span style="color: #008000;">.</span><span style="color: #0000FF;">LineThickness</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
  plotter<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>graph<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">return</span> graph<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> DDDChart_Loaded<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, RoutedEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// remove the mouse pan and zoom controls</span>
  var navigationControl <span style="color: #008000;">=</span> plotter<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OfType</span><span style="color: #008000;">&lt;</span>MouseNavigation<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Single</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  plotter<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>navigationControl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  var zoomControl <span style="color: #008000;">=</span> plotter<span style="color: #008000;">.</span><span style="color: #0000FF;">Descendants</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OfType</span><span style="color: #008000;">&lt;</span>buttonsNavigation<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Single</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>Panel<span style="color: #008000;">&#41;</span>zoomControl<span style="color: #008000;">.</span><span style="color: #0000FF;">Ancestors</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>zoomControl<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  _graphOne <span style="color: #008000;">=</span> InitGraph<span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">FromArgb</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>,<span style="color: #FF0000;">200</span>,<span style="color: #FF0000;">0</span>,<span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _graphTwo <span style="color: #008000;">=</span> InitGraph<span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">FromArgb</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">200</span>, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  _graphThree <span style="color: #008000;">=</span> InitGraph<span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">FromArgb</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">255</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">200</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// Force everything plotted to be visible</span>
  plotter<span style="color: #008000;">.</span><span style="color: #0000FF;">FitToView</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  plotter<span style="color: #008000;">.</span><span style="color: #0000FF;">Legend</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Visibility</span> <span style="color: #008000;">=</span> Visibility<span style="color: #008000;">.</span><span style="color: #0000FF;">Collapsed</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The following code is used to change the data for each series. Again, the D<sub>3</sub> APIs are a little complex. Also, the chart does not have a mode where the X &#038; Y axes compute their range based on the data. Instead, this is performed programatically via <code>FitToView</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderDataToChart<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span>DataPoint<span style="color: #008000;">&gt;&gt;</span> rgbData<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  RenderDataToGraph<span style="color: #008000;">&#40;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">LineGraphR</span>, rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  RenderDataToGraph<span style="color: #008000;">&#40;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">LineGraphG</span>, rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  RenderDataToGraph<span style="color: #008000;">&#40;</span>_chart<span style="color: #008000;">.</span><span style="color: #0000FF;">LineGraphB</span>, rgbData<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// re-scale the chart based on the rendered data</span>
  _chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Plotter</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FitToView</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderDataToGraph<span style="color: #008000;">&#40;</span>LineGraph graph, List<span style="color: #008000;">&lt;</span>DataPoint<span style="color: #008000;">&gt;</span> histogram<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var source <span style="color: #008000;">=</span> graph<span style="color: #008000;">.</span><span style="color: #0000FF;">DataSource</span> <span style="color: #0600FF; font-weight: bold;">as</span> CompositeDataSource<span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// obtain the two sources which the composite is composed of</span>
  var xSource <span style="color: #008000;">=</span> source<span style="color: #008000;">.</span><span style="color: #0000FF;">DataParts</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ElementAt</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> EnumerableDataSource<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;;</span>
  var ySource <span style="color: #008000;">=</span> source<span style="color: #008000;">.</span><span style="color: #0000FF;">DataParts</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ElementAt</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> EnumerableDataSource<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;;</span>
&nbsp;
  var dataX <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  var dataY <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span>var point <span style="color: #0600FF; font-weight: bold;">in</span> histogram<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    dataX<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>point<span style="color: #008000;">.</span><span style="color: #0000FF;">Location</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    dataY<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>point<span style="color: #008000;">.</span><span style="color: #0000FF;">Intensity</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  xSource<span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> dataX<span style="color: #008000;">;</span>
  ySource<span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> dataY<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Conclusions</h2>
<p>In summary, the Visiblox and Visifire charts seem to have the cleanest API, with concise XAML markup to define the charts and little code-behind required to update the series. The Silverlight Toolkit charts XAML markup is a bit verbose, mostly due to performance optimisation. Finally, the D<sub>3</sub> charts have a complex and difficult to follow API. In terms of performance, the Visiblox and D<sub>3</sub> charts give similar results, the Visifire charts are a little behind with, with a frame rate that is approximately 1/3 of the leading charts, and the Silverlight Toolkit charts come last.</p>
<p>You can download the full sourcecode of this comparison here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/12/ChartPerformance.zip'>ChartPerformance.zip</a></p>
<p>NOTE: To build the examples you need to download the charting components from their respective web pages:</p>
<ul>
<li><a href="http://www.visiblox.com/">Visiblox</a></li>
<li><a href="http://www.visifire.com/download_silverlight_charts.php">Visifire</a></li>
<li><a href="http://silverlight.codeplex.com/">Silverlight Toolkit</a></li>
<li><a href="http://dynamicdatadisplay.codeplex.com/releases/view/42438">D<sub>3</sub></a></li>
</ul>
<p>Finally, a couple of my colleagues have created similar charting tests using other technologies, you might be interested in <a href="http://www.scottlogic.co.uk/blog/graham/2010/11/flex-charts-vs-silverlight-charts-a-test-of-performance/">Graham&#8217;s Flex implementation</a>, or <a href="http://www.scottlogic.co.uk/blog/chris/2010/11/html5-charts-vs-flex-charts-vs-silverlight-charts-a-test-of-performance/">Chris&#8217;s cute HTML5 implementation</a>.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2010/12/visiblox-visifire-dynamicdatadisplay-charting-performance-comparison/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Adding a Smoothed Line Series (Bézier curve) to a Visiblox Chart</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2010/11/adding-a-smoothed-line-series-bezier-curve-to-a-visiblox-chart/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2010/11/adding-a-smoothed-line-series-bezier-curve-to-a-visiblox-chart/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 10:40:39 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[codeproject]]></category>
		<category><![CDATA[Bezier]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[spline]]></category>
		<category><![CDATA[visiblox]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=939</guid>
		<description><![CDATA[In this blog post I look at how to add a new series type to the Visiblox charts by creating my own series type which renders a smoothed line using a Bézier curve. This blog post describes how to create a new series type for the Visiblox charts, a spline series. The example below shows [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2010%252F11%252Fadding-a-smoothed-line-series-bezier-curve-to-a-visiblox-chart%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Adding%20a%20Smoothed%20Line%20Series%20%28B%C3%A9zier%20curve%29%20to%20a%20Visiblox%20Chart%20%23%22%20%7D);"></div>
<p><i>In this blog post I look at how to add a new series type to the Visiblox charts by creating my own series type which renders a smoothed line using a Bézier curve.</i></p>
<p>This blog post describes how to create a new series type for the <a href="http://www.visiblox.com">Visiblox</a> charts, a spline series. The example below shows the new series type in action, with the various spline control points rendered (just for fun!):</p>
<div style="text-align: center; "><object width="300" height="300" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/VisibloxSplineSeriesFour2.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<p><br/></p>
<h2>Creating a New Series Type</h2>
<p>The visual representation of a Visiblox <code>DataSeries</code> is the responsibility of a chart series, as defined by the <code>IChartSeries</code> interface. However, the abstract baseclass <code>ChartSeriesBase</code> is most often the best place to start when creating a new series type.</p>
<p>The first step towards creating my smoothed series type is to create a <code>ChartSeries</code> subclass. The only abstract method that we must implement is <code>InvalidateInternal</code>, and it is here that we will place our logic to create the series:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> SplineSeries <span style="color: #008000;">:</span> ChartSeriesBase
<span style="color: #008000;">&#123;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> SplineSeries<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    DefaultStyleKey <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>SplineSeries<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> InvalidateInternal<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// render logic goes here</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>A template also has to be supplied for the series in the generic.xaml file. The <code>ChartSeriesBase</code> requires that a <code>ZoomCanvas</code> element is located within the template as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ResourceDictionary</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:x</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;clr-namespace:VisibloxSplineSeries&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:visPrim</span>=<span style="color: #ff0000;">&quot;clr-namespace:Visiblox.Charts.Primitives;assembly=Visiblox.Charts&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;local:SplineSeries&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;local:SplineSeries&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visPrim:ZoomCanvas</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Setter.Value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Setter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ResourceDictionary<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>That’s all the boiler plate code out of the way with, let’s get down to writing our series implementation.</p>
<h2>A Simple Line Series</h2>
<p>We’ll start by creating a straight-line implementation. Within the <code>UpdateInternal</code> method the following code constructs a Path instance and adds it to the <code>ZoomCanvas</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> InvalidateInternal<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  RootZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  Path path <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Path<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  PathGeometry geometry <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathGeometry<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  PathFigure figure <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathFigure<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  var renderPoints <span style="color: #008000;">=</span> GetRenderPoints<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  figure<span style="color: #008000;">.</span><span style="color: #0000FF;">StartPoint</span> <span style="color: #008000;">=</span> renderPoints<span style="color: #008000;">.</span><span style="color: #0000FF;">First</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var renderPoint <span style="color: #0600FF; font-weight: bold;">in</span> renderPoints<span style="color: #008000;">.</span><span style="color: #0000FF;">Skip</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    figure<span style="color: #008000;">.</span><span style="color: #0000FF;">Segments</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> LineSegment<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      Point <span style="color: #008000;">=</span> renderPoint
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  geometry<span style="color: #008000;">.</span><span style="color: #0000FF;">Figures</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>figure<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  path<span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> geometry<span style="color: #008000;">;</span>
  path<span style="color: #008000;">.</span><span style="color: #0000FF;">StrokeThickness</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
  path<span style="color: #008000;">.</span><span style="color: #0000FF;">Stroke</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  ZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetIsScaledPath</span><span style="color: #008000;">&#40;</span>path, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  RootZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>path<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> List<span style="color: #008000;">&lt;</span>Point<span style="color: #008000;">&gt;</span> GetRenderPoints<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  var renderPoints <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Point<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>IDataPoint point <span style="color: #0600FF; font-weight: bold;">in</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">double</span> xPos <span style="color: #008000;">=</span> XAxis<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataValueAsRenderPositionWithoutZoom</span><span style="color: #008000;">&#40;</span>point<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">double</span> yPos <span style="color: #008000;">=</span> YAxis<span style="color: #008000;">.</span><span style="color: #0000FF;">GetDataValueAsRenderPositionWithoutZoom</span><span style="color: #008000;">&#40;</span>point<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    renderPoints<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Point<span style="color: #008000;">&#40;</span>xPos, yPos<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">return</span> renderPoints<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Let’s look at this code in detail. The method <code>GetRenderPoints</code> creates a list of points which indicate the location where each datapoint should be rendered on the chart. The series has a property <code>DataSeries</code> which is the data being rendered and we enumerate over each of the points in this series. The chart series also has a relationship to the X &#038; Y axes, and it is each axis which is responsible for the converting the X &#038; Y components of our data into a ‘screen’ coordinate. This is performed via the (succinctly named!)  <code>GetDataValueAsRenderPositionWithoutZoom</code> method (more on this later).</p>
<p>The list of points returned by the <code>GetRenderPoints</code> method are used to define a path (a path is defined by a geometry which is defined by one or more figures which themselves are defined by one or more segments &#8230; phew!). This path is styled and added to the <code>RootZoomCanvas</code>, with the attached property <code>IsScaledPath</code> set to true.</p>
<p>The net result of the above code is that we now have a fully functional line series which integrates with the Visiblox behaviours such as pan &#038; zoom:</p>
<div style="text-align: center; "><object width="300" height="300" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/VisibloxSplineSeriesOne.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<p>Now back to this ZoomCanvas &#8230; </p>
<p>The Visiblox charts have been optimised for performance and providing user interactions. A common requirement for interactive charts is the ability to pan and zoom. Both of these can be implemented by changing the range of the X and Y axes (for example a pan operation would result in a fixed offset being applied to the axis range), however this would result in the chart having to recomputed the location of all of each of the points being rendered. As an alternative, the Visiblox axes have a Zoom property which is handled by the <code>ZoomCanvas</code> directly. When a Zoom is applied, the required <code>RenderTransform</code>s are applied to the elements in the canvas, i.e. the series, resulting in a rapid update of chart. When using the <code>ZoomCanvas</code> you have to indicate whether the element added is based on a geometry, which should be transformed (i.e. a zoom makes the geometry appear bigger), or whether the element location should simply by updated to reflect the current zoom, for example, when you zoom in to a chart typically you would want the datapoints to maintain a fixed size.</p>
<p>Gergely Orosz describes the ZoomCanvas in more detail in his recent post on <a href="http://www.visiblox.com/blog/2010/11/zooming-panning-in-silverlight-using-visiblox-charts">Panning &amp; Zooming</a> the charts.</p>
<p>To illustrate how this works, we will add points to our series which are not scaled as we zoom into the chart. The <code>InvalidateInternal</code> method is updated with the additional code to render the points, note that the ellipses have a <code>RenderTransform</code> applied so that their centre is anchored to the correct location on the <code>ZoomCanvas</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> InvalidateInternal<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// ... code for rendering the path</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>var renderPoint <span style="color: #0600FF; font-weight: bold;">in</span> renderPoints<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Ellipse el <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Ellipse<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      Stroke <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span>,
      StrokeThickness <span style="color: #008000;">=</span> <span style="color: #FF0000;">2.0</span>,
      Fill <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span><span style="color: #008000;">&#41;</span>,
      Width <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span>,
      Height <span style="color: #008000;">=</span> <span style="color: #FF0000;">9</span>,
      RenderTransform <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TranslateTransform<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
      <span style="color: #008000;">&#123;</span>
        X <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">4</span>,
        Y <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">4</span>
      <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
    RootZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>el<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    ZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetElementPosition</span><span style="color: #008000;">&#40;</span>el, renderPoint<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>You can see the series in action below:</p>
<div style="text-align: center; "><object width="300" height="300" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/VisibloxSplineSeriesTwo.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<h2>Creating a Smoothed Curve</h2>
<p>So far we have created a simple line series; however the aim of this article is to create a smoothed line series. The <code>Figure</code> within our <code>PathGeometry</code> is currently composed of a number of straight line segments, in order to create a smoothed line we need to use curved segments. Silverlight and WPF both support Bézier curves and these can be used to specify a curved path geometry. A  Bézier curve has four points, a start point, an end point and two control points which define the curvature:</p>
<p><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/mapbezier1.png" alt="" title="mapbezier1" width="215" height="321" class="aligncenter size-full wp-image-944" /></p>
<p>In order to create a curved path for our series we need to determine suitable control points for our Bézier segments. After a bit of googling I stumbled upon an excellent article by Kerem Kat which describes how to use <a href="http://www.codeproject.com/KB/silverlight/MapBezier.aspx">Bézier curves with Bing Maps</a>. The article sourcecode has a method that will return the data points required to render a smoothed line as a Bézier Curve, using <a href="http://www.mvps.org/directx/articles/catmull/">Catmull-Rom</a> splines. </p>
<p>Modifying our series to use Bézier Curves, via the <code>GetBezierPoints</code> method described in the above article, is pretty straightforward:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> InvalidateInternal<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  RootZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  Path path <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Path<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  PathGeometry geometry <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathGeometry<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  PathFigure figure <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PathFigure<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// obtain the render position of each point</span>
  var renderPoints <span style="color: #008000;">=</span> GetRenderPoints<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create the bezier points as per:</span>
  <span style="color: #008080; font-style: italic;">// http://www.codeproject.com/KB/silverlight/MapBezier.aspx</span>
  PointCollection bezierPoints <span style="color: #008000;">=</span> GetBezierPoints<span style="color: #008000;">&#40;</span>renderPoints, Tension<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create the figure composed of bezier segments</span>
  figure<span style="color: #008000;">.</span><span style="color: #0000FF;">StartPoint</span> <span style="color: #008000;">=</span> bezierPoints<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
  <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> bezierPoints<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i <span style="color: #008000;">+=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    figure<span style="color: #008000;">.</span><span style="color: #0000FF;">Segments</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> BezierSegment<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
      Point1 <span style="color: #008000;">=</span> bezierPoints<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span>,       
      Point2 <span style="color: #008000;">=</span> bezierPoints<span style="color: #008000;">&#91;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span>,   
      Point3 <span style="color: #008000;">=</span> bezierPoints<span style="color: #008000;">&#91;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span>    
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  geometry<span style="color: #008000;">.</span><span style="color: #0000FF;">Figures</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>figure<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  path<span style="color: #008000;">.</span><span style="color: #0000FF;">Data</span> <span style="color: #008000;">=</span> geometry<span style="color: #008000;">;</span>
  path<span style="color: #008000;">.</span><span style="color: #0000FF;">StrokeThickness</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
  path<span style="color: #008000;">.</span><span style="color: #0000FF;">Stroke</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SolidColorBrush<span style="color: #008000;">&#40;</span>Colors<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  ZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">SetIsScaledPath</span><span style="color: #008000;">&#40;</span>path, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  RootZoomCanvas<span style="color: #008000;">.</span><span style="color: #0000FF;">Children</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>path<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Note the <code>Tension</code> property which is passed to the <code>GetBezierPoints</code> method, this is a property of Catmull-Rom splines which describes how ‘smoothed’ the line should be. The <code>SplineSeries</code> exposes this as a dependency property, as shown in the example below:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vis:Chart</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chart&quot;</span> <span style="color: #000066;">LegendVisibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vis:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local:SplineSeries</span> <span style="color: #000066;">Tension</span>=<span style="color: #ff0000;">&quot;{Binding Path=Value, ElementName=tensionSlider}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vis:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/vis:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span> <span style="color: #000066;">Grid.Row</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Tension:&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Slider</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;tensionSlider&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">Maximum</span>=<span style="color: #ff0000;">&quot;5.0&quot;</span> <span style="color: #000066;">Minimum</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> </span>
<span style="color: #009900;">        <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;100&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Value, ElementName=tensionSlider}&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;18&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You can see the effect of changing the tension on the spline:</p>
<div style="text-align: center; "><object width="300" height="300" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/VisibloxSplineSeriesThree2.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<h2>For a Bit Of Fun &#8230;</h2>
<p>I thought it would be fun to visualise the Catmull-Rom spline construction by also rendering the control points for each Bézier curve. You can see the results below:</p>
<div style="text-align: center; "><object width="300" height="300" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/VisibloxSplineSeriesFour2.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<p>You can download the full sourcecode for the article here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/VisibloxSplineSeries.zip'>VisibloxSplineSeries.zip</a></p>
<p>To run the examples you will also need to download the Visiblox charts from <a href="http://www.visiblox.com">www.visiblox.com</a>.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2010/11/adding-a-smoothed-line-series-bezier-curve-to-a-visiblox-chart/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visiblox Charts vs. Silverlight Toolkit Charts &#8211; a test of Performance</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/#comments</comments>
		<pubDate>Mon, 08 Nov 2010 08:31:35 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[visiblox]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=914</guid>
		<description><![CDATA[This blog post compares the performance of the Visiblox and Silverlight Toolkit charts using a simple image processing tool to test and illustrate their differences in performance. The results show that the Visiblox charts are approximately 50 &#8211; 100 times faster that the Silverlight Toolkit charts. I was recently asked by my friends at Visiblox [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2010%252F11%252Fvisiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Visiblox%20Charts%20vs.%20Silverlight%20Toolkit%20Charts%20-%20a%20test%20of%20Performance%20%23%22%20%7D);"></div>
<p><em>This blog post compares the performance of the Visiblox and Silverlight Toolkit charts using a simple image processing tool to test and illustrate their differences in performance. The results show that the Visiblox charts are approximately 50 &#8211; 100 times faster that the Silverlight Toolkit charts.</em></p>
<p>I was recently asked by my friends at <a href="http://www.visiblox.com/">Visiblox</a> to test out the latest release of their charts for WPF and Silverlight. One of the key features of the Visiblox charts is their performance; they have been designed to both render and update rapidly in response to changes in the underlying data. I decided to put their latest release to the test in a head-to-head against the Silverlight Toolkit charts.</p>
<p>Microsoft announced the release of the Silverlight Toolkit charts in late 2008 and have since released a number of updates, some of which have <a href="http://blogs.msdn.com/b/delay/archive/2009/03/19/silverlight-charting-is-faster-and-better-than-ever-silverlight-toolkit-march-09-release-now-available.aspx">focussed on performance</a>. I would anticipate that the relatively mature Silverlight Toolkit charts are probably most developer’s first choice when they need to display data graphically within their application.</p>
<p>Before we get into the details of my investigation, here are the two applications working side-by-side, one using the Visiblox chart and the other using the Toolkit charts. Click and drag a line across the image to plot the RGB pixel intensities along the line in the chart above. This is a reasonably tough challenge for the chart, with three series rendered of up to 400 points each. From the examples below you can see that the Visiblox charts are clearly faster.</p>
<table>
<tr>
<th style="text-align: center; ">
Visiblox Chart
</th>
<th style="text-align: center; ">
Silverlight Toolkit Chart
</th>
</tr>
<tr>
<td>
<div style="text-align: center; "><object width="300" height="430" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/11/HistogramVisiblox.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
</td>
<td>
<div style="text-align: center; "><object width="300" height="430" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/10/HistogramToolkit.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
</td>
</tr>
</table>
<p><small>[Hare image used under CC licence from <a href="http://www.flickr.com/photos/heliocentric/2643028940/">flickr</a>, tortoise used royalty free from <a href="http://www.sxc.hu/photo/695928">stock.xchng</a>]</small></p>
<p>I have had quite a bit of experience with the Silverlight Toolkit in the past and have written a few blog posts which detail how to <a href="http://www.scottlogic.co.uk/blog/colin/2009/03/adding-a-location-crosshair-to-silverlight-charts-again/">add interactivity to the charts</a>. The early releases were pretty slow, due to the large number of ‘Control’ instances that the chart constructs, (there are un-official guidelines that you should limit the number of control instances to a few hundred for WPF &#038; Silverlight). However, subsequent releases were quite a bit faster. David Anson also published a number of very useful hints and tips on <a href="http://blogs.msdn.com/b/delay/archive/2010/01/13/i-feel-the-need-the-need-for-speed-seven-simple-performance-boosting-tweaks-for-common-silverlight-wpf-charting-scenarios.aspx">maximising chart performance</a> on his blog. I have followed all of David’s guidelines to provide a fair comparison.</p>
<p>The following sections will provide a little more detail regarding the implementation of this application and how it differs between the Visiblox and Toolkit versions.</p>
<h2>Visiblox Charts</h2>
<p>The markup for the above application is quite simple:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Vertical&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;LayoutRoot&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;180&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chart&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">LegendVisibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5,0,5,5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart.XAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- a 'hidden' X axis --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LinearAxis</span> <span style="color: #000066;">ShowAxis</span>=<span style="color: #ff0000;">&quot;False&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">GridlineStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource GridLineStyle}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">IsMarginEnabled</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart.XAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart.YAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- A Y axis with labels within the chart area --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LinearAxis</span> <span style="color: #000066;">ShowLabels</span>=<span style="color: #ff0000;">&quot;True&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">LabelsPosition</span>=<span style="color: #ff0000;">&quot;Inside&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">GridlineStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource GridLineStyle}&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">ShowMajorTicks</span>=<span style="color: #ff0000;">&quot;False&quot;</span></span>
<span style="color: #009900;">                          <span style="color: #000066;">ShowMinorTicks</span>=<span style="color: #ff0000;">&quot;False&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart.YAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- the series used to render the RGB components --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LineSeries</span> <span style="color: #000066;">LineStroke</span>=<span style="color: #ff0000;">&quot;#A00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LineSeries</span> <span style="color: #000066;">LineStroke</span>=<span style="color: #ff0000;">&quot;#0A0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart:LineSeries</span> <span style="color: #000066;">LineStroke</span>=<span style="color: #ff0000;">&quot;#00A&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart.Series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;instructions&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Use the mouse to 'drag' a line across the image below ...&quot;</span></span>
<span style="color: #009900;">                <span style="color: #000066;">FontSize</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">Foreground</span>=<span style="color: #ff0000;">&quot;#333333&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">TextWrapping</span>=<span style="color: #ff0000;">&quot;Wrap&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;grid&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">MouseLeftButtonUp</span>=<span style="color: #ff0000;">&quot;Grid_MouseLeftButtonUp&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">MouseLeftButtonDown</span>=<span style="color: #ff0000;">&quot;Grid_MouseLeftButtonDown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;image&quot;</span>               </span>
<span style="color: #009900;">                    <span style="color: #000066;">Source</span>=<span style="color: #ff0000;">&quot;/hare.jpg&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Line</span> <span style="color: #000066;">Stroke</span>=<span style="color: #ff0000;">&quot;Black&quot;</span> <span style="color: #000066;">StrokeThickness</span>=<span style="color: #ff0000;">&quot;3&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;line&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The above markup constructs a Chart, Image and a Line within a <code>StackPanel</code>. The code-behind loads the image into a <code>WriteableBitmap</code> in order to access its pixel values, and the mouse event handlers attached to the grid are used to detect when the user drags the line. The technique I published previously on <a href="http://www.scottlogic.co.uk/blog/colin/2010/06/throttling-silverlight-mouse-events-to-keep-the-ui-responsive/">throttling mouse events</a> is used to handle the mouse move event in order to construct the chart data:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> ThrottledEvent_ThrottledMouseMove<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, MouseEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>lButtonDown<span style="color: #008000;">&#41;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span> <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span>grid<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span> <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span>grid<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// compute distance between the points</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> distance <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Sqrt</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span>
      <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create the Visiblox dataseries for the R, G &amp; B components</span>
  var dataR <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataSeries<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;R&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  var dataG <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataSeries<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;G&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  var dataB <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DataSeries<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;B&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// build the charts</span>
  <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> pt <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> pt <span style="color: #008000;">&lt;</span> distance<span style="color: #008000;">;</span> pt<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">double</span> xPos <span style="color: #008000;">=</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> pt <span style="color: #008000;">/</span> distance<span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">double</span> yPos <span style="color: #008000;">=</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> pt <span style="color: #008000;">/</span> distance<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">int</span> xIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>xPos<span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">int</span> yIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>yPos<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">int</span> pixel <span style="color: #008000;">=</span> pixelData<span style="color: #008000;">&#91;</span>xIndex <span style="color: #008000;">+</span> yIndex <span style="color: #008000;">*</span> <span style="color: #FF0000;">300</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// the RGB values are 'packed' into an int, here we unpack them</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span> B <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>pixel <span style="color: #008000;">&amp;</span> 0xFF<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    pixel <span style="color: #008000;">&gt;&gt;=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span> G <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>pixel <span style="color: #008000;">&amp;</span> 0xFF<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    pixel <span style="color: #008000;">&gt;&gt;=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span> R <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>pixel <span style="color: #008000;">&amp;</span> 0xFF<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    pixel <span style="color: #008000;">&gt;&gt;=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// add each datapoint</span>
    dataR<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> DataPoint<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>pt, R<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    dataG<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> DataPoint<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>pt, G<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    dataB<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> DataPoint<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">double</span>, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>pt, B<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// set the data for each series</span>
  chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span> <span style="color: #008000;">=</span> dataR<span style="color: #008000;">;</span>
  chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span> <span style="color: #008000;">=</span> dataG<span style="color: #008000;">;</span>
  chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSeries</span> <span style="color: #008000;">=</span> dataB<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The Visiblox series (which implement <code>IChartSeries</code>) require date to be presented as an <code>IDataSeries</code>, which is a collection of <code>IDataPoint</code> instances. In the above code the chart data is copied directly into a <code>DataSeries</code>. Databinding is also possible via <code>BindableDataSeries</code>, however, for maximum performance it is always better to use <code>DataSeries</code> and copy the data across directly.</p>
<h2>Silverlight Toolkit Charts</h2>
<p>The Toolkit version of the application is much the same as the Visiblox one. The only difference in the application markup is for the chart itself, as shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;SimplifiedDataPoint&quot;</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:Chart</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;chart&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">LegendStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource CollapsedLegendStyle}&quot;</span></span>
<span style="color: #009900;">          <span style="color: #000066;">TitleStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource CollapsedStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- define the line series --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span>   </span>
<span style="color: #009900;">                  <span style="color: #000066;">TransitionDuration</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">DependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Intensity}&quot;</span> </span>
<span style="color: #009900;">                  <span style="color: #000066;">IndependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Location}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{StaticResource SimplifiedDataPoint}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;#A00&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span>   </span>
<span style="color: #009900;">                  <span style="color: #000066;">TransitionDuration</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">DependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Intensity}&quot;</span> </span>
<span style="color: #009900;">                  <span style="color: #000066;">IndependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Location}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{StaticResource SimplifiedDataPoint}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;#0A0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries</span> <span style="color: #000066;">ItemsSource</span>=<span style="color: #ff0000;">&quot;{Binding}&quot;</span>   </span>
<span style="color: #009900;">                  <span style="color: #000066;">TransitionDuration</span>=<span style="color: #ff0000;">&quot;0&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">DependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Intensity}&quot;</span> </span>
<span style="color: #009900;">                  <span style="color: #000066;">IndependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Location}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Style</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;tk:LineDataPoint&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Visibility&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Template&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;{StaticResource SimplifiedDataPoint}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Setter</span> <span style="color: #000066;">Property</span>=<span style="color: #ff0000;">&quot;Background&quot;</span> <span style="color: #000066;">Value</span>=<span style="color: #ff0000;">&quot;#00A&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Style<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries.DataPointStyle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LineSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- configure the axes --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:Chart.Axes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tk:LinearAxis</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;X&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:LinearAxis<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:Chart.Axes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tk:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The markup here is a little more complex, in part because I am following the advice given by David Anson in his <a href="http://blogs.msdn.com/b/delay/archive/2010/01/13/i-feel-the-need-the-need-for-speed-seven-simple-performance-boosting-tweaks-for-common-silverlight-wpf-charting-scenarios.aspx">charting performance blog post</a> in order to maximise the chart performance. With reference to David’s post, the following tips have been implemented:</p>
<ol>
<li>Turn off the fade in/out VSM animations – the template used by the <code>DataPoint</code> in my example has no visual states, hence will not be animated</li>
<li>Change to a simpler <code>DataPoint</code> Template – the template in the example is as simple as possible, it is empty!</li>
<li>Add the points more efficiently – the <code>ItemsSource</code> for each series are being updated via an ‘atomic’ re-assignment.</li>
<li>Disable the data change animations – the <code>TransitionDuration</code> property has been set to zero as per David’s recommendation.</li>
</ol>
<p>The other three tips in the blog post were not relevant to this test scenario.</p>
<p>The code-behind for the Toolkit chart version of this application is again much the same as for the Visiblox charts, the main difference is due to the Toolkit chart binding to business objects rather than having its own series type. Here is the implementation of the (throttled) mouse move event handler, and the business object which is bound to the chart.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Handles mouse move to draw the line and intensity histograms</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> ThrottledEvent_ThrottledMouseMove<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, MouseEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>lButtonDown<span style="color: #008000;">&#41;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span> <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span>grid<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
  line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span> <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span>grid<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// compute distance between the points</span>
  <span style="color: #6666cc; font-weight: bold;">double</span> distance <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Sqrt</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span>
      <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// create the series for the R, G &amp;amp; B components</span>
  var dataR <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>DataPoint<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  var dataG <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>DataPoint<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  var dataB <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>DataPoint<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// build the charts</span>
  <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> pt <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> pt <span style="color: #008000;">&lt;</span> distance<span style="color: #008000;">;</span> pt<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">double</span> xPos <span style="color: #008000;">=</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">X2</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">X1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> pt <span style="color: #008000;">/</span> distance<span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">double</span> yPos <span style="color: #008000;">=</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y2</span> <span style="color: #008000;">-</span> line<span style="color: #008000;">.</span><span style="color: #0000FF;">Y1</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">*</span> pt <span style="color: #008000;">/</span> distance<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">int</span> xIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>xPos<span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">int</span> yIndex <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>yPos<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">int</span> pixel <span style="color: #008000;">=</span> pixelData<span style="color: #008000;">&#91;</span>xIndex <span style="color: #008000;">+</span> yIndex <span style="color: #008000;">*</span> <span style="color: #FF0000;">300</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// the RGB values are 'packed' into an int, here we unpack them</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span> B <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>pixel <span style="color: #008000;">&amp;</span> 0xFF<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    pixel <span style="color: #008000;">&gt;&gt;=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span> G <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>pixel <span style="color: #008000;">&amp;</span> 0xFF<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    pixel <span style="color: #008000;">&gt;&gt;=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">byte</span> R <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>pixel <span style="color: #008000;">&amp;</span> 0xFF<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    pixel <span style="color: #008000;">&gt;&gt;=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// add each datapoint to the series</span>
    dataR<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> DataPoint<span style="color: #008000;">&#40;</span>pt, R<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    dataG<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> DataPoint<span style="color: #008000;">&#40;</span>pt, G<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    dataB<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> DataPoint<span style="color: #008000;">&#40;</span>pt, B<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #008080; font-style: italic;">// add each series to the chart</span>
  <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">&#41;</span>chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> dataR<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">&#41;</span>chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> dataG<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">&#41;</span>chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> dataB<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">...</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// A value object used to present the data to the chart</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> DataPoint
<span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> Location <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
  <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">double</span> Intensity <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF; font-weight: bold;">public</span> DataPoint<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> location, <span style="color: #6666cc; font-weight: bold;">double</span> intensity<span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    Location <span style="color: #008000;">=</span> location<span style="color: #008000;">;</span>
    Intensity <span style="color: #008000;">=</span> intensity<span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h2>Conclusions</h2>
<p>From the above example application we can see that the Visiblox charts performs approximately 50 &#8211; 100 times faster than the Silverlight Toolkit charts. This is of course a limited test that focuses on a specific mode of operation, however, the Visiblox charts have been designed with a focus on performance, so I would expect a similar result in other performance test cases.</p>
<p>The difference in speed between the two charting components can be broadly attributed to three key differences in design:</p>
<ol>
<li><strong>Lightweight visuals</strong> – as mentioned in the introduction, the Toolkit charts are ‘control’ heavy, pushing the limits of the framework guidelines, in order to provide flexible styling and templating. The Visiblox charts use a much more lightweight approach, however, if templating is required a TemplatedLineSeries can be used.</li>
<li><strong>Databinding as an option</strong> – with Visiblox it is possible to present the data directly to the chart using the DataSeries class, whilst with the Toolkit charts you have to use databinding which brings with it a performance overhead. Again, with Visiblox you can use databinding to business objects if you wish. With the above Visiblox example application the performance is approximately halved by using databinding, this is still 25-50 times faster than the toolkit charts! (The sourcecode download includes the databinding Visiblox vesion).</li>
<li><strong>Optimised handling of changes</strong> – the Visiblox charts are optimised in such a way as to minimise the impact of changes in the data or other properties of the chart. You can update datapoints, entire series, or change the various properties of an axis and be guaranteed that the chart will only re-computed its layout once.</li>
</ol>
<p>You can download the full sourcecode for the example applications given in this blog post here: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/10/ChartPerformance.zip'>ChartPerformance.zip</a></p>
<p>For the Visiblox examples you will need to visit <a href="http://www.visiblox.com/">www.visiblox.com</a> to download their chart component, and for the Toolkit examples you will need to download and install the <a href="http://silverlight.codeplex.com/">Silverlight Toolkit</a>.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2010/11/visiblox-charts-vs-silverlight-toolkit-charts-a-test-of-performance-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Ineffective Data Visualisation &#8230; and how to fix it</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2010/04/ineffective-data-visualisation-and-how-to-fix-it/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2010/04/ineffective-data-visualisation-and-how-to-fix-it/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 10:33:56 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[visualisation]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=629</guid>
		<description><![CDATA[This blog post looks at a recently published set of charts in a UK newspaper and how they fail to help in the comprehension of the data which they visualise. I will also look at much more effective ways of displaying this same data. At Scott Logic we tend to spend quite a bit of [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2010%252F04%252Fineffective-data-visualisation-and-how-to-fix-it%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Ineffective%20Data%20Visualisation%20...%20and%20how%20to%20fix%20it%20%23%22%20%7D);"></div>
<p><em>This blog post looks at a recently published set of charts in a UK newspaper and how they fail to help in the comprehension of the data which they visualise. I will also look at much more effective ways of displaying this same data.</em></p>
<p>At Scott Logic we tend to spend quite a bit of our time thinking about the effective visualisation of data. In the financial sector data abounds, with stock prices changing every second, traders and analysts have a lot of data at their disposal. Without methods to analyse and visualise this data it is easy to gets lost in the sheer quantity. For this reason, the works of <a href="http://www.amazon.co.uk/s/ref=pd_lpo_k2_dp_sr_sq_top?ie=UTF8&amp;keywords=edward%20tufte&amp;index=blended&amp;pf_rd_p=103612307&amp;pf_rd_s=lpo-top-stripe&amp;pf_rd_t=201&amp;pf_rd_i=0961392142&amp;pf_rd_m=A3P5ROKL5A1OLE&amp;pf_rd_r=1WRA0VX1KK1XGRVN9GRX">Edward Tufte</a> and <a href="http://www.amazon.co.uk/Stephen-Few/e/B001H6IQ5M/ref=sr_tc_2_0?qid=1272621572&amp;sr=8-2-ent">Stephen Few</a> are often passed round the office!</p>
<p>With the UK General election looming, statistics and trends are a common feature in our news. Unfortunately these seems to lead to a whole slew of charts and graphics which succeed in their artistry but fail miserably in helping the reader understand the data which the graphics represent.</p>
<p>Just this morning I was reading an article in the Metro newspaper about the <a href="http://www.metro.co.uk/news/823850-general-election-2010-metro-harris-poll-points-towards-hung-parliament">changes in party support over the past week&#8217;s opinion polls</a> and the voting habits of different age groups. The article was supported by the following graphic:</p>
<p><a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/article-1272485979111-0958F468000005DC-660044_636x377.jpg"><img class="aligncenter size-full wp-image-630" title="article-1272485979111-0958F468000005DC-660044_636x377" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/article-1272485979111-0958F468000005DC-660044_636x377.jpg" alt="" width="636" height="377" /></a></p>
<p>One of the key ideas behind the charting and visualising of data is to allow the reader to rapidly digest the data, spot trends, understand relationships, etc&#8230; Unfortunately, the graphics above fail miserably in this respect. Here are some of the faults I spotted:</p>
<p><strong>(1)</strong> <strong>Chart title</strong> &#8211; the main chart title relates to the chart on the right, but not to the chart on the left.</p>
<p><strong>(2) Choice of colours </strong>- if you look at the datapoints on the right-hand chart it is not easy to determine which party they relate to due to a poor choice of colour, peach and salmon?!</p>
<p><strong>(3) Trends are hidden </strong>- the main purpose of the right hand chart is to illustrate the trends in party support with relation to age. To do this you have to hunt for the same coloured point from one age band to the next.</p>
<p><strong>(4) Gridlines</strong> &#8211; the right-hand chart has labels every 5 percent point, but gridlines every 2 points. This means that there is not a gridline for each label, this makes it very hard to determine the actual value of each datapoint.</p>
<p><strong>(5) Doughnut</strong> &#8211; the doughnut (i.e. the stylised pie-chart with a yummy hole) has a couple of problems, which week does it represent the split in party support for? this week? last week? Also, which is the bigger pie piece, Lib. Dem. or Conservative? It is impossible to tell without reaching for your protractor (I seem to have left mine at home today).</p>
<p><strong>(6) Arbitrary graphics</strong> &#8211; I cannot see any reason, other than artistic licence, for the vertical highlights on the right-hand chart. This is misleading, it draws the eye to these areas of the chart with the expectation that they are highlighted for some reason.</p>
<p><strong>(7) Change not visualised</strong> &#8211; the change in support from last week to this week is not visualised in any way, it is presented in tabular form. This means that the reader might miss important information, for example, a 10 percent point raise from 10 to 20 is clearly more significant than a rise from 70 to 80, this is made quite obvious if we visualise the change.</p>
<p><strong>(8) Units</strong> &#8211; the indication of units is quite distant from the data.</p>
<p>I am sure there are more problems &#8230; if you spot any others, leave a comment.</p>
<p>So, let&#8217;s see if we can rectify some of these issues. Starting with the chart on the right, its main purpose is to illustrate the relationship between age group and party support. In this case it is vital that the reader of this chart can easily navigate from the datapoint which indicated Conservative party support (for example) in one age range the next. With this in a mind, a line chart is much more appropriate and the trends become immediately visible:</p>
<p><a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/popularityByGeneration.png"><img class="aligncenter size-full wp-image-639" title="popularityByGeneration" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/popularityByGeneration.png" alt="" width="456" height="298" /></a></p>
<p>Note also the colours, these are no longer arbitrarily assigned. Each political party has a <a href="http://en.wikipedia.org/wiki/Political_colour">party colour</a> which, if used, allows most people to instantly determine the party each line relates to. The gridlines are also more sensibly placed and we have lost the &#8216;artistic&#8217; highlights. Finally, the Y axis starts at zero, this allow the reader to instantly see the scale of the differences between the popularity figures without having to read the axis range.</p>
<p>Now, let&#8217;s turn our attention to the doughnut and the accompanying table. The reader should be able to determine two key pieces of information from these, (1) The relative popularity of each party and (2) The change in popularity since last week. It would be ideal if the two could be combined so that the reader can also compare the scale of this change with the overall difference in popularity. In order to allow this, it is much better to display the information in a single chart:</p>
<p><a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/popularityWeeklyChange.png"><img class="aligncenter size-full wp-image-640" title="popularityWeeklyChange" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/popularityWeeklyChange.png" alt="" width="402" height="275" /></a>With the above chart we can see at-a-glance the relative popularity of each party again displayed in party colours. I must admit it took me a little while to work out how to indicate which columns represented this week&#8217;s figures and which were last week&#8217;s. I tried using variations in the column intensity, but this is a hard concept to indicate via a key, I also added small labels, but this just complicates and clutters. Finally I realised that by adding a pattern I could maintain the party colour, yet clearly relate the columns for the previous week (This makes use of the <a href="http://iws.ccccd.edu/acano/introdesign/gestalt.htm">Gestalt Principle of Similarity</a>). Unfortunately Excel 2007, which I used to create these charts, does not support patterns, however I found this excellent <a href="http://www.andypope.info/charts/patternfills.htm">add-in from Andy Pope</a>, and I thoroughly recommend it.</p>
<p>I think the two charts I have presented are much clearer than those in the original graphics from the newspaper article. However, a direct comparison between the two would not be entirely fair. The graphics used in the media often have further constraints imposed on them, (1) They are often restricted in size, having to fit within a fixed page size layout, (2) They should be eye-catching and visually appealing, drawing a potential reader towards the article.</p>
<p>With this in mind, I have re-worked the graphs above into the same layout and size as the originals. I have even added drop-shadows for visual appeal &#8230;</p>
<p><a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/updated1.png"><img class="aligncenter size-full wp-image-647" title="updated" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2010/04/updated1.png" alt="" width="636" height="377" /></a></p>
<p>I think the above is a good compromise between providing an artistically pleasing graphic whilst still allowing the reader to understand the data (and from there spot trends etc&#8230;).</p>
<p>Regards, Colin E.</p>
<p><strong>Update: </strong>Thanks to<a href="http://www.scottlogic.co.uk/blog/graham/"> Graham Odds</a> for a few extra ideas about tidying up the final charts.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2010/04/ineffective-data-visualisation-and-how-to-fix-it/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Adding a Location Crosshair to Silverlight charts (again!)</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/03/adding-a-location-crosshair-to-silverlight-charts-again/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2009/03/adding-a-location-crosshair-to-silverlight-charts-again/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 13:33:18 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[codeproject]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=220</guid>
		<description><![CDATA[Silverlight is moving fast. Really fast. The recent MIX09 conference saw the release of Silverlight 3 (Beta) and also a new release of the Silverlight Toolkit. All this change is making it hard for us bloggers to keep up! Just over a month ago I posted an article on this blog about how to add [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2009%252F03%252Fadding-a-location-crosshair-to-silverlight-charts-again%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Adding%20a%20Location%20Crosshair%20to%20Silverlight%20charts%20%28again%21%29%20%23%22%20%7D);"></div>
<p>Silverlight is moving fast. Really fast. The recent <a href="http://live.visitmix.com/">MIX09</a> conference saw the release of Silverlight 3 (Beta) and also a new release of the <a href="http://blogs.msdn.com/delay/archive/2009/03/19/silverlight-charting-is-faster-and-better-than-ever-silverlight-toolkit-march-09-release-now-available.aspx">Silverlight Toolkit</a>. All this change is making it hard for us bloggers to keep up!</p>
<p>Just over a month ago I posted an article on this blog about how to add <a href="http://www.scottlogic.co.uk/blog/colin/2009/02/adding-a-location-crosshair-to-silverlight-charts/">a location crosshair</a> to the Silverlight Toolkit Charts. This blog post briefly discusses how the charts have changed with the release last week, and updates the code accordingly.</p>
<p>If you want to know how the general approach works, I would recommend reading the <a href="http://www.scottlogic.co.uk/blog/colin/2009/02/adding-a-location-crosshair-to-silverlight-charts/">previous blog post</a>, this post serves as an update and discussion on how the chart template has changed.</p>
<p>There have been a number of minor changes to the charts that affect my previous implementation, including a change of namespace and orientation type on the chart axes. However, the biggest change is in the template of the chart control itself. Previously the chart template was structured via a Grid as shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;charting:Chart&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;ChartArea&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding ChartAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- ##### chart control adds column / row definitions and axes here #### --&gt;</span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PlotArea&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding PlotAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!-- the standard chart template components --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;GridLinesContainer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;SeriesContainer&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;#FF919191&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!-- ##### I added cross hair and legend here #### --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>After loading the template the chart adds the axes and the appropriate column / row definitions. This leaves us free to add new visual content withing the &#8216;PlotArea&#8217; grid. Inspecting the visual tree, with <a href="http://silverlightspy.com/silverlightspy/">Silverlight Spy</a>, it look like the following:</p>
<p><a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/03/visualtree-before.png"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/03/visualtree-before.png" alt="visualtree-before" title="visualtree-before" width="292" height="220" class="alignnone size-full wp-image-221" /></a></p>
<p>The content I added in order to construct a crosshair and legend are highlighted in red.</p>
<p>The March release of the Silverlight toolkit modifies the way in which axes are added to the chart by the introduction of a new layout panel, the EdgePanel (think DockPanel!). This panel allows you to locate (or dock) elements at one of the four edges of a panel or the panel centre. The modified control template is show below:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;charting:Chart&quot;</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;ChartTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;ChartRoot&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding PlotAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chartingprimitives:EdgePanel</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;ChartArea&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding ChartAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>                                   
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Canvas.ZIndex</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding PlotAreaStyle}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">Canvas.ZIndex</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;#FF919191&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!-- ##### I added cross hair and legend here #### --&gt;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!-- ##### chart control adds column / row definitions and axes here #### --&gt;</span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chartingprimitives:EdgePanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>I have indicated the location where I add my own visual content and also the location where the chart control adds the axes. The resulting visual tree is shown below:</p>
<p><a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/03/visualtree-after.png"><img src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/03/visualtree-after.png" alt="visualtree-after" title="visualtree-after" width="340" height="256" class="alignnone size-full wp-image-223" /></a></p>
<p>The significant difference here is that all the components of our chart are contained within the same EdgePanel, with their location dictated by their EdgePanel.Edge property. One problem this does introduce for us is that of Z-ordering, previously our additional content was top of the stack, now it sits somewhere in between. Fortunately EdgePanel honours the Canvas.ZIndex attached property allowing us to push our content to the top. The modified template is given below in full:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;charting:Chart&quot;</span> <span style="color: #000066;">x:Key</span>=<span style="color: #ff0000;">&quot;ChartTemplate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;ChartRoot&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding PlotAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chartingprimitives:EdgePanel</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;ChartArea&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding ChartAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>                                   
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Canvas.ZIndex</span>=<span style="color: #ff0000;">&quot;-1&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding PlotAreaStyle}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">Canvas.ZIndex</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;#FF919191&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!-- a location crosshair --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;CrosshairContainer&quot;</span> <span style="color: #000066;">Canvas.ZIndex</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Background</span>=<span style="color: #ff0000;">&quot;Transparent&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">MouseMove</span>=<span style="color: #ff0000;">&quot;CrosshairContainer_MouseMove&quot;</span> <span style="color: #000066;">MouseEnter</span>=<span style="color: #ff0000;">&quot;CrosshairContainer_MouseEnter&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">MouseLeave</span>=<span style="color: #ff0000;">&quot;CrosshairContainer_MouseLeave&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Crosshair&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Line</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Vertical&quot;</span> <span style="color: #000066;">X1</span>=<span style="color: #ff0000;">&quot;{Binding Path=X}&quot;</span> <span style="color: #000066;">Y1</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">X2</span>=<span style="color: #ff0000;">&quot;{Binding Path=X}&quot;</span> <span style="color: #000066;">Y2</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">Stroke</span>=<span style="color: #ff0000;">&quot;Black&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Line</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span> <span style="color: #000066;">X1</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">Y1</span>=<span style="color: #ff0000;">&quot;{Binding Path=Y}&quot;</span> <span style="color: #000066;">X2</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">Y2</span>=<span style="color: #ff0000;">&quot;{Binding Path=Y}&quot;</span> <span style="color: #000066;">Stroke</span>=<span style="color: #ff0000;">&quot;Black&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!-- a location 'legend' --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">Canvas.ZIndex</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;LocationIndicator&quot;</span> <span style="color: #000066;">Visibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{StaticResource LocationLegendStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Location: &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Key,</span>
<span style="color: #009900;">                                Converter={StaticResource FormattingConverter}, ConverterParameter=hh:mm:ss}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;, &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Value,</span>
<span style="color: #009900;">                                Converter={StaticResource FormattingConverter}, ConverterParameter=0.00}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chartingprimitives:EdgePanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>One more subtle point, the event handlers for MouseMove, MouseLeave etc.. when associated with a Grid only work if the background is not null, hence the need for a transparent background. I have no idea why, believe me &#8230; it just works!</p>
<p>One final important change is the method used to translate points from screen coordinates into a position within the chart coordinate system. Previously I used a method called <code>GetPlotAreaCoordinateValueRange</code> on the &#8216;hidden <code>IRangeAxis</code> interface. This has now been renamed to <code>GetValueAtPosition</code> and returns and takes a <code>UnitValue</code> type as its input (presumably for API consistency with the pie charts). Here is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Transforms the supplied position on the plot area grid into a point within</span>
<span style="color: #008080; font-style: italic;">/// the plot area coordinate system</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> KeyValuePair<span style="color: #008000;">&lt;</span>DateTime, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span> GetPlotAreaCoordinates<span style="color: #008000;">&#40;</span>Point position<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    IComparable yAxisHit <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>IRangeAxis<span style="color: #008000;">&#41;</span>YAxis<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValueAtPosition</span><span style="color: #008000;">&#40;</span>
        <span style="color: #008000;">new</span> UnitValue<span style="color: #008000;">&#40;</span>PlotArea<span style="color: #008000;">.</span><span style="color: #0000FF;">ActualHeight</span> <span style="color: #008000;">-</span> position<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span>, Unit<span style="color: #008000;">.</span><span style="color: #0000FF;">Pixels</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    IComparable xAxisHit <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>IRangeAxis<span style="color: #008000;">&#41;</span>XAxis<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetValueAtPosition</span><span style="color: #008000;">&#40;</span>
        <span style="color: #008000;">new</span> UnitValue<span style="color: #008000;">&#40;</span>position<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span>, Unit<span style="color: #008000;">.</span><span style="color: #0000FF;">Pixels</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> KeyValuePair<span style="color: #008000;">&lt;</span>DateTime, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">&#41;</span>xAxisHit, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>yAxisHit<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>With these changes in place, our crosshair is fully functional once more:</p>
<div id="slPluginHost"> <object id="SilverlightPlugin" width="400" height="300" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/03/sllinechartcrosshair.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<p>&#8230; until the next release of the toolkit <img src='http://www.scottlogic.co.uk/blog/colin/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>You can download the project sourcecode: <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/03/sllinechartcrosshairupdated.zip'>sllinechartcrosshairupdated.zip</a>.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2009/03/adding-a-location-crosshair-to-silverlight-charts-again/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Adding a Location Crosshair to Silverlight Charts</title>
		<link>http://www.scottlogic.co.uk/blog/colin/2009/02/adding-a-location-crosshair-to-silverlight-charts/</link>
		<comments>http://www.scottlogic.co.uk/blog/colin/2009/02/adding-a-location-crosshair-to-silverlight-charts/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 14:33:32 +0000</pubDate>
		<dc:creator>Colin Eberhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[charts]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.scottlogic.co.uk/blog/colin/?p=99</guid>
		<description><![CDATA[UPDATE &#8211; The March09 update of the Silverlight toolkit is incompatible with the code detailed below. For an up-to-date version see the following blog post. This blog post describes how to add a location crosshair to your Silverlight charts as shown below: The chart itself is rendered using the charting component of the recently release [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_light-green" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.scottlogic.co.uk%252Fblog%252Fcolin%252F2009%252F02%252Fadding-a-location-crosshair-to-silverlight-charts%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Adding%20a%20Location%20Crosshair%20to%20Silverlight%20Charts%20%23%22%20%7D);"></div>
<div style="background-color:#fdd; margin:5px; padding:5px; border: solid 2px red;"><b>UPDATE</b> &#8211; The March09 update of the Silverlight toolkit is incompatible with the code detailed below. For an up-to-date version see the <a href="http://www.scottlogic.co.uk/blog/colin/2009/03/adding-a-location-crosshair-to-silverlight-charts-again/">following blog post</a>.</div>
<p>This blog post describes how to add a location crosshair to your Silverlight charts as shown below:</p>
<div id="slPluginHost"> <object id="SilverlightPlugin" width="400" height="300" data="data:application/x-silverlight," type="application/x-silverlight-2" ><param name="source" value="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/02/sllinechartcrosshair1.xap"/><a href="http://go.microsoft.com/fwlink/?LinkID=124807"  style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object></div>
<p>The chart itself is rendered using the charting component of the recently release <a href="http://www.codeplex.com/Silverlight">Silverlight Toolkit</a>. Creating and displaying a simple line chart is as simple as referencing the correct silverlight toolkit namespaces and placing a chart with an associated lineseries into the XAML for your page:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;charting:Chart</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Chart&quot;</span> <span style="color: #000066;">PlotAreaStyle</span>=<span style="color: #ff0000;">&quot;{StaticResource PlotAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;charting:LineSeries</span></span>
<span style="color: #009900;">		<span style="color: #000066;">IndependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Path=Key}&quot;</span></span>
<span style="color: #009900;">		<span style="color: #000066;">DependentValueBinding</span>=<span style="color: #ff0000;">&quot;{Binding Path=Value}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/charting:Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In this example, the data is provided in the form of an XML file as shown in the snippet below:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;history</span> <span style="color: #000066;">generated</span>=<span style="color: #ff0000;">&quot;2009/02/03 10:51:02 GMT+0000&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataPoints<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataPoint</span> <span style="color: #000066;">date</span>=<span style="color: #ff0000;">&quot;2009/02/03 08:01:00 GMT+0000&quot;</span> <span style="color: #000066;">change</span>=<span style="color: #ff0000;">&quot;21.61&quot;</span> <span style="color: #000066;">changePercent</span>=<span style="color: #ff0000;">&quot;0.36&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;6073.99&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataPoint</span> <span style="color: #000066;">date</span>=<span style="color: #ff0000;">&quot;2009/02/03 08:02:45 GMT+0000&quot;</span> <span style="color: #000066;">change</span>=<span style="color: #ff0000;">&quot;16.11&quot;</span> <span style="color: #000066;">changePercent</span>=<span style="color: #ff0000;">&quot;0.27&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;6068.49&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataPoint</span> <span style="color: #000066;">date</span>=<span style="color: #ff0000;">&quot;2009/02/03 10:50:45 GMT+0000&quot;</span> <span style="color: #000066;">change</span>=<span style="color: #ff0000;">&quot;0.4&quot;</span> <span style="color: #000066;">changePercent</span>=<span style="color: #ff0000;">&quot;0.01&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;6052.78&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataPoints<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/history<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This data shows the performance of the FTSE 100 index on a relatively uneventful morning. The XML file is read using LINQ to XML into a collection of KeyValuePairs. The LineSeries&#8217; ItemsSource is set to the result of this query, with the bindings in the above XAML binding the Key and Value properties of each KeyValuePair instance.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> LineSeries LineSeries
<span style="color: #008000;">&#123;</span>
    get
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">&#41;</span>Chart<span style="color: #008000;">.</span><span style="color: #0000FF;">Series</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">public</span> Page<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    InitializeComponent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    XDocument doc <span style="color: #008000;">=</span> XDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;chartData.xml&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    var elements <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">from</span> dataPoint <span style="color: #0600FF; font-weight: bold;">in</span> doc<span style="color: #008000;">.</span><span style="color: #0000FF;">Descendants</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;dataPoint&quot;</span><span style="color: #008000;">&#41;</span>                           
                   <span style="color: #0600FF; font-weight: bold;">select</span> <span style="color: #008000;">new</span> KeyValuePair<span style="color: #008000;">&lt;</span>DateTime, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span>
                   <span style="color: #008000;">&#40;</span>
                       DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>dataPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;date&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">19</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>,
                       <span style="color: #6666cc; font-weight: bold;">Double</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span>dataPoint<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;value&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span>
                   <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    LineSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">=</span> elements<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This results in the following (rather ugly!) chart:</p>
<p><a href="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/02/ftse100.png"><img class="alignnone size-full wp-image-107" title="ftse100" src="http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/02/ftse100.png" alt="ftse100" width="400" height="167" /></a></p>
<p>Whilst the background fade effect and line series datapoints can be modified by styling the chart, the removal of unwanted elements such as the legend require us to delve into the the Chart&#8217;s control template. The modified control template is given below:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;charting:Chart.Template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ControlTemplate</span> <span style="color: #000066;">TargetType</span>=<span style="color: #ff0000;">&quot;charting:Chart&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;ChartArea&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding ChartAreaStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!-- NOTE: the chart legend and title have been removed --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;PlotArea&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{TemplateBinding PlotAreaStyle}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">MouseMove</span>=<span style="color: #ff0000;">&quot;PlotArea_MouseMove&quot;</span> <span style="color: #000066;">MouseEnter</span>=<span style="color: #ff0000;">&quot;PlotArea_MouseEnter&quot;</span> <span style="color: #000066;">MouseLeave</span>=<span style="color: #ff0000;">&quot;PlotArea_MouseLeave&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!-- the standard chart template components --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;GridLinesContainer&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">x:Name</span>=<span style="color: #ff0000;">&quot;SeriesContainer&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">BorderBrush</span>=<span style="color: #ff0000;">&quot;#FF919191&quot;</span> <span style="color: #000066;">BorderThickness</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!-- a location crosshair --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Grid</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Crosshair&quot;</span> <span style="color: #000066;">Visibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Line</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Vertical&quot;</span> <span style="color: #000066;">X1</span>=<span style="color: #ff0000;">&quot;{Binding Path=X}&quot;</span> <span style="color: #000066;">Y1</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">X2</span>=<span style="color: #ff0000;">&quot;{Binding Path=X}&quot;</span> <span style="color: #000066;">Y2</span>=<span style="color: #ff0000;">&quot;250&quot;</span> <span style="color: #000066;">Stroke</span>=<span style="color: #ff0000;">&quot;Black&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Line</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span> <span style="color: #000066;">X1</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">Y1</span>=<span style="color: #ff0000;">&quot;{Binding Path=Y}&quot;</span> <span style="color: #000066;">X2</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">Y2</span>=<span style="color: #ff0000;">&quot;{Binding Path=Y}&quot;</span> <span style="color: #000066;">Stroke</span>=<span style="color: #ff0000;">&quot;Black&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!-- a location 'legend' --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Border</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;LocationIndicator&quot;</span> <span style="color: #000066;">Visibility</span>=<span style="color: #ff0000;">&quot;Collapsed&quot;</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;{StaticResource LocationLegendStyle}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StackPanel</span> <span style="color: #000066;">Orientation</span>=<span style="color: #ff0000;">&quot;Horizontal&quot;</span> <span style="color: #000066;">Margin</span>=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Location: &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Key}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;, &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextBlock</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;{Binding Path=Value}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StackPanel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Border<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Grid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ControlTemplate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/charting:Chart.Template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>In the above template you can see a couple of Grids, one named GridLinesContainer, and the other names SeriesContainer. When constructing the chart, the chart control will navigate the visual tree constructed from its control template to find elements of these names. It will then add the grid lines and series to these containers accordingly. This gives us the freedom to modify the chart&#8217;s control template whilst still allowing it to function normally. In the above template I have added two new elements, a cross hair and a location indicator. I have also added handlers for a few of the mouse events on the plot area.</p>
<p>The mouse move event handler in the code behind finds the current mouse position within the PlotArea grid. Firstly, the coordinates of this point are found within the chart coordinate system (more on this later), following this, the DataContexts for the Crosshair and PlotArea are set to the mouse position and location within the chart coordinate system respectively. Looking in the above XAML we can see that the Crosshair contains a pair of lines which are bound to the X and Y properties of their DataContext, ensuring that the two lines intersect at the current mouse location. The LocationIndicator will inherit the PlotArea&#8217;s DataContext, allowing it to output the current location in the chart coordinate system.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> PlotArea_MouseMove<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, MouseEventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>LineSeries<span style="color: #008000;">.</span><span style="color: #0000FF;">ItemsSource</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
    Point mousePos <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPosition</span><span style="color: #008000;">&#40;</span>PlotArea<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    KeyValuePair<span style="color: #008000;">&lt;</span>DateTime, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span> crosshairLocation <span style="color: #008000;">=</span> GetPlotAreaCoordinates<span style="color: #008000;">&#40;</span>mousePos<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    PlotArea<span style="color: #008000;">.</span><span style="color: #0000FF;">DataContext</span> <span style="color: #008000;">=</span> crosshairLocation<span style="color: #008000;">;</span>
    Crosshair<span style="color: #008000;">.</span><span style="color: #0000FF;">DataContext</span> <span style="color: #008000;">=</span> mousePos<span style="color: #008000;">;</span>
    PlotArea<span style="color: #008000;">.</span><span style="color: #0000FF;">Cursor</span> <span style="color: #008000;">=</span> Cursors<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">protected</span> Grid PlotArea
<span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> ChartArea<span style="color: #008000;">.</span><span style="color: #0000FF;">FindName</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PlotArea&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Grid<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">protected</span> Grid Crosshair
<span style="color: #008000;">&#123;</span>
    get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> ChartArea<span style="color: #008000;">.</span><span style="color: #0000FF;">FindName</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Crosshair&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Grid<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">protected</span> Grid ChartArea
<span style="color: #008000;">&#123;</span>
    get
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// chart area is within a different namescope to this page, therefore</span>
        <span style="color: #008080; font-style: italic;">// we must navigate the visual tree to locate it</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> VisualTreeHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">GetChild</span><span style="color: #008000;">&#40;</span>Chart, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Grid<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>One thing worth noting in the above code is that way in which the PlotArea and Crosshair elements are located. Usually it is possible to simply name elements within your XAML using their Name attribute then refer to them directly in the code-behind or locate them via the <a href="msdn.microsoft.com/en-us/library/bb979952(VS.95).aspx">DependencyObject.FindName</a> method. However, FindName relies on the named element being in the same namescope. Control template are in a different namescope to the XAML page which they are defined within, therefore we have to navigate the visual tree to find the root element of the chart control, then invoke FindName from there. See the MSDN page on <a href="http://msdn.microsoft.com/en-us/library/cc189026(VS.95).aspx#NamescopesinTemplates">XAML namescopes</a> for more details.</p>
<p>The GetPlotAreaCoordinates method is given below:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> KeyValuePair<span style="color: #008000;">&lt;</span>DateTime, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span> GetPlotAreaCoordinates<span style="color: #008000;">&#40;</span>Point position<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    Range<span style="color: #008000;">&lt;</span>IComparable<span style="color: #008000;">&gt;</span> yAxisHit <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>IRangeAxis<span style="color: #008000;">&#41;</span>YAxis<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPlotAreaCoordinateValueRange</span><span style="color: #008000;">&#40;</span>PlotArea<span style="color: #008000;">.</span><span style="color: #0000FF;">Height</span> <span style="color: #008000;">-</span> position<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Range<span style="color: #008000;">&lt;</span>IComparable<span style="color: #008000;">&gt;</span> xAxisHit <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>IRangeAxis<span style="color: #008000;">&#41;</span>XAxis<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetPlotAreaCoordinateValueRange</span><span style="color: #008000;">&#40;</span>position<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> KeyValuePair<span style="color: #008000;">&lt;</span>DateTime, <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">&#41;</span>xAxisHit<span style="color: #008000;">.</span><span style="color: #0000FF;">Minimum</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>yAxisHit<span style="color: #008000;">.</span><span style="color: #0000FF;">Minimum</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The silverlight chart axes actually provides methods which can be used to translate from screen coordinates to chart coordinates via the IRangeAxis interface, however they are hidden by <a href="http://msdn.microsoft.com/en-us/library/aa288461(VS.71).aspx">explicit interface implementation</a> of these interface methods by the concrete axis classes. It is a shame that such useful methods are hidden! I have never really seen the value of explicit interface implementation.</p>
<p>In conclusion, this blog post has shown how simple it is to add a crosshair to your silverlight linecharts. What I personally find interesting is the way in which you can not only customise the appearance of Silverlight (and WPF) controls, but also add behaviour without the need to subclass the controls themselves. I think that this makes life easier for the users of Silverlight/WPF controls, in that they can use the same techniques to extend any control rather than relying on the control having built in extension points (it is often a source of frustration when developing with Windows Forms (or similar technologies) when you wish to customise some aspect of an existing control, however the control author has not provided events, or virtual methods for this purpose). It also of course makes life easier for the control developer in that they do not have to spend so much time thinking about how their control might be extended and adapted by its users. </p>
<p>You can download a visual studio project with the code from this blog post, <a href='http://www.scottlogic.co.uk/blog/colin/wp-content/uploads/2009/02/sllinechartcrosshair.zip'>sllinechartcrosshair.zip</a>.</p>
<p>Regards, Colin E.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.scottlogic.co.uk/blog/colin/2009/02/adding-a-location-crosshair-to-silverlight-charts/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

