Hello All,
In my first scenario, I had to build a chart with numeric Xaxis and numeric Yaxis (in the code behind). It worked like a charm when I defined it as:
series = new ScatterSeries();series.ItemsSource = model.CDFResults[i].DataPoints; series.MarkerType = MarkerType.Circle; series.XMemberPath = "dt"; series.YMemberPath = "value"; series.XAxis = (NumericXAxis)NEWCHART.Axes.Where(x => x.Name == "thisisX").FirstOrDefault() as NumericXAxis; series.YAxis = (NumericYAxis)NEWCHART.Axes.Where(x => x.Name == "thisisY").FirstOrDefault() as NumericYAxis; series.ShowDefaultTooltip = true;
NEWCHART.Series.Add(series);
Now in the second case, the X axis needs to be datetime or Date.
I couldn't find any option as series.CATEGORYDATETIME.. how do I define X axis as datetime type in the code behind? Please advice. Thanks!
Hello Priyank,
Thank you for your post!
For the series in the XamDataChart, there are not separate properties for setting certain types of axes. This is done via the XAxis and YAxis properties only. However, there are two main types of series - Category and Numeric, and these series types define the types of axes that you can assign to those XAxis and YAxis properties. The ScatterSeries is of a numeric series type, and so it can only be used directly with the NumericXAxis and NumericYAxis. Usage of the CategoryDateTime-related axes with a ScatterSeries is currently unsupported.
This is not to say that you cannot have your chart display Dates as the labels for those axes though. I would like you to take a look at this blog post which outlines the way you can display dates as your labels for NumericX or NumericY axes: http://ko.infragistics.com/community/blogs/kiril_matev/archive/2010/07/14/using-date-labels-with-scatter-series-in-the-xamdatachart.aspx.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hello Andrew.
Thanks for the reply.
I could not make it work in my case. Firstly, I am doing data binding in the code behind. Could you please advice?
This is how I achieve data binding:
CDFResults is the observable collection in the view model.
for (int i = 0; i < model.CDFResults.Count; i++)
{
series = new ScatterLineSeries();
series.ItemsSource = model.CDFResults[i].DataPoints;
series.XMemberPath = "dt";
series.YMemberPath = "value";
series.XAxis = (NumericXAxis)NEWCHART.Axes.Where(x => x.Name == "thisisX").FirstOrDefault() as NumericXAxis;
series.YAxis = (NumericYAxis)NEWCHART.Axes.Where(x => x.Name == "thisisY").FirstOrDefault() as NumericYAxis;
series.ShowDefaultTooltip = true;
series.Title = model.CDFPlotCollection[i].categoryname;
NEWCHART.Series.Add(series); }
Then I added the converter class that you suggested and added the label setting for numericX axis in the xaml as:
<ig:NumericXAxis x:Name="thisisX" MajorStrokeThickness="1" MinorStrokeThickness="1" ><ig:NumericXAxis.Label> <DataTemplate> <TextBlock Text="Converter={StaticResource TicksToDateTimeConverter}}" /> </DataTemplate> </ig:NumericXAxis.Label> </ig:NumericXAxis>
Note that I removed the binding part in the XAML and only mentioned converter.
Thanks!
Priyank
I imagine that from the code you have provided for the Text property of your TextBlock above is that once the chart loads, you are seeing "Converter={StaticResource TicksToDateTimeConverter}}" as each of the labels for your axis.
As you are doing your work mostly in code-behind, I have created a sample project that constructs the chart described in the aforementioned blog post completely in code behind. If you would like to continue doing this in XAML, the correct syntax for the binding for your axis label would be Text="{Binding Item, Converter={StaticResource TicksToDateTimeConverter}}."
I have attached the sample code-behind project. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.