<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Felice Pollano Blog - Charting</title>
    <link>http://www.felicepollano.com/</link>
    <description>The official Fatica Labs Blog!</description>
    <language>en-us</language>
    <copyright>Felice Pollano</copyright>
    <lastBuildDate>Wed, 25 May 2011 20:49:37 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>felice@felicepollano.com</managingEditor>
    <webMaster>felice@felicepollano.com</webMaster>
    <item>
      <trackback:ping>http://www.felicepollano.com/Trackback.aspx?guid=493280d8-4de2-46c4-9fc2-6055f46329ae</trackback:ping>
      <pingback:server>http://www.felicepollano.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.felicepollano.com/PermaLink.aspx?guid=493280d8-4de2-46c4-9fc2-6055f46329ae</pingback:target>
      <dc:creator>Felice Pollano</dc:creator>
      <wfw:comment>http://www.felicepollano.com/CommentView.aspx?guid=493280d8-4de2-46c4-9fc2-6055f46329ae</wfw:comment>
      <wfw:commentRss>http://www.felicepollano.com/SyndicationService.asmx/GetEntryCommentsRss?guid=493280d8-4de2-46c4-9fc2-6055f46329ae</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In  the <a href="http://www.felicepollano.com/2011/05/15/MultipleChartsWithWPFDynamicDataDisplay.aspx" target="_blank">previous
sample</a> we shown how to present multiple chart by keeping them aligned in order
to be comparable on the horizontal axis by using the <strong><em>WidthSpring</em></strong> feature.
But D3 charting can automatically pan and zoom ( both by rect zoom by pressing control
and left dragging the mouse on the chart, or by the wheel ) and in this case we loose
the axis synchronization. Here below the undesired behavior:
</p>
        <table border="1" cellpadding="2" cellspacing="0" width="579">
          <tbody>
            <tr>
              <td valign="top" width="358">
                <a href="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_2.png">
                  <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_thumb.png" border="0" height="252" width="334" />
                </a>
              </td>
              <td valign="top" width="219">
On the left we see the top chart zoomed, the other ones show the horizontal range
thus there is no more relation among the three charts.</td>
            </tr>
          </tbody>
        </table>
        <p>
So we create an attached property as below:
</p>
        <pre class="code">
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">ChartPlotter </span>
          <span style="color: red">x</span>
          <span style="color: blue">:</span>
          <span style="color: red">Name</span>
          <span style="color: blue">="price" </span>
          <span style="color: red">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: red">SynchroVisible.Axis</span>
          <span style="color: blue">="X" </span>
          <span style="color: red">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: red">SynchroVisible.With</span>
          <span style="color: blue">="{</span>
          <span style="color: #a31515">Binding </span>
          <span style="color: red">ElementName</span>
          <span style="color: blue">=volume}"
…&gt;</span>
        </pre>
        <pre class="code"> </pre>
        <p>
by applying this property we choose which axis synchronize ( X in the example, but
can be Y or XY ) and which chart keep synchronized with, in this case we bind with
the chart named “volume”. By repeating the property two chart by two chart:
</p>
        <pre class="code">
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">ChartPlotter </span>
          <span style="color: red">x</span>
          <span style="color: blue">:</span>
          <span style="color: red">Name</span>
          <span style="color: blue">="volume" </span>
          <span style="color: red">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: red">SynchroVisible.Axis</span>
          <span style="color: blue">="X" </span>
          <span style="color: red">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: red">SynchroVisible.With</span>
          <span style="color: blue">="{</span>
          <span style="color: #a31515">Binding </span>
          <span style="color: red">ElementName</span>
          <span style="color: blue">=ma}"
…</span>
          <span style="color: blue">&gt; </span>
        </pre>
        <pre class="code">
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">ChartPlotter </span>
          <span style="color: red">x</span>
          <span style="color: blue">:</span>
          <span style="color: red">Name</span>
          <span style="color: blue">="ma" </span>
          <span style="color: red">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: red">SynchroVisible.Axis</span>
          <span style="color: blue">="X" </span>
          <span style="color: red">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: red">SynchroVisible.With</span>
          <span style="color: blue">="{</span>
          <span style="color: #a31515">Binding </span>
          <span style="color: red">ElementName</span>
          <span style="color: blue">=price}"
…</span>
          <span style="color: blue">&gt; </span>
        </pre>
        <p>
 
</p>
        <p>
so we achieve this interesting result <strong>without any code behind</strong>:
</p>
        <table border="1" cellpadding="2" cellspacing="0" width="544">
          <tbody>
            <tr>
              <td valign="top" width="200">
                <a href="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_4.png">
                  <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_thumb_1.png" border="0" height="259" width="306" />
                </a>
              </td>
              <td valign="top" width="342">
This is the result after panning the chart ( by dragging the mouse pointer into the
chart area in any of the three chart ) as you can see the other chart properly follow…</td>
            </tr>
            <tr>
              <td valign="top" width="200">
                <a href="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_6.png">
                  <img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_thumb_2.png" border="0" height="259" width="305" />
                </a>
              </td>
              <td valign="top" width="342">
The same apply if we zoom on the chart area ( by pressing ctrl while dragging, or
by the mouse wheel ) other chart amplify the resolution on the synchronized axis and
the start position accordingly.</td>
            </tr>
          </tbody>
        </table>
        <p>
Check out the source for this example <a href="https://bitbucket.org/Felice_Pollano/d3redux/get/b2cb81b28116.zip" target="_blank">here</a>.
</p>
        <img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=493280d8-4de2-46c4-9fc2-6055f46329ae" />
      </body>
      <title>Dynamic Data Display: synchronize axis</title>
      <guid isPermaLink="false">http://www.felicepollano.com/PermaLink.aspx?guid=493280d8-4de2-46c4-9fc2-6055f46329ae</guid>
      <link>http://www.felicepollano.com/2011/05/25/DynamicDataDisplaySynchronizeAxis.aspx</link>
      <pubDate>Wed, 25 May 2011 20:49:37 GMT</pubDate>
      <description>&lt;p&gt;
