Hi There,
I want to display TickData(FinancialPriceSeries) and FillData(ScatterSeries) on same DataChart. X-Axis has timestamp and Y-Axis has price value. Here is the part of code
public class TickDataPoint {.........................
public int Index { get { return _index; } set { if (_index == value) return; _index = value; OnPropertyChanged("Index"); } } public double Open { get { return _open; } set { if (_open == value) return; _open = value; OnPropertyChanged("Open"); } } public double High { get { return _high; } set { if (_high == value) return; _high = value; OnPropertyChanged("High"); } } public double Low { get { return _low; } set { if (_low == value) return; _low = value; OnPropertyChanged("Low"); } } public double Close { get { return _close; } set { if (_close == value) return; _close = value; OnPropertyChanged("Close"); } } public double Volume { get { return _volume; } set { if (_volume == value) return; _volume = value; OnPropertyChanged("Volume"); } } public DateTime Date { get { return _date; } set { if (_date == value) return; _date = value; OnPropertyChanged("Date"); } } ................................................... }
=========
public class FillDataPoint : ObservableModel{ ............................ public double FillPrice { get { return _fillPrice; } set { if (_fillPrice == value) return; _fillPrice = value; OnPropertyChanged("FillPrice"); }} public DateTime Date{get { return _date; }set { if (_date == value) return; _date = value; OnPropertyChanged("Date"); }} public string Side{get { return _side; }set { if (_side == value) return; _side = value; OnPropertyChanged("Side"); }} ......................}
public class DataCollection
{
ObservableCollection<TickDataPoint> _tickDataPoints = GetTickData(); ObservableCollection<FillDataPoint> _fillDataPoints = GetTradeData();
}
========================
<ig:XamDataChart x:Name="PriceChart" Legend="{Binding ElementName=PriceLegend}" Margin="5" VerticalZoomable="True" HorizontalZoomable="True" Grid.Row="1" > <ig:SyncManager.SyncSettings> <ig:SyncSettings SyncChannel="syncDynamicCharts" SynchronizeHorizontally="True" SynchronizeVertically="False" /> </ig:SyncManager.SyncSettings> <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="DateXAxis" Label="{}{Date:HH:mm:ss}"> <ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideBottom" Extent="30" Visibility="Collapsed" /> </ig:CategoryXAxis.LabelSettings> </ig:CategoryXAxis> <ig:NumericYAxis x:Name="PriceYAxis" > <ig:NumericYAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideLeft" Extent="55" /> </ig:NumericYAxis.LabelSettings> </ig:NumericYAxis> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:FinancialPriceSeries x:Name="TickDataSeries" Title="Stock Price" DisplayType="Candlestick" OpenMemberPath="Open" CloseMemberPath="Close" HighMemberPath="High" LowMemberPath="Low" VolumeMemberPath="Volume" XAxis="{Binding ElementName=DateXAxis}" YAxis="{Binding ElementName=PriceYAxis}"> </ig:FinancialPriceSeries> <ig:ScatterSeries x:Name="FillDataSeries" MarkerType="Circle" XMemberPath="Date" YMemberPath="FillPrice" XAxis="{Binding ElementName=DateXAxis}" YAxis="{Binding ElementName=PriceYAxis}"> </ig:ScatterSeries> </ig:XamDataChart.Series> </ig:XamDataChart>
=====================================================
I tried
TickDataSeries.DataContext = _dataCollection.TickDataPoints;FillDataSeries.DataContext = _dataCollection.FillDataPoints;
And
TickDataSeries.ItemSource = _oneTickDataModel.TickDataPoints;FillDataSeries.ItemSource = _oneTickDataModel.FillDataPoints;
===========
How can I bind two different Observable collection to these two different series of same chart?
Please let me know.
Thanking you in advance for your help.
Nasir
I am still waiting if anyone knows how to draw Financial Series (TickData) and Point Series (FillData) on same data chart. Both series are bound to different data source.
I made some changes in the code and was able to plot the FillData points with Tickdata points. But all the filldata points are drawing in one line.
===============================================
<ig:XamDataChart x:Name="PriceChart" Legend="{Binding ElementName=PriceLegend}" Margin="5" VerticalZoomable="True" HorizontalZoomable="True" Grid.Row="1" > <ig:SyncManager.SyncSettings> <ig:SyncSettings SyncChannel="syncDynamicCharts" SynchronizeHorizontally="True" SynchronizeVertically="False" /> </ig:SyncManager.SyncSettings> <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="DateXAxis" Label="{}{Date:HH:mm:ss}"> <ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideBottom" Extent="30" /> </ig:CategoryXAxis.LabelSettings> </ig:CategoryXAxis> <ig:NumericYAxis x:Name="PriceYAxis" > <ig:NumericYAxis.LabelSettings> <ig:AxisLabelSettings Location="OutsideLeft" Extent="55" /> </ig:NumericYAxis.LabelSettings> </ig:NumericYAxis> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:FinancialPriceSeries x:Name="TickDataSeries" Title="Stock Price" DisplayType="Candlestick" OpenMemberPath="Open" CloseMemberPath="Close" HighMemberPath="High" LowMemberPath="Low" VolumeMemberPath="Volume" XAxis="{Binding ElementName=DateXAxis}" YAxis="{Binding ElementName=PriceYAxis}"> </ig:FinancialPriceSeries> <ig:PointSeries x:Name="FillDataSeries" ValueMemberPath="FillPrice" XAxis="{Binding ElementName=DateXAxis}" YAxis="{Binding ElementName=PriceYAxis}"> </ig:PointSeries> </ig:XamDataChart.Series> </ig:XamDataChart>
===================================
DateXAxis.ItemsSource = _oneTickDataModel.TickDataPoints;TickDataSeries.ItemsSource = _oneTickDataModel.TickDataPoints;FillDataSeries.ItemsSource = _oneTickDataModel.FillDataPoints;
=========================================
Can anyone check what is wrong here?
Is there any other way to draw these data on DataChart?
Thanks
Hello Nasir,
Thank you for your post. I have been looking into and I created a sample project for you with the functionality you want. Also I can say that for the ScatterLineSeries yo uneed two numeric Axes.
Hope this helps you.
Stephen,
That's exactly I am expecting. But data points are not aligned. Please run this sample.
=========================================================================
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ig="http://schemas.infragistics.com/xaml" x:Class="WpfApplication1.MainWindow" Title="MainWindow" Height="350" Width="525"> <Grid> <ig:XamDataChart x:Name="PriceChart" VerticalZoomable="True" HorizontalZoomable="True" > <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="FinancialPriceSeriesXAxis" Label="{}{Date:HH:mm:ss}"> <ig:CategoryXAxis.LabelSettings> <ig:AxisLabelSettings /> </ig:CategoryXAxis.LabelSettings> </ig:CategoryXAxis> <ig:CategoryXAxis x:Name="PointSeriesXAxis" Label="{}{Date:HH:mm:ss}"> </ig:CategoryXAxis> <ig:NumericYAxis x:Name="PriceYAxis" > </ig:NumericYAxis> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:FinancialPriceSeries x:Name="TickDataSeries" Title="Stock Price" DisplayType="Candlestick" OpenMemberPath="Open" CloseMemberPath="Close" HighMemberPath="High" LowMemberPath="Low" VolumeMemberPath="Volume" XAxis="{Binding ElementName=FinancialPriceSeriesXAxis}" YAxis="{Binding ElementName=PriceYAxis}"> </ig:FinancialPriceSeries> <ig:PointSeries x:Name="FillDataSeries" MarkerType="Circle" ValueMemberPath="Value1" XAxis="{Binding ElementName=PointSeriesXAxis}" YAxis="{Binding ElementName=PriceYAxis}"> </ig:PointSeries> </ig:XamDataChart.Series> </ig:XamDataChart> </Grid></Window>=================================================================================================using Infragistics.Controls.Charts;namespace WpfApplication1{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); ObservableCollection<Data> _tickDataPoints = new ObservableCollection<Data>(); _tickDataPoints.Add(new Data{Close=100, Date = new DateTime(2013, 03, 13, 1, 15, 00), High=105, Low=98, Open=103, Label = "Item1"}); _tickDataPoints.Add(new Data { Close = 102, Date = new DateTime(2013, 03, 13, 1, 15, 00), High = 107, Low = 98, Open = 105, Label = "Item2" }); _tickDataPoints.Add(new Data { Close = 104, Date = new DateTime(2013, 03, 13, 1, 30, 00), High = 109, Low = 100, Open = 107, Label = "Item3" }); _tickDataPoints.Add(new Data { Close = 106, Date = new DateTime(2013, 03, 13, 1, 45, 00), High = 111, Low = 102, Open = 109, Label = "Item4" }); _tickDataPoints.Add(new Data { Close = 108, Date = new DateTime(2013, 03, 13, 2, 00, 00), High = 113, Low = 104, Open = 111, Label = "Item5" }); _tickDataPoints.Add(new Data { Close = 110, Date = new DateTime(2013, 03, 13, 2, 15, 00), High = 115, Low = 106, Open = 113, Label = "Item6" }); _tickDataPoints.Add(new Data { Close = 112, Date = new DateTime(2013, 03, 13, 2, 30, 00), High = 117, Low = 108, Open = 115, Label = "Item7" }); _tickDataPoints.Add(new Data { Close = 114, Date = new DateTime(2013, 03, 13, 2, 45, 00), High = 119, Low = 110, Open = 117, Label = "Item8" }); _tickDataPoints.Add(new Data { Close = 116, Date = new DateTime(2013, 03, 13, 3, 00, 00), High = 121, Low = 112, Open = 119, Label = "Item9" }); _tickDataPoints.Add(new Data { Close = 118, Date = new DateTime(2013, 03, 13, 3, 15, 00), High = 123, Low = 114, Open = 121, Label = "Item10" }); _tickDataPoints.Add(new Data { Close = 120, Date = new DateTime(2013, 03, 13, 3, 30, 00), High = 125, Low = 116, Open = 123, Label = "Item11" }); _tickDataPoints.Add(new Data { Close = 122, Date = new DateTime(2013, 03, 13, 3, 45, 00), High = 127, Low = 118, Open = 125, Label = "Item12" }); _tickDataPoints.Add(new Data { Close = 124, Date = new DateTime(2013, 03, 13, 4, 00, 00), High = 129, Low = 120, Open = 127, Label = "Item13" }); _tickDataPoints.Add(new Data { Close = 126, Date = new DateTime(2013, 03, 13, 4, 15, 00), High = 131, Low = 122, Open = 129, Label = "Item14" }); _tickDataPoints.Add(new Data { Close = 128, Date = new DateTime(2013, 03, 13, 4, 30, 00), High = 133, Low = 124, Open = 131, Label = "Item15" }); _tickDataPoints.Add(new Data { Close = 130, Date = new DateTime(2013, 03, 13, 4, 45, 00), High = 135, Low = 126, Open = 133, Label = "Item16" }); _tickDataPoints.Add(new Data { Close = 132, Date = new DateTime(2013, 03, 13, 5, 00, 00), High = 137, Low = 128, Open = 135, Label = "Item17" }); _tickDataPoints.Add(new Data { Close = 134, Date = new DateTime(2013, 03, 13, 5, 15, 00), High = 139, Low = 130, Open = 137, Label = "Item18" }); _tickDataPoints.Add(new Data { Close = 136, Date = new DateTime(2013, 03, 13, 5, 30, 00), High = 141, Low = 132, Open = 139, Label = "Item19" }); _tickDataPoints.Add(new Data { Close = 138, Date = new DateTime(2013, 03, 13, 5, 45, 00), High = 143, Low = 134, Open = 141, Label = "Item20" }); _tickDataPoints.Add(new Data { Close = 140, Date = new DateTime(2013, 03, 13, 6, 00, 00), High = 145, Low = 136, Open = 143, Label = "Item21" }); ObservableCollection<ChartData> _fillDataPoints = new ObservableCollection<ChartData>(); _fillDataPoints.Add(new ChartData { Date=new DateTime(2013, 03, 13, 2, 15, 00), Value1=115, Value2 = 115, Value3 = 115}); _fillDataPoints.Add(new ChartData { Date = new DateTime(2013, 03, 13, 2, 35, 00), Value1 = 117, Value2 = 117, Value3 = 117 }); _fillDataPoints.Add(new ChartData { Date = new DateTime(2013, 03, 13, 2, 55, 00), Value1 = 120, Value2 = 120, Value3 = 120 }); _fillDataPoints.Add(new ChartData { Date = new DateTime(2013, 03, 13, 3, 15, 00), Value1 = 123, Value2 = 123, Value3 = 117 }); _fillDataPoints.Add(new ChartData { Date = new DateTime(2013, 03, 13, 3, 45, 00), Value1 = 117, Value2 = 117, Value3 = 117 }); _fillDataPoints.Add(new ChartData { Date = new DateTime(2013, 03, 13, 4, 15, 00), Value1 = 131, Value2 = 131, Value3 = 131 }); _fillDataPoints.Add(new ChartData { Date = new DateTime(2013, 03, 13, 4, 25, 00), Value1 = 133, Value2 = 133, Value3 = 133 }); _fillDataPoints.Add(new ChartData { Date = new DateTime(2013, 03, 13, 4, 45, 00), Value1 = 135, Value2 = 135, Value3 = 135 }); FinancialPriceSeriesXAxis.ItemsSource = _tickDataPoints; PointSeriesXAxis.ItemsSource = _tickDataPoints; (PriceChart.Series[0] as FinancialPriceSeries).ItemsSource = _tickDataPoints; (PriceChart.Series[1] as PointSeries).ItemsSource = _fillDataPoints; } }============================================================================================================================================================== public class Data : INotifyPropertyChanged { private int open; private int close; private int high; private int low; private int value; private string label; private DateTime date; public DateTime Date { get { return date; } set { date = value; PropChanged("Date"); } } public string Label { get { return label; } set { label = value; PropChanged("Label"); } } public int Open { get { return open; } set { open = value; PropChanged("Open"); } } public int Close { get { return close; } set { close = value; PropChanged("Close"); } } public int High { get { return high; } set { high = value; PropChanged("High"); } } public int Low { get { return low; } set { low = value; PropChanged("Low"); } } public int Value { get { return value; } set { this.value = value; PropChanged("Value"); } } public event PropertyChangedEventHandler PropertyChanged; public void PropChanged(string name) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(name)); } } public class ChartData { public DateTime Date { get; set; } public double Value1 { get; set; } public double Value2 { get; set; } public double Value3 { get; set; } }}
=================================================================================
See the result. First FillDataPoint is plotting at 1:15:00 (YAxis value = 115) instead of 2:15:00. And last FillDataPoint is plotted at 2:45:00 ((YAxis value = 115) instead of 4:45:00. There are 5 data points for both Fill and Tick at same time (2:15:00, 3:15:00, 3:45:00, 4:15:00 and 4:45:00) but they are plotting on different time.
Please run this program and let me know how to fix this.
I have created a sample project for you, using the code you have provided, with the functionality you want. Basically I used CategoryDateTimeXAxis instead of CategoryXAxis and I set its MinimumValue and MaximumValue Properties, so now the Datapoints are aligned.
Hi Stefan,
Thanks for your help. I can see expected result in the sample.
But in my application when I tried to use CategoryDateTimeXAxis instead of CategoryXAxis it is taking very long (or application hung) to plot the points. I have more than 30,000 TickDataPoint and around 200 FillDataPoint.
And if I change back to CategoryXAxis it works fine but Datapoints aren't aligned as before.
You can change your previous sample to generate more than 30,00 TickData points and 200 FillData Points and check the result.
Let me know what can be the issue here.
Hello Nasir
To achieve the functionality you want, you have to use CategiryDateTimeXAxis, because the spaces between data points, based on the amount of time span between them, are important and since CategiryDateTimeXAxis perform sorts on the data it is expected the it takes more time to load than the CategoryXAxis. Also I can say that both Axis should have the same Minimum and Maximum Values equal to the Minimum and Maximum Date of the TickDataPoint collection.
Hi Stefen,
Thanks for your help. I got the point. I will do work around to reduce the time.
I have other question related to same application.
How can I change/format the color for FinancialSeries. I want Candle Stick to be red or blue. I also want to change the color of point in PointSeries based on value.
Please let me know and if its possible give me sample code.
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Stefen,
Thanks for your help.
I have modified the sample, so now it has the functionality you want. Basically I set FinancialPriceSeries' NegativeBrush in order to make the Series Red. Also I create a MarkerTempalte for the PointSeries and used a Converter to set the color based on the value.