WPF Charting: It’s official! [June 2009 release of the WPF Toolkit is now available!]


This blog has moved to a new location and comments have been disabled.

All old posts, new posts, and comments can be found on The blog of dlaa.me.

See you there!

Comments (80)
  1. cplotts says:

    In order to get the design assemblies to build … I also had to remove the conditional compilation symbol MWD40 … as it was complaining about ToolboxCategoryAttribute.

  2. cplotts says:

    By the way, nice job! I am taking a deep look at what you guys have done as I hope to use it for our WPF application. In particular, I plan on creating a custom logarithmic axes for our industry specific line charts.

  3. David Anson says:

    cplotts,

    Thanks for sharing your feedback about the MWD40 symbol! I tried the complete build steps on two different machines and did not need to make that change – but if you did, then maybe some other people will need to as well. 🙂

  4. jaison-joy@hotmail.com says:

    how to export the chart created in wpf to excel ?

  5. David Anson says:

    jaison-joy,

    What kind of export are you looking for? The chart is created from data the application owns, so if the application wants to export that same data to Excel (via COM/XLS/CSV/etc.), then it can do so. If an image of the chart is desired, that can be obtained via WPF’s RenderTargetBitmap. I’m not sure what export functionality people are looking for from the Chart control itself, so if you have specific scenarios in mind, I’d love to hear them!

  6. rajeshaz09 says:

    I used un official WPF charting controls which you mentioed in previous post (http://blogs.msdn.com/delay/archive/2009/03/20/silverlight-charting-remains-just-a-click-away-and-runs-on-wpf-too-chartbuilder-sample-and-source-code-updated-for-charting-s-march-09-release.aspx).

    Now i am planning to upgrade it.

    Btw: Can this release supports Expression blend 2.0 ?

    what is the reason for supports blend3.0 ? is it for maintain compatability btw silverlight and wpf ?

    Thnaks for your work.

  7. David Anson says:

    Rajesh,

    Blend 3 supports Silverlight 3 and Blend 2 supports Silverlight 2. What you probably want to switch to is the official release of Charting in the June 2009 WPF Toolkit which has been specifically verified to work with Blend 3. Here’s a link with more information:

    http://blogs.msdn.com/delay/archive/2009/06/25/wpf-charting-it-s-official-june-2009-release-of-the-wpf-toolkit-is-now-available.aspx

    Thanks!

  8. LunaWPF says:

    How do you copy an entire WPF Chart, including the Title, Legends, Axes and DataPoints (lines, columns or AreaSeries) to the clipboard?

    The motivation for this question is:

    – User creats a WPF Chart

    – User right-clicks anywhere on the chart to bring up a ContextMenu which says "Copy to Clipboard"

    – User opens PPT (or Word) and pastes the WPF Chart into a PPT slide (or a Word document).

    Thanks

  9. David Anson says:

    LunaWPF,

    The general technique for capturing a part of a WPF application is via the RenderTargetBitmap API which is documented in MSDN here:

    http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx

    This API lets you capture the visuals of any control (like Chart) as an image – which can then be put on the clipboard via the standard clipboard APIs.

    Hope this helps!

  10. graham_fletcher says:

    Is there any support planned for XYZ charting?

    This could apply to any charts that currently display x/y pairs, and is a fairly common feature in advanced charting packages.

    Apart from that small request, the rest looks great!

  11. David Anson says:

    Graham,

    Yes, we’d eventually like to support more chart types – including 3D, etc.. It’s just that there have been enough competing priorities that we haven’t been able to do so yet.

    Thanks for your patience!

  12. mks_v1 says:

    I like it, but how do you display extreme ranges on a bar chart

    e.g.

    January Sales are: 20,000,000

    February Sales are: 50

    if the value is very small, the bar rectangle may not be drawn, but the value should be displayed as a column annotation. I’ve seen this on on the graph controls

  13. David Anson says:

    mks_v1,

    We don’t currently support what are known as "scale breaks" in the axis. However, the following post of mine shows one way to get the annotations you’re asking for:

    http://blogs.msdn.com/delay/archive/2009/07/27/simple-column-labels-you-can-create-at-home-re-templating-the-silverlight-wpf-data-visualization-columndatapoint-to-add-annotations.aspx

    Hope this helps!

  14. FaisalAli says:

    Does WPF Charting control support zoom and pan features? Also, the charting control seems to run a little slower. I plotted 1000 points on a line series chart and it took a few seconds to display the plot. Is there a way to make it run faster?

    Thanks.

  15. David Anson says:

    FaisalAli,

    No, I’m afraid the Charting controls do not natively support zoom and pan at the moment. 🙁 Support for this capability is fairly high on our TODO list, but not quite at the top based on the relatively limited number of requests we’ve gotten for it so far. For what it’s worth, if you’re plotting 1000 points, you’re starting to go beyond where we expect most people to be. However, there are a few tricks that can be used to speed things up for cases like this, some of which are fairly simple. One of the items near the top of my own blog TODO list is to write a post about some of these tricks in order to try to help people out who are just starting to bump into performance issues like this.

    Thanks for your patience – I hope it will be helpful!

  16. maverickcoder says:

    I want to stack multiple line charts. Can I remove the chart area around the chart. Something like this.

    |_____________________

    |_____________________

    |_____________________

    Is this possible?

    Thanks

  17. David Anson says:

    maverickcoder,

    Yes, this is possible – it sounds like all you need to do is customize the Template for those Charts to remove the extra stuff you don’t want (like the Title and Legend).

  18. GregHau says:

    I'm having trouble with understanding how to tailor the charts mainly due to lack of documentation.  Is there any documentation released yet that provides a reference for the various Charting XAML elements & attributes that are available and how they can be used for charting?  This would be great.  

  19. David Anson says:

    GregHau,

    I keep a list of all kinds of Data Visualization resources here: http://cesso.org/r/DVLinks

    That link points to a list of all my own blog posts on the topic which should provide a pretty thorough overview of how everything works and I know of a lot of people who have managed to achieve great things based on the content I've linked to. 🙂

    Hope this helps!

  20. GregHau says:

    Thanks Delay – I already had this link which is great – do you know if there is a way (re being self-sufficient) to look up reference documentation (online, or in the source of the toolkit if I download it) that could be used to answer a question?  i.e. as opposed to looking for examples where someone else may have done it.  

    As an example perhaps I've been looking for a way to not have data point markers at each of the data points.  Is there a way I could reference, perhaps starting at chartingToolkit:LineSeries element, to find out what element/attributes I would have to use in my XAML to not have data point markers?  

    I'm a little new to XAML so perhaps this doesn't help, but it's more about how to lookup/check the specific WPF Toolkit Charting elements/attributes and how to use them that would help me I think, or how to look them up in the source perhaps if the end-user doco isn't ready yet.  Perhaps if I can find the appropriate areas of the source classes I could then set the appropriate configuration in code-behind in C# just to not have to deal with XAML & Charting together (i.e. both are somewhat new to me)?  

    Thanks

  21. David Anson says:

    GregHau,

    I appreciate your attempts to be self-sufficient, but unfortunately there is no official documentation for the Data Visualization assembly, so the links I've collected represent the "unofficial" documentation. That said, the answers to some of what you're asking will become more clear as you become more familiar with Silverlight/XAML/etc..

    Regarding the question about removing the DataPoints for a LineSeries, the following post of mine covers that along with some other ideas for improving performance: blogs.msdn.com/…/i-feel-the-need-the-need-for-speed-seven-simple-performance-boosting-tweaks-for-common-silverlight-wpf-charting-scenarios.aspx

    As for navigating the source code, while I could point you at the relevant areas for specific questions, I don't think there's any general-purpose solution for finding the "right" area automatically. Again, as you develop increasing familiarity with the platform and DataVis, some of this will become easier.

    That's probably not the most convenient answer for right now, but the good news is that there's every reason to believe things will get easier over time! 🙂

  22. GregHau says:

    thanks Delay – I think you're no doubt correct – I'll plod along for the moment referencing articles etc and I'll no doubt get better.

    Is it correct to say re Charting this (WPF Toolkit) is the main focus Microsoft will have regarding provides this type of support?  i.e. in terms of spending time ramping up on the toolkit we should be 99% confident that it will continue to exist and be enhanced by Microsoft?  It would seem this is almost already one of the main choices available to .net developers wanting to add charting capabilities, but can not afford the commercial offerings.

  23. GregHau says:

    Delay – you don't happen to know if there is a link that covers how to get a graph to dynamically stretch vertically?  For example within a StackPanel (VerticalAlignment=Stretch) that is part of grid (for which the grid row itself, with MaxHeight=Infinity).  It seems like at the moment for me stretching occurs for the graph OK in the horizontal direction, however it's in the vertical direction I'm having the issue.  

  24. David Anson says:

    GregHau,

    For the time being, the Data Visualization assembly in the Silverlight and WPF Toolkits is the Charting solution (from Microsoft) that I'd recommend for Silverlight and WPF development. (There are, of course, other Charting solutions for these platforms and I'm sure they're fine choices as well – I'm just addressing your specific question about an offering *from Microsoft*.)

    Regarding your layout question, content in a StackPanel with Orientation=Vertical (default) will never stretch vertically. If I'm understanding correctly, you'd see the same behavior with Button that you're seeing with Chart. This is just how StackPanel works – if you want vertical stretching, you probably want to use a Grid (with Rows) instead.

    Hope this helps!

  25. GregHau says:

    Hi Delay – mind if I ask if you have any pointers to examples of creating the lines on a chart (lineSeries) programmatically.  So basically just wanted to have the base XAML for the chart, and then programmatically add & remote the lineSeries (I.e. add & remove lines on the graph) as required as data comes into the app.   I did post this question on the forum too at wpf.codeplex.com/…/View.aspx .  Had some example code in the post that I was trying to use but getting exceptions.  Cheers Greg

  26. David Anson says:

    GregHau,

    I think there are some examples of that in my DataVisualizationDemos application here: blogs.msdn.com/…/nobody-likes-a-show-off-today-s-datavisualizationdemos-release-includes-new-demos-showing-off-stacked-series-behavior.aspx (Try the "performance" or "text to chart" samples first.)

    The basic steps are to create the Chart, configure it, create the Series, configure it, add the Series to Chart.Series, add the Chart to the visual tree, and that's it. Just think of what code runs as a result of the XAML you type and that'll be just about exactly what you do. 🙂

  27. GregHau says:

    Delay – ah yes the TextToChart should cover it off for me – thanks

  28. Michael says:

    I am using the chart in our application. I noticed that when I review the data in XPS file formats. The dataPiont lines are not shown. if the chart is Pie chart or bar chart. it seem to have different fades. I assumed its because of the animation of the datapointseries. If this is correct. How do you disable the animation entirely so that the chart shows on XPS files.

    Thanks.

  29. Michael says:

    I am interested in disabling the datapointseries animation from code behind not XAML.

    Thanks

  30. Michael says:

    Hi Delay thanks for the quick response. This is a real pain. In as much as the chart is a cool feature without printing its use is highly limited. Is it not possible to have developed the chart so that by just setting a property to true or false  in the chart, the animation will be enabled or disabled. I noticed a property called animationsequence and  i thought that setting the sequence to simultanous will take the fading in away. nothing happened. The application I am developing is a variable data software that handles thousands of data and generates thousands of XPS paged document using multitreading. How can the chart be added in the visual tree and extracted out again. I am not using the XPS printer driver in vista, I am using Xpsdocumentwriter thus it does not require the user to answer to the print dialog box. I dont mind retemplating the whole datagrid template.  I downloaded the toolkit source code just to play around with it and found the generic.xaml file that defined all the template.  Will removing the VisualStateManager section in the template fix my problem or are there more to retemplating the chart to disable the animation effect. I urgently need answers. I dont mind going the retemplating root. I just wants something that works reliably

    Regards

  31. David Anson says:

    [I've answered the duplicate version of Michael's comment above that was added to the other post I reference.]

  32. GregHau says:

    Hi Delay – is there a way to have a custom Y axis title and range that will apply to all series.  Unless I'm missing something you seem to put this data in with the lineSeries.  The issue I see is then any subsequent titles (even if the same) applied to the 2nd, 3rd series then appear as well.  As I'm programmatically creating the lineSeries's I've had to put a check in the loop to ensure I only put in the lineSeries.DependentRangeAxis in the first lineSeries.  Wondering if there's a better way to add custom Y Axis range/text when you have multiple lines where you want them to share the one Yaxis text description & range details?

  33. David Anson says:

    GregHau,

    You might look at adding that Axis to (or specifying it in) the Chart.Axes collection. If they don't have an Axis set directly on themselves via the Series.*Axis properties, Axes will look in the Chart.Axes collection during initialization and use any suitable axis they find inside. Therfore, if you put a viable Axis there before adding/creating the Series, they should all pick it and share it as it sounds like you want them to. 🙂

  34. Jonny says:

    Hi Delay,

    Does the Chart Control support multithreaded application. I am getting the error message "The calling thread cannot access this object because a different thread owns it."  and I am getting this error in the same tread that created the chart controls.

  35. David Anson says:

    Jonny,

    WPF (and Silverlight) tend to require that only the "UI thread" is allowed to access UI elements – it sounds like you're bumping into this. You're welcome to do any data processing you'd like on other threads, but when it comes time to set the ItemsSource, manipulate the UI, or make a change that directly affects the UI (ex: invoke a PropertyChanged event), you'll want to switch to the UI thread to avoid the error you're seeing (Dispatcher.BeginInvoke is rather handy for this). There should be plenty of other coverage of this on the web; I don't think what you're seeing is unique to Charting.

    I hope this helps!

  36. Orianne says:

    hi everyone

    Do you know where i can find support on plotting two line series on the same chart?

    Further more, i want to have on another chart a conditional area chart. Red on top of the x-Axis and Green under.

  37. David Anson says:

    Orianne,

    You can find lots of examples of Charting in my links collection here: http://cesso.org/r/DVLinks

    Specifically, this post has an example of two lines: blogs.msdn.com/…/silverlight-charting-gets-a-host-of-improvements-silverlight-toolkit-december-08-release-now-available.aspx

    Regarding a conditional Area chart, that's not supported by default. That said, there are probably some clever ways you might achieve this – and blogging them is already on my TODO list.

  38. Jonny says:

    Hi Delay is it posible to add the datapoint value from code without using the Itemssource property of the series.

    for instance the Lineseries have points propery but this only allows accepts x and y value of double. how can you have an x value that is double and use a y value of string. As I said earlier I do not intend to use the Itemsource. I am still a novice in multitreaded application and cant get the error "The calling thread cannot access this object because a different thread owns it" resolved.

  39. David Anson says:

    Jonny,

    Not directly – but if you set LineSeries.ItemsSource to an instance of ObservableCollection<T>, you can use the Add and Remove methods on that collection to dynamically add and remove items from the Chart whenever you want (as long as you're doing so from the UI thread).

    Regarding your specific example, I don't understand what LineSeries would be expected to do if given a Y value that's a string – DependentValues are supposed to be able to be compared to each other and are therefore assumed to be doubles. I don't think this relates to your ability to use multiple threads or not – but you'll probably want to be sure you can get the charts you want on a single thread before you start adding more threads. 🙂

  40. Jonny says:

    The charts works well in single thread and I am able to preview the XPS generated file for one record. However, the main processing is  multitreaded to facilitate speed as the files generated a in thousands.

  41. GregHau says:

    Hi Delay – any pointers re how to remove the markers from Line graph?  

    thanks

  42. David Anson says:

    GregHau,

    Yes, it's one of the tips in my performance post here: blogs.msdn.com/…/i-feel-the-need-the-need-for-speed-seven-simple-performance-boosting-tweaks-for-common-silverlight-wpf-charting-scenarios.aspx

    FYI that there are lots of other good Data Visualization resources here: http://cesso.org/r/DVLinks

    Hope this helps!

  43. GregHau says:

    Hi Delay – tried this (but with a chartingToolkit:LineDataPoint, not a charting:ScatterDataPoint)  – for some reason the graph isn't picking up the template – I've done the correct thing based on WPF XAML as far as I know however I'm really stuck – I've posted the code, see link, if you had a chance to have a quick look – is there a reason when using the WPFToolkit for charting that the normal XAML template approach would behave differently?  That is if I have under Windows.Resources and using (Style TargetType="chartingToolkit:LineDataPoint") why it wouldn't be picked up by a chartingToolkit:LineSeries?

    wpf.codeplex.com/…/View.aspx

  44. David Anson says:

    GregHau,

    It looks like Cory Plotts is actively helping you on that thread, so I'll hold off for now. 🙂 Though my recommendation would be to try it first the "Charting" way by explicitly setting Series.DataPointStyle to the style you want. If that doesn't work, then something else is getting in the way and it's not an implicit Style issue. If it does work, then we can sort out why implicit Styles wouldn't be working here.

  45. Eddie says:

    I'd like to specify declaratively in the XAML that I'd like a variable number of LineSeries series. Is this possible?

  46. David Anson says:

    Eddie,

    That's not supported by default, but I link to posts by Jeremiah Morrill and Beat Kiener that show ways of doing this in my link collection: http://cesso.org/r/DVLinks

  47. Eddie says:

    Thanks for the link delay, this one looks particularly promising: blog.thekieners.com/…/databinding-multi-series-charts

    Do you have a plan to add support for this at a later date?

  48. David Anson says:

    Eddie,

    It's on the TODO list – but that list also includes things for the rest of the Silverlight Toolkit and the Windows Phone Toolkit as well… 🙂 If one of those solutions works well for you, it would be a great approach for now.

  49. Xiaoyong says:

    Hi Delay, I am using StackedColumnSeries in my WPF program since it is mush faster than Telerik RadChart that I used before. The program adds/deletes data item upon received data in real time. Everything works fine except that I can not remove data item from binded ObservableCollection. Exception thrown: "Collection was modified; enumeration operation may not execute".  All stacked series behave this way. series such as line series, pie series, column series and bar series don't have this problem. Any suggestions? Thanks

  50. Xiaoyong says:

    Hi, Delay, I just downloaded source code and was able to step into source code.  It is probably a bug. I made following change in DefinitionSeries.cs (starts line 934). It works now.

                         //foreach (DataItem oldDataItem in DataItems.Where(di => (di.SeriesDefinition == definition) && (oldStartingIndex <= di.Index) && (di.Index < oldStartingIndex + oldItems.Count)))

                       //{

                       //    oldDataItem.Index = -1;

                       //    if (null != oldDataItem.DataPoint)

                       //    {

                       //        oldDataItem.DataPoint.State = DataPointState.Hiding;

                       //    }

                       //}

                       var oldDataItems = DataItems.Where(di => (di.SeriesDefinition == definition) && (oldStartingIndex <= di.Index) && (di.Index < oldStartingIndex + oldItems.Count));

                       int counts = oldDataItems.Count();

                       for (int i = 0; i < counts; i++)

                       {

                           DataItem oldDataItem = oldDataItems.ElementAt(i) as DataItem;

                           oldDataItem.Index = -1;

                           if (null != oldDataItem.DataPoint)

                           {

                               oldDataItem.DataPoint.State = DataPointState.Hiding;

                           }

                       }

  51. David Anson says:

    Xiaoyong,

    I'm glad to hear you got this working! I'm going to guess that you've customized your DataPoint Template to remove the Hiding VisualStateManager state – which causes the DataPoint to transition to Hidden immediately and should explain why this problem doesn't show up by default. If so, your change is exactly the right fix – I think there's already a bug on this, but I'll double-check right now to be sure. Thanks very much for looking into this and sharing your fix!

  52. ramh says:

    hello delay,

    Thanks for the fantastic blog going. Also you response for queries are great.

    I got a custom chart which is a combination of pie and scatter chart, which is not industry standard.

    Will it require some custom code? Also it needs fancy stuff like tool tips, export to pdf/excel and zooming.

    Also what all dependencies i need to look for while deploying this chart application developed with the toolkit?

    Will I be able to tweak and generate using the wpf toolkit.  

    Thank you..

  53. David Anson says:

    ramh,

    It sounds like your scenario may be a little more specialized than what's currently supported by the Toolkit Data Visualization offering. It might be a good way to get started, but depending on your zoom needs, you might end up having to write some custom code to do what you want.

    Regarding dependencies, the only dependency of the WPF Data Visualization assembly is the WPF Toolkit – and both are open source, so you can download all the code and compile/modify them yourself if you want.

    Hope this helps!

  54. Hunter says:

    I want to create stack column series. I cannot find the same in the toolkit. please update me on this.

  55. David Anson says:

    Hunter,

    There hasn't been an update to the WPF Toolkit since stacked series were added to the Silverlight Toolkit (April 2010). However, my Data Visualization Development Releases always have the latest code and binaries for all supported platforms and that's how you can get stacked series support for WPF 3.5/4. Here's the latest link:

    blogs.msdn.com/…/phone-y-charts-silverlight-wpf-data-visualization-development-release-4-and-windows-phone-7-charting-sample.aspx

    Hope this helps!

  56. Steve B. says:

    Hi, this is a really nice piece of work, thanks for sharing.

    Is it possibe to add the titles and legend to your "Jelly Charting" example. I tried:

                       <charting:LineSeries

                       ItemsSource="{Binding Converter={StaticResource JellyConverter}}"

                       …

                       TransitionDuration="0">

                       <charting:LineSeries.DependentRangeAxis>

                           <charting:LinearAxis

                                       Orientation="Y"

                                       Title="Some Title"

                                       Interval="50"

                                       ShowGridLines="True"/>

                      </charting:LineSeries.DependentRangeAxis>

                     …

    but unfortunately it didn't work.

  57. David Anson says:

    Steve B.,

    In the Jelly Charting post (blogs.msdn.com/…/peanut-butter-jelly-time-how-to-create-a-pleasing-visual-effect-with-silverlight-wpf-charting.aspx), I specifically provided a custom ControlTemplate without a Legend and set the Width/Height of the axes to 1 – you could definitely undo those things in order to get closer to a "normal"-looking chart. 🙂

  58. Steve B. says:

    Thanks a lot, that worked 🙂

  59. Jamie Pattison says:

    Are the chart controls supported with VS 2010 Premium/ Expression 4 and VB .Net?

  60. David Anson says:

    Jamie Pattison,

    Yes, that should work fine. FYI that you might want to start from my Development Release 4 which contains the latest features and fixes from the April 2010 Silverlight Toolkit: blogs.msdn.com/…/phone-y-charts-silverlight-wpf-data-visualization-development-release-4-and-windows-phone-7-charting-sample.aspx

    But both should work fine. 🙂

  61. Al T. says:

    Hi, Great Info here! I was wondering if I could get some advice… I've been able to set up a dynamic chart but for some reason I cannot assign series to particular axes. The problem is that i have many series and I would like to assign them to 2 types of Y axis. I do not want to see the range each time I I add the series. For example: I have

    A left and right  side Y axis and i want 2 series on the left Y and 2 series on the right Y. I can assign all the left axes in the Axes collection like this:

       <DVC:Chart.Axes>

         <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Temperature °F" Minimum="0" Maximum="300" Interval="10" Location="Left" />

    But the catch is when I try to assign more than one series to the right, I am forced to assign each series with a statement like this :

           <DVC:LineSeries.DependentRangeAxis>

             <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Humidity %" Minimum="0" Maximum="100" Interval="10" Location="Right" />

           </DVC:LineSeries.DependentRangeAxis>

    This causes more than one rang to show on the right as I am creating an axis for each.   If I do not set this then It will fall through an select the left axis. Ive set the visibility of the axis to hidden but it leaves a gap where it was and if I collapse it, it collapses the series as well. Is there any way to assign a series to an axis like ?:  

    <DVC:LineSeries Title="Humidity" BoundAxisName="RightSideAxis">

    I've attached some code below in case It may help someone

         <DVC:LineSeries Title="Humidity" Name="Humidity" ItemsSource="{Binding}" IndependentValueBinding="{Binding Date}" DependentValueBinding="{Binding Value}">

           <DVC:LineSeries.DataPointStyle>

           </DVC:LineSeries.DataPointStyle>

           <DVC:LineSeries.DependentRangeAxis>

             <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Humidity %" Minimum="0" Maximum="100" Interval="10" Location="Right" />

           </DVC:LineSeries.DependentRangeAxis>

         </DVC:LineSeries>

         <DVC:LineSeries Title="Wet Temp" Name="WetTemp" ItemsSource="{Binding}" IndependentValueBinding="{Binding Date}" DependentValueBinding="{Binding Value}">

           <DVC:LineSeries.DataPointStyle>

           </DVC:LineSeries.DataPointStyle>

         </DVC:LineSeries>

       </DVC:Chart.Series>

       <DVC:Chart.Axes>

         <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Temperature °F" Minimum="0" Maximum="300" Interval="10" Location="Left" />

         <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Humidity %" Minimum="0" Maximum="100" Interval="10" Location="Right" />

         <DVC:DateTimeAxis Orientation="X" ShowGridLines="True" IntervalType="Days">

           <DVC:DateTimeAxis.AxisLabelStyle>

           </DVC:DateTimeAxis.AxisLabelStyle>

         </DVC:DateTimeAxis>

       </DVC:Chart.Axes>

         <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Temperature °F" Minimum="0" Maximum="300" Interval="10" Location="Left" />

    But the catch is when I try to assign more than one series to the right, I am forced to assign each series with a statement like this :

           <DVC:LineSeries.DependentRangeAxis>

             <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Humidity %" Minimum="0" Maximum="100" Interval="10" Location="Right" />

           </DVC:LineSeries.DependentRangeAxis>

    This causes more than one rang to show on the right as I am creating an axis for each.   If I do not set this then It will fall through an select the left axis. Ive set the visibility of the axis to hidden but it leaves a gap where it was and if I collapse it, it collapses the series as well. Is there any way to assign a series to an axis like ?:  

    <DVC:LineSeries Title="Humidity" BoundAxisName="RightSideAxis">

    I've attached some code below in case It may help someone

         <DVC:LineSeries Title="Humidity" Name="Humidity" ItemsSource="{Binding}" IndependentValueBinding="{Binding Date}" DependentValueBinding="{Binding Value}">

           <DVC:LineSeries.DataPointStyle>

           </DVC:LineSeries.DataPointStyle>

           <DVC:LineSeries.DependentRangeAxis>

             <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Humidity %" Minimum="0" Maximum="100" Interval="10" Location="Right" />

           </DVC:LineSeries.DependentRangeAxis>

         </DVC:LineSeries>

         <DVC:LineSeries Title="Wet Temp" Name="WetTemp" ItemsSource="{Binding}" IndependentValueBinding="{Binding Date}" DependentValueBinding="{Binding Value}">

           <DVC:LineSeries.DataPointStyle>

           </DVC:LineSeries.DataPointStyle>

         </DVC:LineSeries>

       </DVC:Chart.Series>

       <DVC:Chart.Axes>

         <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Temperature °F" Minimum="0" Maximum="300" Interval="10" Location="Left" />

         <DVC:LinearAxis Orientation="Y" ShowGridLines="True" Title="Humidity %" Minimum="0" Maximum="100" Interval="10" Location="Right" />

         <DVC:DateTimeAxis Orientation="X" ShowGridLines="True" IntervalType="Days">

           <DVC:DateTimeAxis.AxisLabelStyle>

           </DVC:DateTimeAxis.AxisLabelStyle>

         </DVC:DateTimeAxis>

       </DVC:Chart.Axes>

  62. David Anson says:

    Al T.,

    It sounds like the difficulty arises because *both* Axes are suitable for each Series (otherwise the Series would select the correct one automatically). The thing I'd try is something like this: <DVC:LineSeries … DependentRangeAxis="{Binding ElementName=MyRightAxis}" /> Basically, instead of defining a new Axis inline (which creates a new instance and leads to the problems you describe), just tell the Series to share the same Axis instance you've already created. This might take a bit of cleverness to ensure the Binding/ElementName lookup resolves correctly, etc., but ought to work as you want once everything's hooked up properly. 🙂

    Hope this helps!

  63. sharon says:

    Hi

    Is there a sample for 3d charts ?

  64. David Anson says:

    sharon,

    No, sorry; 3D isn't supported at present.

  65. Laozhang says:

    Hi Delay ,I've a problem with exporting the WPF Chart to a JPEG or XPS format.

    Problem is that while the export goes well, the chart is not scaled, since only a percentage is displayed.

    but it can be displayed correctly in the WPF application.

    Here is my test code :

               Chart chartView = new Chart();

       chartView.BeginInit();

               chartView.Width = 300;

               chartView.Height = 250;

               chartView.Background = Brushes.Azure;

               PieSeries pieSeries = new PieSeries();

               Binding KeyBind = new Binding("Key");

               Binding ValueBind = new Binding("Value");

               pieSeries.Title = "Test";

               pieSeries.IndependentValueBinding = KeyBind;

               pieSeries.DependentValueBinding = ValueBind;

       KeyValuePair<object, double>[] itemsSource = new KeyValuePair<object, double>[] {

    new KeyValuePair<object, double>("Apple", 100.0),

    new KeyValuePair<object, double>("Orange", 200.0) };

       pieSeries.ItemsSource = itemsSource ;

       chartView.Series.Add(pieSeries);

           chartView.EndInit();

             RenderTargetBitmap renderTarget =

                   new RenderTargetBitmap((int)300,

                                       (int)250,

                                       96,

                                       96,

                                       System.Windows.Media.PixelFormats.Pbgra32);

               Size tmpSize = new Size(m_PrintWidth, m_PrintHeight);

               chartView.Measure(tmpSize);

               chartView.Arrange(new Rect(tmpSize));

               chartView.UpdateLayout();

               renderTarget.Render(chartView);

               PngBitmapEncoder encoder = new PngBitmapEncoder();

               encoder.Frames.Add(BitmapFrame.Create(renderTarget));

               using (FileStream pageOutStream = new FileStream(@"c:pie.png", FileMode.Create, FileAccess.Write))

               {

                   encoder.Save(pageOutStream);

                   pageOutStream.Close();

               }

    Am i doing wrong ?

    Thanks  a lot in advance for any hints!

  66. Laozhang says:

    Hi Delay,The code works perfectly if I display the chart in a window first,but if I don't display it in a window,I have got the image to save to file and the data on the X & Y axis legendArea is displayed but the plotArea on the graph are not drawn.

  67. David Anson says:

    Laozhang,

    Glad to hear you're making progress! Maybe something in the following post I did on printing a chart will be helpful to you: blogs.msdn.com/…/no-trees-were-harmed-in-the-making-of-this-blog-post-how-to-successfully-print-a-chart-with-the-silverlight-4-beta.aspx

  68. Laozhang says:

    Thanks for your reply.

    I am trying to create a WPF Chart without XAML in c# code(DLL file) and saving it to file(xps or image) without displaying it on screen.

    It didn't work.

  69. David Anson says:

    Laozhang,

    The techniques I describe shouldn't require the content be displayed on screen to work – and it should work the same whether it's created in code or XAML. Some other ideas: Are m_printWidth/Height in your example correct? Have you tried putting the content on screen to visually verify it? Does it work if printed after that?

  70. Laozhang says:

    Hi Delay, Thanks once more for a speedy response.I modified the code ,it displays perfectly in a WPF application, but when I save it to a xps file, it wasn't outputting the plotArea(legendArea was outputted).

          private void CreateChart()

           {

               Chart chartView = new Chart();

               int printWidth = 790;

               int printHeight = 1125;

               chartView.BeginInit();

               chartView.Width = 300;

               chartView.Height = 250;

               chartView.Background = Brushes.Azure;

               PieSeries pieSeries = new PieSeries();

               Binding KeyBind = new Binding("Key");

               Binding ValueBind = new Binding("Value");

               pieSeries.Title = "Test";

               pieSeries.IndependentValueBinding = KeyBind;

               pieSeries.DependentValueBinding = ValueBind;

               KeyValuePair<object, double>[] itemsSource = new KeyValuePair<object, double>[] {

               new KeyValuePair<object, double>("Apple", 100.0),

               new KeyValuePair<object, double>("Orange", 200.0) };

               pieSeries.ItemsSource = itemsSource;

               chartView.Series.Add(pieSeries);

               chartView.EndInit();

               var content = new Border

               {

                   BorderBrush = new SolidColorBrush(Colors.Magenta),

                   BorderThickness = new Thickness(10),

                   Child = chartView,

               };

               // Create container for putting content in the visual tree invisibly

               Grid visualTreeContainer = new Grid

               {

                   Width = 300,

                   Height = 250,

                   Opacity = 0,

               };

               // Put content in the visual tree to initialize

               visualTreeContainer.Children.Add(content);

               using (XpsDocument xpsDocument = new XpsDocument(@"c:test.xps", FileAccess.ReadWrite, CompressionOption.Maximum))

               {

                   XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

                   // PrintTicket

                   PrintTicket printTicket = new PrintTicket();

                   if (printWidth > printHeight)

                   {

                       printTicket.PageOrientation = PageOrientation.Landscape;

                   }

                   else

                   {

                       printTicket.PageOrientation = PageOrientation.Portrait;

                   }

                   VisualsToXpsDocument visWriter = xpsdw.CreateVisualsCollator(printTicket, printTicket) as VisualsToXpsDocument;

                   Size size = new Size(printWidth, printHeight);

                   content.Measure(size);

                   content.Arrange(new Rect(new Point(), size));

                   content.UpdateLayout();

                   visWriter.Write(content);

                   visWriter.EndBatchWrite();

                   visualTreeContainer.Children.Remove(content);

               }

           }

  71. David Anson says:

    Laozhang,

    It doesn't look like the code above accomodates for the default delayed fade-in of DataPoint instances that I discuss in blogs.msdn.com/…/no-trees-were-harmed-in-the-making-of-this-blog-post-how-to-successfully-print-a-chart-with-the-silverlight-4-beta.aspx You can give it time to settle or provide a custom (non-fading) Template for the DataPoints. Also, it *might* be helpful to simulate the measure/arrange pass a couple of times in a row – perhaps running that code just once isn't enough for everything to settle (i.e., if it calls Invalidate as part of layout, the code above won't accomodate that whereas the visual tree would).

  72. Taylor says:

    I was hoping to try to port the Silverlight Toolkit's latest features (we really need the charting with stacked series) over to WPF Toolkit and met lots of resistance.  Lots of differences between code and dependencies.  Is there any chance that WPF Toolkit will be updated with some of these pieces or should I consider it deprecated and go to a third party for charting controls (which sucks, because the code will have to be very different between the two platforms, whereas other custom controls [gauges] are all built so they can run in either easily.  With the internals changing between two platforms, makes it really hard to do a MVVM pattern, since the VM isn't perfectly applicable…

  73. David Anson says:

    Taylor,

    If you want to run the latest Data Visualization assembly code on multiple platforms, you probably want to have a look at my Data Visualization Development Release which provides multiple CSPROJs that do exactly that. 🙂 Here's a link to the latest which brings the April 2010 Silverlight Toolkit implementation to WPF:

    blogs.msdn.com/…/phone-y-charts-silverlight-wpf-data-visualization-development-release-4-and-windows-phone-7-charting-sample.aspx

  74. Taylor says:

    Thank you, David!  Awesome work!

    I tried porting it over myself and there were so many issues — I look forward to learning how you did this as well!

  75. Seevali says:

    Hi..

    How to databind a chart to a database table

  76. David Anson says:

    Seevali,

    Typically, you'll issue some kind of query against the database, form the results into a collection of objects, bind that data to a Series.ItemsSource property, and configure the In/DependentValuePath on the Series appropriately. I give an overview of the Chart-related steps in the following post:

    blogs.msdn.com/…/announcing-a-free-open-source-charting-solution-for-silverlight-silverlight-toolkit-released-today-at-pdc.aspx

    Regarding how to get the data out of the database, that's not specific to Charting and you're free to use whatever method (ex: Linq-to-SQL) you'd like.

    Hope this helps!

  77. I'm inserting a Chart object to a FlowDocument with the code:

        Paragraph p = new Paragraph();

        InLineUIContainer container = new InlineUIContainer(chart);

        p.Inlines.Add(container);

        rtb.Document.Blocks.Add(p);

    When I try to remove it from the FlowDocument with the code:

         p.Inlines.Remove(container);

    I get the following InvalidOperationException:

        "Cannot serialize a non-public type

        'System.Windows.Controls.DataVisualization.UniqueObservableCollection`1    

        [System.Windows.Controls.DataVisualization.Charting.IAxis]'."

    Please advise.

  78. David Anson says:

    Adolfo A Aguiar,

    Offhand, I'm not sure why you're seeing that. 🙁 The attempt to serialize isn't coming from the DataVis assembly, so you might look at the call stack to see where it's coming from and why (because deserializing on removal doesn't make sense to me at first glance). You might also download the source code for the DataVis assembly so you can build it yourself and maybe see if marking the relevant type as public is enough to get your scenario working? As far as I know, this isn't an issue normally, so I'm assuming it's related to FlowDocument/InlineUIContainer somehow…

    Hope this helps!

Comments are closed.