In&amp;nbsp; the &lt;a href="http://www.felicepollano.com/2011/05/15/MultipleChartsWithWPFDynamicDataDisplay.aspx" target="_blank"&gt;previous
sample&lt;/a&gt; we shown how to present multiple chart by keeping them aligned in order
to be comparable on the horizontal axis by using the &lt;strong&gt;&lt;em&gt;WidthSpring&lt;/em&gt;&lt;/strong&gt; feature.
But D3 charting can automatically pan and zoom ( both by rect zoom by pressing control
and left dragging the mouse on the chart, or by the wheel ) and in this case we loose
the axis synchronization. Here below the undesired behavior:
&lt;/p&gt;
&lt;table border="1" cellpadding="2" cellspacing="0" width="579"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="358"&gt;
&lt;a href="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_thumb.png" border="0" height="252" width="334"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top" width="219"&gt;
On the left we see the top chart zoomed, the other ones show the horizontal range
thus there is no more relation among the three charts.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
So we create an attached property as below:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ChartPlotter &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="price" &lt;/span&gt;&lt;span style="color: red"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SynchroVisible.Axis&lt;/span&gt;&lt;span style="color: blue"&gt;="X" &lt;/span&gt;&lt;span style="color: red"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SynchroVisible.With&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;ElementName&lt;/span&gt;&lt;span style="color: blue"&gt;=volume}"
…&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;
by applying this property we choose which axis synchronize ( X in the example, but
can be Y or XY ) and which chart keep synchronized with, in this case we bind with
the chart named “volume”. By repeating the property two chart by two chart:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ChartPlotter &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="volume" &lt;/span&gt;&lt;span style="color: red"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SynchroVisible.Axis&lt;/span&gt;&lt;span style="color: blue"&gt;="X" &lt;/span&gt;&lt;span style="color: red"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SynchroVisible.With&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;ElementName&lt;/span&gt;&lt;span style="color: blue"&gt;=ma}"
…&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ChartPlotter &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="ma" &lt;/span&gt;&lt;span style="color: red"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SynchroVisible.Axis&lt;/span&gt;&lt;span style="color: blue"&gt;="X" &lt;/span&gt;&lt;span style="color: red"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;SynchroVisible.With&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;ElementName&lt;/span&gt;&lt;span style="color: blue"&gt;=price}"
…&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
so we achieve this interesting result &lt;strong&gt;without any code behind&lt;/strong&gt;:
&lt;/p&gt;
&lt;table border="1" cellpadding="2" cellspacing="0" width="544"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;a href="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_4.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_thumb_1.png" border="0" height="259" width="306"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top" width="342"&gt;
This is the result after panning the chart ( by dragging the mouse pointer into the
chart area in any of the three chart ) as you can see the other chart properly follow…&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;a href="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_6.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/677f9a9a9e6b_12B29/image_thumb_2.png" border="0" height="259" width="305"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td valign="top" width="342"&gt;
The same apply if we zoom on the chart area ( by pressing ctrl while dragging, or
by the mouse wheel ) other chart amplify the resolution on the synchronized axis and
the start position accordingly.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
Check out the source for this example &lt;a href="https://bitbucket.org/Felice_Pollano/d3redux/get/b2cb81b28116.zip" target="_blank"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=493280d8-4de2-46c4-9fc2-6055f46329ae" /&gt;</description>
      <comments>http://www.felicepollano.com/CommentView.aspx?guid=493280d8-4de2-46c4-9fc2-6055f46329ae</comments>
      <category>Charting</category>
      <category>D3</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.felicepollano.com/Trackback.aspx?guid=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386</trackback:ping>
      <pingback:server>http://www.felicepollano.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.felicepollano.com/PermaLink.aspx?guid=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386</pingback:target>
      <dc:creator>Felice Pollano</dc:creator>
      <wfw:comment>http://www.felicepollano.com/CommentView.aspx?guid=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386</wfw:comment>
      <wfw:commentRss>http://www.felicepollano.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This post dig a little more <a href="http://www.felicepollano.com/2011/05/15/MultipleChartsWithWPFDynamicDataDisplay.aspx" target="_blank">into
this blog post code</a> about working with and customizing Dynamic Data Display charting.
Since the default bar chart implementation does not work, it’s easy to create our
own by simply deriving one chart from <em><strong>PointGraphBase</strong></em>.
</p>
        <p>
 
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">BarChart </span>: <span style="color: #2b91af">PointsGraphBase </span>{</pre>
        <pre class="code">…</pre>
        <p align="justify">
          <font face="Verdana">Then we define the classical bounch of dependencies properties
which code is not so fancy to see: Thickness, Stroke and fill brush, and so on. </font>The
core function we must implement is <strong>OnRenderCore</strong>. Let’s see how:
</p>
        <div align="justify">
          <pre class="code">
            <span style="color: blue">protected override
void </span>OnRenderCore(System.Windows.Media.<span style="color: #2b91af">DrawingContext </span>dc, <span style="color: #2b91af">RenderState </span>state)
{ <span style="color: blue">if </span>(DataSource == <span style="color: blue">null</span>) <span style="color: blue">return</span>; <span style="color: blue">var </span>transform
= Plotter2D.Viewport.Transform; <span style="color: #2b91af">DataRect </span>bounds
= <span style="color: #2b91af">DataRect</span>.Empty; <span style="color: blue">using </span>(<span style="color: #2b91af">IPointEnumerator </span>enumerator
= DataSource.GetEnumerator(GetContext())) { <span style="color: #2b91af">Point </span>point
= <span style="color: blue">new </span><span style="color: #2b91af">Point</span>(); <span style="color: blue">while </span>(enumerator.MoveNext())
{ enumerator.GetCurrent(<span style="color: blue">ref </span>point); enumerator.ApplyMappings(<span style="color: blue">this</span>); <span style="color: #2b91af">Point </span>zero
= <span style="color: blue">new </span><span style="color: #2b91af">Point</span>(point.X,
0); <span style="color: #2b91af">Point </span>screenPoint = point.DataToScreen(transform); <span style="color: #2b91af">Point </span>screenZero
= zero.DataToScreen(transform); <span style="color: blue">double </span>height = screenPoint.Y
- screenZero.Y; <span style="color: blue">if </span>(height &gt;= 0) { dc.DrawRectangle(Fill, <span style="color: blue">new </span><span style="color: #2b91af">Pen</span>(Stroke,
StrokeThickness)</pre>
        </div>
        <blockquote>
          <pre class="code">, <span style="color: blue">new </span><span style="color: #2b91af">Rect</span>(screenPoint.X
- BarWidth / 2, screenZero.Y, BarWidth, height)); } <span style="color: blue">else </span>{
dc.DrawRectangle(Fill, <span style="color: blue">new </span><span style="color: #2b91af">Pen</span>(Stroke,
StrokeThickness), </pre>
          <pre class="code">
            <span style="color: blue">new </span>
            <span style="color: #2b91af">Rect</span>(screenPoint.X
- BarWidth / 2, screenPoint.Y, BarWidth, -height)); } bounds = <span style="color: #2b91af">DataRect</span>.Union(bounds,
point); } } <span style="color: #2b91af">Viewport2D</span>.SetContentBounds(<span style="color: blue">this</span>,
bounds); } </pre>
        </blockquote>
        <div align="justify">So nothing really special, just some key point:
