Jump to content
Software FX Community

Candlestick Example Chart?


charlierobbins

Recommended Posts

Is there anywhere that I can find a declarative example for how to use the Candlestick Gallery? I've been pouring over your documentation, but there doesn't seem to be much regarding candlestick charts. Specifically, I'm curious what I should set the BindingPath attribute on the SeriesAttributes object I am setting for Chart.Series. For standard charts (i.e. charts with two data points, not four) there is "BindingPath," "BindingPathX", etc. Thanks

 

Charlie

Link to comment
Share on other sites

To create a Candlestick chart you need to create a chart with 4 series, and use BindingPath on each of these series, e.g.

<XmlDataProvider x:Key="MyData" XPath="OHLCData/OHLC"><x:XData><OHLCData xmlns=""><OHLC Low="20" High="30" Open="22" Close="26"/><OHLC Low="12" High="32" Open="28" Close="22"/><OHLC Low="24" High="30" Open="24.5" Close="29.5"/><OHLC Low="20" High="30" Open="22" Close="26"/><OHLC Low="12" High="32" Open="28" Close="22"/><OHLC Low="24" High="30" Open="24.5" Close="29.5"/><OHLC Low="20" High="30" Open="22" Close="26"/><OHLC Low="12" High="32" Open="28" Close="22"/><OHLC Low="24" High="30" Open="24.5" Close="29.5"/><OHLC Low="20" High="30" Open="22" Close="26"/><OHLC Low="12" High="32" Open="28" Close="22"/><OHLC Low="24" High="30" Open="24.5" Close="29.5"/><OHLC Low="20" High="30" Open="22" Close="26"/><OHLC Low="12" High="32" Open="28" Close="22"/><OHLC Low="24" High="30" Open="24.5" Close="29.5"/></OHLCData></x:XData></XmlDataProvider>

<cfx:Chart Gallery="Candlestick" x:Name="chart1" Grid.Row="2" Margin="10" ItemsSource="{Binding Source={StaticResource MyData}}"><cfx:Chart.Series><cfx:SeriesAttributes BindingPath="@Open" GroupContent="Nasdaq"/><cfx:SeriesAttributes BindingPath="@High"/><cfx:SeriesAttributes BindingPath="@Low"/><cfx:SeriesAttributes BindingPath="@Close"/></cfx:Chart.Series></cfx:Chart>

Please note that the order of the series should always be Open - High - Low - Close

Regards,

JuanC

Link to comment
Share on other sites

Juan,

    Thanks for the initial help. I got your example working, but I do not plan on using an XmlDataProvider in my application. Do you have any examples that have the ItemsSource of the Chart databound to an ObservableCollection of a custom data object? I have tried getting this to work using a simple binding:

 <cfx:Chart x:Name="CandlestickChart" ItemsSource="{Binding SampleData}" Gallery="Candlestick">

 Where SampleData is an ObservableCollection<CandleStickDataItem>. CandleStickDataItem has Properties on it called High, Low, Open and Close. I then modified the <SeriesAttributes>:

<cfx:SeriesAttributesCollection>   <cfx:SeriesAttributes BindingPath="Open"/>   <cfx:SeriesAttributes BindingPath="High"/>   <cfx:SeriesAttributes BindingPath="Low"/>   <cfx:SeriesAttributes BindingPath="Close"/>   </cfx:SeriesAttributesCollection>

 But I got no results shown. Any advice on using this functionality correctly?

 Also we are building a highly stylized application and I can't seem to find a good way to style a CandleStick chart. It seems quite simple for a bar or pie chart as shown in your sample; I simply utilize <SeriesAttribute.Template />. What's the correct approach for a CandleStick? Thanks

Charlie

Link to comment
Share on other sites

If you want to setup your data in XAML you will be using an ObjectDataProvider in your resources and your ItemsSource should be set to a Binding whose Source is the ObjectDataProvider, e.g.<Grid.Resources><ObjectDataProvider x:Key="bidsData" ObjectType="{x:Type localData:Bids}" /></Grid.Resources>

<

cfx:Chart x:Name="chart1" ItemsSource="{Binding Source={StaticResource bidsData}}">

If you want to set your data in code, you can just set the ItemsSource property to your collection.

Note that this is independent of the gallery you use.

About styling your candlestick chart, please send an email to wpf at softwarefx dot com.

Regards,

JuanC

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...