</div>
        <div align="justify"> 
</div>
        <ul>
          <li>
            <div align="justify">
              <strong>ApplyMapping</strong> is the function who map the model
coordinates into the graphical X-Y coordinates.
</div>
          </li>
          <li>
            <div align="justify">
              <strong>DataToScreen/ScreenToData</strong> are the (extension)
method who maps from world coordinates to screen coordinates.
</div>
          </li>
        </ul>
        <div align="justify"> 
</div>
        <div align="justify">The other code is just drawing the rectangles for each point
at a certain bar width, and we obtain this:
</div>
        <div align="justify">
          <a href="http://www.felicepollano.com/public/Windows-Live-Writer/WPF-Dynamic-data-Display-how-to-create-a_13D21/image_2.png">
            <img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/WPF-Dynamic-data-Display-how-to-create-a_13D21/image_thumb.png" width="244" height="151" />
          </a>
        </div>
        <div align="justify"> 
</div>
        <p>
 
</p>
        <p>
 
</p>
        <p>
As you can probably see, line are anti-aliased even if we specified <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.snapstodevicepixels.aspx" target="_blank">SnapToDevicePixels</a>.
This is due to the fact that <a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.snapstodevicepixels.aspx" target="_blank">SnapToDevicePixels</a> does
not work when we manually draw onto a DrawingContext. If we want to remove this we
need to <a href="http://stackoverflow.com/questions/6018106/wpf-drawingcontext-seems-ignore-snaptodevicepixels/6018437#comment-6969009" target="_blank">follow
these instructions</a> and create some GudelineSet to force WPF align to physical
bytes.
</p>
        <img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386" />
      </body>
      <title>WPF Dynamic data Display: how to create a bar chart</title>
      <guid isPermaLink="false">http://www.felicepollano.com/PermaLink.aspx?guid=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386</guid>
      <link>http://www.felicepollano.com/2011/05/17/WPFDynamicDataDisplayHowToCreateABarChart.aspx</link>
      <pubDate>Tue, 17 May 2011 20:50:48 GMT</pubDate>
      <description>&lt;p&gt;
This post dig a little more &lt;a href="http://www.felicepollano.com/2011/05/15/MultipleChartsWithWPFDynamicDataDisplay.aspx" target="_blank"&gt;into
this blog post code&lt;/a&gt; about working with and customizing Dynamic Data Display charting.
Since the default bar chart implementation does not work, it’s easy to create our
own by simply deriving one chart from &lt;em&gt;&lt;strong&gt;PointGraphBase&lt;/strong&gt;&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BarChart &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;PointsGraphBase &lt;/span&gt;{&lt;/pre&gt;&lt;pre class="code"&gt;…&lt;/pre&gt;
&lt;p align="justify"&gt;
&lt;font face="Verdana"&gt;Then we define the classical bounch of dependencies properties
which code is not so fancy to see: Thickness, Stroke and fill brush, and so on. &lt;/font&gt;The
core function we must implement is &lt;strong&gt;OnRenderCore&lt;/strong&gt;. Let’s see how:
&lt;/p&gt;
&lt;div align="justify"&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;protected override
void &lt;/span&gt;OnRenderCore(System.Windows.Media.&lt;span style="color: #2b91af"&gt;DrawingContext &lt;/span&gt;dc, &lt;span style="color: #2b91af"&gt;RenderState &lt;/span&gt;state)
{ &lt;span style="color: blue"&gt;if &lt;/span&gt;(DataSource == &lt;span style="color: blue"&gt;null&lt;/span&gt;) &lt;span style="color: blue"&gt;return&lt;/span&gt;; &lt;span style="color: blue"&gt;var &lt;/span&gt;transform
= Plotter2D.Viewport.Transform; &lt;span style="color: #2b91af"&gt;DataRect &lt;/span&gt;bounds
= &lt;span style="color: #2b91af"&gt;DataRect&lt;/span&gt;.Empty; &lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IPointEnumerator &lt;/span&gt;enumerator
= DataSource.GetEnumerator(GetContext())) { &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;point
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(); &lt;span style="color: blue"&gt;while &lt;/span&gt;(enumerator.MoveNext())
{ enumerator.GetCurrent(&lt;span style="color: blue"&gt;ref &lt;/span&gt;point); enumerator.ApplyMappings(&lt;span style="color: blue"&gt;this&lt;/span&gt;); &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;zero
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(point.X,
0); &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screenPoint = point.DataToScreen(transform); &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screenZero
= zero.DataToScreen(transform); &lt;span style="color: blue"&gt;double &lt;/span&gt;height = screenPoint.Y
- screenZero.Y; &lt;span style="color: blue"&gt;if &lt;/span&gt;(height &amp;gt;= 0) { dc.DrawRectangle(Fill, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Pen&lt;/span&gt;(Stroke,
StrokeThickness)&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Rect&lt;/span&gt;(screenPoint.X
- BarWidth / 2, screenZero.Y, BarWidth, height)); } &lt;span style="color: blue"&gt;else &lt;/span&gt;{
dc.DrawRectangle(Fill, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Pen&lt;/span&gt;(Stroke,
StrokeThickness), &lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Rect&lt;/span&gt;(screenPoint.X
- BarWidth / 2, screenPoint.Y, BarWidth, -height)); } bounds = &lt;span style="color: #2b91af"&gt;DataRect&lt;/span&gt;.Union(bounds,
point); } } &lt;span style="color: #2b91af"&gt;Viewport2D&lt;/span&gt;.SetContentBounds(&lt;span style="color: blue"&gt;this&lt;/span&gt;,
bounds); } &lt;/pre&gt;&lt;/blockquote&gt; 
&lt;div align="justify"&gt;So nothing really special, just some key point:
&lt;/div&gt;
&lt;div align="justify"&gt;&amp;nbsp;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div align="justify"&gt;&lt;strong&gt;ApplyMapping&lt;/strong&gt; is the function who map the model
coordinates into the graphical X-Y coordinates.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div align="justify"&gt;&lt;strong&gt;DataToScreen/ScreenToData&lt;/strong&gt; are the (extension)
method who maps from world coordinates to screen coordinates.
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div align="justify"&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div align="justify"&gt;The other code is just drawing the rectangles for each point
at a certain bar width, and we obtain this:
&lt;/div&gt;
&lt;div align="justify"&gt;&lt;a href="http://www.felicepollano.com/public/Windows-Live-Writer/WPF-Dynamic-data-Display-how-to-create-a_13D21/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/WPF-Dynamic-data-Display-how-to-create-a_13D21/image_thumb.png" width="244" height="151"&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;&amp;nbsp;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As you can probably see, line are anti-aliased even if we specified &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.snapstodevicepixels.aspx" target="_blank"&gt;SnapToDevicePixels&lt;/a&gt;.
This is due to the fact that &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.snapstodevicepixels.aspx" target="_blank"&gt;SnapToDevicePixels&lt;/a&gt; does
not work when we manually draw onto a DrawingContext. If we want to remove this we
need to &lt;a href="http://stackoverflow.com/questions/6018106/wpf-drawingcontext-seems-ignore-snaptodevicepixels/6018437#comment-6969009" target="_blank"&gt;follow
these instructions&lt;/a&gt; and create some GudelineSet to force WPF align to physical
bytes.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386" /&gt;</description>
      <comments>http://www.felicepollano.com/CommentView.aspx?guid=b64308cb-b90f-4f5f-a5fc-e65ffa3ec386</comments>
      <category>Charting</category>
      <category>D3</category>
      <category>WPF</category>
    </item>
    <item>
      <trackback:ping>http://www.felicepollano.com/Trackback.aspx?guid=ea2fe80e-255d-4b37-9567-a8b5ca08ab47</trackback:ping>
      <pingback:server>http://www.felicepollano.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.felicepollano.com/PermaLink.aspx?guid=ea2fe80e-255d-4b37-9567-a8b5ca08ab47</pingback:target>
      <dc:creator>Felice Pollano</dc:creator>
      <wfw:comment>http://www.felicepollano.com/CommentView.aspx?guid=ea2fe80e-255d-4b37-9567-a8b5ca08ab47</wfw:comment>
      <wfw:commentRss>http://www.felicepollano.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ea2fe80e-255d-4b37-9567-a8b5ca08ab47</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p align="justify">
I was looking for a good open source charting library and I noticed that is a little
difficult to find something really useful and easy to use. I had a look at the <a href="http://blogs.msdn.com/b/delay/archive/2009/06/25/wpf-charting-it-s-official-june-2009-release-of-the-wpf-toolkit-is-now-available.aspx" target="_blank">WPF
Toolkit charting library</a>, a little old for sure, but look promising at a first
glance. Unfortunately it is not so easy to use, not brilliant in term of speed and
with some discutable behavior,  as for example the absence of a way to remove
the chart animation, or removing the fancy bullet in the line chart. By digging a
little deeper I found the <a href="http://dynamicdatadisplay.codeplex.com/" target="_blank">WPF
Dynamic Data Display</a></p>
        <p align="justify">
          <a href="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_thumb.png" width="104" height="104" />
          </a>Even
if it seems not recently updated in term of source code, it has a professional level
functionality, easy to customize and use, and with some effort <a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank">MVVM</a> compatible.
Make sure to download the <a href="http://dynamicdatadisplay.codeplex.com/SourceControl/list/changesets" target="_blank">unreleased
latest source changeset</a> because it is dramatically different from the released
one. Here below we show hoe to use this charting library for a very common task, creating
multiple chart with the same X Axis. The goal is to have the classical view of a stock
chart: Candlestick+Volume some indicators. As a surprise we can see that the latest
changeset does not have out of the box any candlestick chart, neither is possible
to display a proper bar chart ( there is an OldBarGraph in the code, but it does not
seems to work anymore ). Well this is not generally a problem, since a good charting
library should be extensible in some way, so we try to create our chart by extending
the existing ones. Before to go on let’s have a look on the sample application:
</p>
        <p align="justify">
          <a href="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_thumb_1.png" width="665" height="390" />
          </a>
        </p>
        <p align="justify">
The application, even if simple, uses <a href="http://caliburnmicro.codeplex.com/" target="_blank"><a href="http://caliburnmicro.codeplex.com/" target="_blank">Caliburn
Micro</a>,</a><a href="http://www.felicepollano.com/2011/04/23/An12HourApplicationInWPFWithCaliburnMicro.aspx" target="_blank">have
a look here if you need some notes about that</a>. Data are embedded resources obtained
fro <a href="http://finance.yahoo.com/" target="_blank">YAHOO! Finance</a> for the
sole purpose of writing this example application. So lets start with the candles.
We note in the source code bounch that exists a MarkerPointsGraph, a graph that display
a Marker at each “Y” coordinate, so couldn’t be the candlestick a marker ? Yes, by
just deriving from PointMarker. Let see how “difficult” this can be:
</p>
        <p align="justify">
 
</p>
        <pre class="code">
          <span style="color: blue">public class </span>
          <span style="color: #2b91af">CandleStickPointMarker</span>:<span style="color: #2b91af">ShapePointMarker</span>,<span style="color: #2b91af">ITransformAware </span>{ <span style="color: blue">…</span><span style="color: blue">public
override void </span>Render(System.Windows.Media.<span style="color: #2b91af">DrawingContext </span>dc, <span style="color: #2b91af">Point </span>screenPoint)
{ <span style="color: #2b91af">Point </span>screenOpen = GetScreenPoint(Open,screenPoint.X); <span style="color: #2b91af">Point </span>screenHigh
= GetScreenPoint(High,screenPoint.X); <span style="color: #2b91af">Point </span>screenLow
= GetScreenPoint(Low, screenPoint.X); <span style="color: green">//screenPoint is
the CLOSE by gentleman agreement. </span><span style="color: blue">var </span>close
= screenPoint.ScreenToData(Transform).Y; <span style="color: #2b91af">Pen </span>strokePen; <span style="color: blue">if </span>(Open
&gt;= close) <span style="color: green">// black </span>{ strokePen = <span style="color: blue">new </span><span style="color: #2b91af">Pen</span>(BlackCandleStroke,
CandelstickStrokeWidth); <span style="color: blue">var </span>h = -screenOpen.Y +
screenPoint.Y; dc.DrawRectangle(BlackCandleFill,strokePen , <span style="color: blue">new </span><span style="color: #2b91af">Rect</span>(screenPoint.X
- CandelstickWidth / 2, screenOpen.Y, CandelstickWidth, h) ); dc.DrawLine(strokePen,
screenLow, screenPoint); dc.DrawLine(strokePen, screenHigh, screenOpen); } <span style="color: blue">else </span><span style="color: green">//
white </span>{ strokePen=<span style="color: blue">new </span><span style="color: #2b91af">Pen</span>(WhiteCandleStroke,
CandelstickStrokeWidth); <span style="color: blue">var </span>h = screenOpen.Y - screenPoint.Y;
dc.DrawRectangle(WhiteCandleFill, strokePen , <span style="color: blue">new </span><span style="color: #2b91af">Rect</span>(screenPoint.X
- CandelstickWidth / 2, screenPoint.Y, CandelstickWidth, h) ); dc.DrawLine(strokePen,
screenLow, screenOpen); dc.DrawLine(strokePen, screenHigh, screenPoint); } } <span style="color: blue">private </span><span style="color: #2b91af">Point </span>GetScreenPoint(<span style="color: blue">double </span>Open,<span style="color: blue">double </span>screenX)
{ <span style="color: #2b91af">Point </span>screen = <span style="color: blue">new </span><span style="color: #2b91af">Point</span>(0,
Open); <span style="color: blue">return new </span><span style="color: #2b91af">Point</span>(screenX,screen.DataToScreen(Transform).Y);
} } </pre>
        <p>
Really easy, we just need a trick: since the marker currently works with a pre-transformed
coordinate for the single point the marker usually represent, and we need instead
other three value ( Open/Min/Max ) we need to transform these value recovered directly
from the data source. This is the reason I had to create the interface <span style="color: #2b91af">ITransformAware
, <font color="#000000">so we can pass the transform to the PointMarker, let see how:</font></span></p>
        <pre class="code">
          <span style="color: blue">using </span>(<span style="color: #2b91af">IPointEnumerator </span>enumerator
= DataSource.GetEnumerator(GetContext())) { <span style="color: #2b91af">Point </span>point
= <span style="color: blue">new </span><span style="color: #2b91af">Point</span>(); <span style="color: blue">while </span>(enumerator.MoveNext())
{ enumerator.GetCurrent(<span style="color: blue">ref </span>point); enumerator.ApplyMappings(Marker); <span style="color: green">//Point
screenPoint = point.Transform(state.Visible, state.Output); </span><span style="color: #2b91af">Point </span>screenPoint
= point.DataToScreen(transform); bounds = <span style="color: #2b91af">DataRect</span>.Union(bounds,
point); <font style="background-color: #ffff00"><span style="color: blue">var </span>ta
= Marker <span style="color: blue">as </span><span style="color: #2b91af">ITransformAware</span>; <span style="color: blue">if</span>( <span style="color: blue">null </span>!=
ta ) ta.Transform = transform;</font> Marker.Render(dc, screenPoint); } } </pre>
        <p>
This is the only trick. DataSOurce side what we have to do is to add the mapping for
the missing coordinates:
</p>
        <p>
 
</p>
        <pre class="code">
          <span style="color: blue">value</span>.SetYMapping(k
=&gt; <span style="color: blue">double</span>.Parse(k[4], <span style="color: #2b91af">CultureInfo</span>.InvariantCulture)); <span style="color: blue">value</span>.AddMapping(<span style="color: #2b91af">CandleStickPointMarker</span>.<font style="background-color: #ffff00">OpenProperty</font>,
k =&gt; <span style="color: blue">double</span>.Parse(k[1], <span style="color: #2b91af">CultureInfo</span>.InvariantCulture)); <span style="color: blue">value</span>.AddMapping(<span style="color: #2b91af">CandleStickPointMarker</span>.<font style="background-color: #ffff00">HighProperty</font>,
k =&gt; <span style="color: blue">double</span>.Parse(k[2], <span style="color: #2b91af">CultureInfo</span>.InvariantCulture)); <span style="color: blue">value</span>.AddMapping(<span style="color: #2b91af">CandleStickPointMarker</span>.<font style="background-color: #ffff00">LowProperty</font>,
k =&gt; <span style="color: blue">double</span>.Parse(k[3], <span style="color: #2b91af">CultureInfo</span>.InvariantCulture)); </pre>
        <p>
Xaml Side:
</p>
        <pre class="code">
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">ChartPlotter </span>
          <span style="color: red">x</span>
          <span style="color: blue">:</span>
          <span style="color: red">Name</span>
          <span style="color: blue">="price" </span>
          <span style="color: red">LegendVisibility</span>
          <span style="color: blue">="Hidden" </span>
          <span style="color: red">NewLegendVisible</span>
          <span style="color: blue">="False" </span>
          <span style="color: red">Grid.Row</span>
          <span style="color: blue">="1"&gt;
&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">VerticalAxisTitle</span>
          <span style="color: blue">&gt;</span>
          <span style="color: #a31515">Price</span>
          <span style="color: blue">&lt;/</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">VerticalAxisTitle</span>
          <span style="color: blue">&gt; <font style="background-color: #00ff00">&lt;</font></span>
          <font style="background-color: #00ff00">
            <span style="color: #a31515">ddd</span>
            <span style="color: blue">:</span>
            <span style="color: #a31515">WidthSpring </span>
            <span style="color: red">SourcePanel</span>
            <span style="color: blue">="{</span>
            <span style="color: #a31515">Binding </span>
            <span style="color: red">LeftPanel</span>
            <span style="color: blue">, </span>
            <span style="color: red">ElementName</span>
          </font>
          <span style="color: blue">
            <font style="background-color: #00ff00">=volume}"/&gt;</font> &lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">MarkerPointsGraph </span>
          <span style="color: red">DataSource</span>
          <span style="color: blue">="{</span>
          <span style="color: #a31515">Binding </span>
          <span style="color: red">PriceDS</span>
          <span style="color: blue">}"
&gt; &lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">MarkerPointsGraph.Marker</span>
          <span style="color: blue">&gt;
&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">CandleStickPointMarker </span>
          <span style="color: red">WhiteCandleFill</span>
          <span style="color: blue">="Azure" </span>
          <span style="color: red">BlackCandleFill</span>
          <span style="color: blue">="DarkBlue"&gt;
&lt;/</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">CandleStickPointMarker</span>
          <span style="color: blue">&gt;
&lt;/</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">MarkerPointsGraph.Marker</span>
          <span style="color: blue">&gt;
&lt;/</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">MarkerPointsGraph</span>
          <span style="color: blue">&gt;
&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">ChartPlotter.MainHorizontalAxis</span>
          <span style="color: blue">&gt;
&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">NumericAxis </span>
          <span style="color: red">LabelProvider</span>
          <span style="color: blue">="{</span>
          <span style="color: #a31515">StaticResource </span>
          <span style="color: red">tickToDate</span>
          <span style="color: blue">}"/&gt;
&lt;/</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">ChartPlotter.MainHorizontalAxis</span>
          <span style="color: blue">&gt;
&lt;/</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">ChartPlotter</span>
          <span style="color: blue">&gt; </span>
        </pre>
        <p>
 
</p>
        <p>
Really easy and strightforward. Notice than choosing the candlestick theme does not
involve changing a style, bust just setting a brush.  The green line shown one
interesting trick, by specifying the WidthSpring, we spring all the chart with the
left part aligned. Very important since we need to compare the charts all together.
Frankly speaking I did not manage any way to achieve that with WPF Toolkit charts.
</p>
        <p>
          <a href="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_8.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_thumb_3.png" width="92" height="300" />
          </a>WidthSpring
keeps the left part of the chart aligned.
</p>
        <p>
Bar chart is done by specializing the <strong>PointsGraphBase</strong> chart. Data
are passed as a regular LineChart:
</p>
        <p>
 
</p>
        <pre class="code">
          <span style="color: blue">public </span>
          <span style="color: #2b91af">EnumerableDataSource</span>&lt;<span style="color: blue">string</span>[]&gt;
VolumeDS { <span style="color: blue">get </span>{ <span style="color: blue">return </span>volumeDS;
} <span style="color: blue">set </span>{ <span style="color: blue">value</span>.SetXMapping(k
=&gt; <span style="color: #2b91af">DateTime</span>.ParseExact(k[0], <span style="color: #a31515">"yyyy-MM-dd"</span>, <span style="color: #2b91af">CultureInfo</span>.InvariantCulture).Ticks); <span style="color: blue">value</span>.SetYMapping(k
=&gt; <span style="color: blue">double</span>.Parse(k[5], <span style="color: #2b91af">CultureInfo</span>.InvariantCulture));
volumeDS = <span style="color: blue">value</span>; } } </pre>
        <p>
 
</p>
        <p>
An interesting part is what we show as labels on the XAxis ? We can customize that
too:
</p>
        <p>
          <span style="color: blue">&lt;</span>
          <span style="color: #a31515">ddd</span>
          <span style="color: blue">:</span>
          <span style="color: #a31515">NumericAxis </span>
          <span style="color: red">LabelProvider</span>
          <span style="color: blue">="{</span>
          <span style="color: #a31515">StaticResource </span>
          <span style="color: red">tickToDate</span>
          <span style="color: blue">}"/&gt; </span>
        </p>
        <p>
          <span style="color: blue">
            <font color="#000000">As we can see,</font>
            <font color="#000000">we
provide as LabelProvider that produce the label for each tick. If we are not satidfied
by the tick, we can provide our TickProvider. </font>
          </span>
        </p>
        <p>
          <span style="color: blue">
            <font color="#000000">Here below you can find my DynamicDataDisplay
version ( sorry for providing that way, I’m tryng to contact the development team
to send the patches )</font>
          </span>
        </p>
        <p>
          <span style="color: blue">
          </span>
        </p>
        <iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-b8821720666a55e7.office.live.com/embedicon.aspx/.Public/DynamicDataDisplay.zip" frameborder="0" marginwidth="0" scrolling="no">
        </iframe>
        <p>
and here the sample app: 
</p>
        <iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-b8821720666a55e7.office.live.com/embedicon.aspx/.Public/DynamicDataDisplay.Test.zip" frameborder="0" marginwidth="0" scrolling="no">
        </iframe>
        <img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=ea2fe80e-255d-4b37-9567-a8b5ca08ab47" />
      </body>
      <title>Multiple Charts with WPF Dynamic Data Display</title>
      <guid isPermaLink="false">http://www.felicepollano.com/PermaLink.aspx?guid=ea2fe80e-255d-4b37-9567-a8b5ca08ab47</guid>
      <link>http://www.felicepollano.com/2011/05/15/MultipleChartsWithWPFDynamicDataDisplay.aspx</link>
      <pubDate>Sun, 15 May 2011 19:31:57 GMT</pubDate>
      <description>&lt;p align="justify"&gt;
I was looking for a good open source charting library and I noticed that is a little
difficult to find something really useful and easy to use. I had a look at the &lt;a href="http://blogs.msdn.com/b/delay/archive/2009/06/25/wpf-charting-it-s-official-june-2009-release-of-the-wpf-toolkit-is-now-available.aspx" target="_blank"&gt;WPF
Toolkit charting library&lt;/a&gt;, a little old for sure, but look promising at a first
glance. Unfortunately it is not so easy to use, not brilliant in term of speed and
with some discutable behavior,&amp;nbsp; as for example the absence of a way to remove
the chart animation, or removing the fancy bullet in the line chart. By digging a
little deeper I found the &lt;a href="http://dynamicdatadisplay.codeplex.com/" target="_blank"&gt;WPF
Dynamic Data Display&lt;/a&gt; 
&lt;/p&gt;
&lt;p align="justify"&gt;
&lt;a href="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_thumb.png" width="104" height="104"&gt;&lt;/a&gt;Even
if it seems not recently updated in term of source code, it has a professional level
functionality, easy to customize and use, and with some effort &lt;a href="http://en.wikipedia.org/wiki/Model_View_ViewModel" target="_blank"&gt;MVVM&lt;/a&gt; compatible.
Make sure to download the &lt;a href="http://dynamicdatadisplay.codeplex.com/SourceControl/list/changesets" target="_blank"&gt;unreleased
latest source changeset&lt;/a&gt; because it is dramatically different from the released
one. Here below we show hoe to use this charting library for a very common task, creating
multiple chart with the same X Axis. The goal is to have the classical view of a stock
chart: Candlestick+Volume some indicators. As a surprise we can see that the latest
changeset does not have out of the box any candlestick chart, neither is possible
to display a proper bar chart ( there is an OldBarGraph in the code, but it does not
seems to work anymore ). Well this is not generally a problem, since a good charting
library should be extensible in some way, so we try to create our chart by extending
the existing ones. Before to go on let’s have a look on the sample application:
&lt;/p&gt;
&lt;p align="justify"&gt;
&lt;a href="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_thumb_1.png" width="665" height="390"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="justify"&gt;
The application, even if simple, uses &lt;a href="http://caliburnmicro.codeplex.com/" target="_blank"&gt;&lt;a href="http://caliburnmicro.codeplex.com/" target="_blank"&gt;Caliburn
Micro&lt;/a&gt;,&lt;/a&gt; &lt;a href="http://www.felicepollano.com/2011/04/23/An12HourApplicationInWPFWithCaliburnMicro.aspx" target="_blank"&gt;have
a look here if you need some notes about that&lt;/a&gt;. Data are embedded resources obtained
fro &lt;a href="http://finance.yahoo.com/" target="_blank"&gt;YAHOO! Finance&lt;/a&gt; for the
sole purpose of writing this example application. So lets start with the candles.
We note in the source code bounch that exists a MarkerPointsGraph, a graph that display
a Marker at each “Y” coordinate, so couldn’t be the candlestick a marker ? Yes, by
just deriving from PointMarker. Let see how “difficult” this can be:
&lt;/p&gt;
&lt;p align="justify"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CandleStickPointMarker&lt;/span&gt;:&lt;span style="color: #2b91af"&gt;ShapePointMarker&lt;/span&gt;,&lt;span style="color: #2b91af"&gt;ITransformAware &lt;/span&gt;{ &lt;span style="color: blue"&gt;…&lt;/span&gt; &lt;span style="color: blue"&gt;public
override void &lt;/span&gt;Render(System.Windows.Media.&lt;span style="color: #2b91af"&gt;DrawingContext &lt;/span&gt;dc, &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screenPoint)
{ &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screenOpen = GetScreenPoint(Open,screenPoint.X); &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screenHigh
= GetScreenPoint(High,screenPoint.X); &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screenLow
= GetScreenPoint(Low, screenPoint.X); &lt;span style="color: green"&gt;//screenPoint is
the CLOSE by gentleman agreement. &lt;/span&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;close
= screenPoint.ScreenToData(Transform).Y; &lt;span style="color: #2b91af"&gt;Pen &lt;/span&gt;strokePen; &lt;span style="color: blue"&gt;if &lt;/span&gt;(Open
&amp;gt;= close) &lt;span style="color: green"&gt;// black &lt;/span&gt;{ strokePen = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Pen&lt;/span&gt;(BlackCandleStroke,
CandelstickStrokeWidth); &lt;span style="color: blue"&gt;var &lt;/span&gt;h = -screenOpen.Y +
screenPoint.Y; dc.DrawRectangle(BlackCandleFill,strokePen , &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Rect&lt;/span&gt;(screenPoint.X
- CandelstickWidth / 2, screenOpen.Y, CandelstickWidth, h) ); dc.DrawLine(strokePen,
screenLow, screenPoint); dc.DrawLine(strokePen, screenHigh, screenOpen); } &lt;span style="color: blue"&gt;else &lt;/span&gt;&lt;span style="color: green"&gt;//
white &lt;/span&gt;{ strokePen=&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Pen&lt;/span&gt;(WhiteCandleStroke,
CandelstickStrokeWidth); &lt;span style="color: blue"&gt;var &lt;/span&gt;h = screenOpen.Y - screenPoint.Y;
dc.DrawRectangle(WhiteCandleFill, strokePen , &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Rect&lt;/span&gt;(screenPoint.X
- CandelstickWidth / 2, screenPoint.Y, CandelstickWidth, h) ); dc.DrawLine(strokePen,
screenLow, screenOpen); dc.DrawLine(strokePen, screenHigh, screenPoint); } } &lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;GetScreenPoint(&lt;span style="color: blue"&gt;double &lt;/span&gt;Open,&lt;span style="color: blue"&gt;double &lt;/span&gt;screenX)
{ &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screen = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(0,
Open); &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(screenX,screen.DataToScreen(Transform).Y);
} } &lt;/pre&gt;
&lt;p&gt;
Really easy, we just need a trick: since the marker currently works with a pre-transformed
coordinate for the single point the marker usually represent, and we need instead
other three value ( Open/Min/Max ) we need to transform these value recovered directly
from the data source. This is the reason I had to create the interface &lt;span style="color: #2b91af"&gt;ITransformAware
, &lt;font color="#000000"&gt;so we can pass the transform to the PointMarker, let see how:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IPointEnumerator &lt;/span&gt;enumerator
= DataSource.GetEnumerator(GetContext())) { &lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;point
= &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point&lt;/span&gt;(); &lt;span style="color: blue"&gt;while &lt;/span&gt;(enumerator.MoveNext())
{ enumerator.GetCurrent(&lt;span style="color: blue"&gt;ref &lt;/span&gt;point); enumerator.ApplyMappings(Marker); &lt;span style="color: green"&gt;//Point
screenPoint = point.Transform(state.Visible, state.Output); &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Point &lt;/span&gt;screenPoint
= point.DataToScreen(transform); bounds = &lt;span style="color: #2b91af"&gt;DataRect&lt;/span&gt;.Union(bounds,
point); &lt;font style="background-color: #ffff00"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;ta
= Marker &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ITransformAware&lt;/span&gt;; &lt;span style="color: blue"&gt;if&lt;/span&gt;( &lt;span style="color: blue"&gt;null &lt;/span&gt;!=
ta ) ta.Transform = transform;&lt;/font&gt; Marker.Render(dc, screenPoint); } } &lt;/pre&gt;
&lt;p&gt;
This is the only trick. DataSOurce side what we have to do is to add the mapping for
the missing coordinates:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="code"&gt;               &lt;span style="color: blue"&gt;value&lt;/span&gt;.SetYMapping(k
=&amp;gt; &lt;span style="color: blue"&gt;double&lt;/span&gt;.Parse(k[4], &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture)); &lt;span style="color: blue"&gt;value&lt;/span&gt;.AddMapping(&lt;span style="color: #2b91af"&gt;CandleStickPointMarker&lt;/span&gt;.&lt;font style="background-color: #ffff00"&gt;OpenProperty&lt;/font&gt;,
k =&amp;gt; &lt;span style="color: blue"&gt;double&lt;/span&gt;.Parse(k[1], &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture)); &lt;span style="color: blue"&gt;value&lt;/span&gt;.AddMapping(&lt;span style="color: #2b91af"&gt;CandleStickPointMarker&lt;/span&gt;.&lt;font style="background-color: #ffff00"&gt;HighProperty&lt;/font&gt;,
k =&amp;gt; &lt;span style="color: blue"&gt;double&lt;/span&gt;.Parse(k[2], &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture)); &lt;span style="color: blue"&gt;value&lt;/span&gt;.AddMapping(&lt;span style="color: #2b91af"&gt;CandleStickPointMarker&lt;/span&gt;.&lt;font style="background-color: #ffff00"&gt;LowProperty&lt;/font&gt;,
k =&amp;gt; &lt;span style="color: blue"&gt;double&lt;/span&gt;.Parse(k[3], &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture)); &lt;/pre&gt;
&lt;p&gt;
Xaml Side:
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ChartPlotter &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;="price" &lt;/span&gt;&lt;span style="color: red"&gt;LegendVisibility&lt;/span&gt;&lt;span style="color: blue"&gt;="Hidden" &lt;/span&gt;&lt;span style="color: red"&gt;NewLegendVisible&lt;/span&gt;&lt;span style="color: blue"&gt;="False" &lt;/span&gt;&lt;span style="color: red"&gt;Grid.Row&lt;/span&gt;&lt;span style="color: blue"&gt;="1"&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;VerticalAxisTitle&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Price&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;VerticalAxisTitle&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;font style="background-color: #00ff00"&gt;&amp;lt;&lt;/font&gt;&lt;/span&gt;&lt;font style="background-color: #00ff00"&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;WidthSpring &lt;/span&gt;&lt;span style="color: red"&gt;SourcePanel&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;LeftPanel&lt;/span&gt;&lt;span style="color: blue"&gt;, &lt;/span&gt;&lt;span style="color: red"&gt;ElementName&lt;/span&gt;&lt;/font&gt;&lt;span style="color: blue"&gt;&lt;font style="background-color: #00ff00"&gt;=volume}"/&amp;gt;&lt;/font&gt; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;MarkerPointsGraph &lt;/span&gt;&lt;span style="color: red"&gt;DataSource&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;PriceDS&lt;/span&gt;&lt;span style="color: blue"&gt;}"
&amp;gt; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;MarkerPointsGraph.Marker&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;CandleStickPointMarker &lt;/span&gt;&lt;span style="color: red"&gt;WhiteCandleFill&lt;/span&gt;&lt;span style="color: blue"&gt;="Azure" &lt;/span&gt;&lt;span style="color: red"&gt;BlackCandleFill&lt;/span&gt;&lt;span style="color: blue"&gt;="DarkBlue"&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;CandleStickPointMarker&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;MarkerPointsGraph.Marker&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;MarkerPointsGraph&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ChartPlotter.MainHorizontalAxis&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;NumericAxis &lt;/span&gt;&lt;span style="color: red"&gt;LabelProvider&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;tickToDate&lt;/span&gt;&lt;span style="color: blue"&gt;}"/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ChartPlotter.MainHorizontalAxis&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ChartPlotter&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Really easy and strightforward. Notice than choosing the candlestick theme does not
involve changing a style, bust just setting a brush.&amp;nbsp; The green line shown one
interesting trick, by specifying the WidthSpring, we spring all the chart with the
left part aligned. Very important since we need to compare the charts all together.
Frankly speaking I did not manage any way to achieve that with WPF Toolkit charts.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.felicepollano.com/public/Windows-Live-Writer/3249032ad3d3_13B4D/image_thumb_3.png" width="92" height="300"&gt;&lt;/a&gt;WidthSpring
keeps the left part of the chart aligned.
&lt;/p&gt;
&lt;p&gt;
Bar chart is done by specializing the &lt;strong&gt;PointsGraphBase&lt;/strong&gt; chart. Data
are passed as a regular LineChart:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EnumerableDataSource&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[]&amp;gt;
VolumeDS { &lt;span style="color: blue"&gt;get &lt;/span&gt;{ &lt;span style="color: blue"&gt;return &lt;/span&gt;volumeDS;
} &lt;span style="color: blue"&gt;set &lt;/span&gt;{ &lt;span style="color: blue"&gt;value&lt;/span&gt;.SetXMapping(k
=&amp;gt; &lt;span style="color: #2b91af"&gt;DateTime&lt;/span&gt;.ParseExact(k[0], &lt;span style="color: #a31515"&gt;"yyyy-MM-dd"&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture).Ticks); &lt;span style="color: blue"&gt;value&lt;/span&gt;.SetYMapping(k
=&amp;gt; &lt;span style="color: blue"&gt;double&lt;/span&gt;.Parse(k[5], &lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture));
volumeDS = &lt;span style="color: blue"&gt;value&lt;/span&gt;; } } &lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
An interesting part is what we show as labels on the XAxis ? We can customize that
too:
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ddd&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;NumericAxis &lt;/span&gt;&lt;span style="color: red"&gt;LabelProvider&lt;/span&gt;&lt;span style="color: blue"&gt;="{&lt;/span&gt;&lt;span style="color: #a31515"&gt;StaticResource &lt;/span&gt;&lt;span style="color: red"&gt;tickToDate&lt;/span&gt;&lt;span style="color: blue"&gt;}"/&amp;gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: blue"&gt;&lt;font color="#000000"&gt;As we can see,&lt;/font&gt; &lt;font color="#000000"&gt;we
provide as LabelProvider that produce the label for each tick. If we are not satidfied
by the tick, we can provide our TickProvider. &lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: blue"&gt;&lt;font color="#000000"&gt;Here below you can find my DynamicDataDisplay
version ( sorry for providing that way, I’m tryng to contact the development team
to send the patches )&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: blue"&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-b8821720666a55e7.office.live.com/embedicon.aspx/.Public/DynamicDataDisplay.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;
&lt;/iframe&gt;
&lt;p&gt;
and here the sample app: 
&lt;/p&gt;
&lt;iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="http://cid-b8821720666a55e7.office.live.com/embedicon.aspx/.Public/DynamicDataDisplay.Test.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;
&lt;/iframe&gt;
&lt;img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=ea2fe80e-255d-4b37-9567-a8b5ca08ab47" /&gt;</description>
      <comments>http://www.felicepollano.com/CommentView.aspx?guid=ea2fe80e-255d-4b37-9567-a8b5ca08ab47</comments>
      <category>Charting</category>
      <category>D3</category>
      <category>WPF</category>
    </item>
  </channel>
</rss>