Hello!
I'm new to DataChart, and have a following question.
I need to create a line chart with several series, like this:
Series1: { X: 0, Y:0; X:1, Y:5; X:2,Y:10; X:3, Y:15 }Series2 may be like this: { X: 10, Y:10; X:11, Y:15; X:12,Y:110; X:13, Y:115 }Series3 may also be something different.
Normally I'd do it like this:
for( i = 0; i < 3; i++ ){ series = new LineSeries(); points = new points(); for( // all points ) { point = new point; // .... points.Add( point ); } series.ItemSource = points; chart.Series.Add( series );}
The question is -- what do I do with the XAxis? In the samples there is a line:
xmXAxis.ItemsSource = data;
But here it's not a simple data, it's an array of arrays of points. If I don't execute this line, the chart comes out empty. So, how whould I do this? Or would I better be off with WebChart in tis case (but what about performace?)?
Thanks in advance!
hi,
The xaxis expects an itemsource that has a set of items with a property on each that represents the category label.
This could be a sepereate itemsSource than any of your series, or it could be the same itemssource as one of your series.
For example if your items look like this:
public class DataItem
{
public string Label { get; set; }
public double Value { get; set; }
}
Then each of your series data sources would have a set of labels (usually the same, if you are trying to correllate the data). So you could assign any of those as the data source for the x axis and set its Label="{Label}" to tell it which property to get the labels from.
Alternatively, you could create a seperate itemssource to provide the category labels:
public class LabelItem
etc.
In general you can probably just assign your first series itemssource to the itemssource of the x axis, depending on what you are doing.
When dealing with category series, it is important that each itemssource have the same number of items, and be in the same order. Because the chart will not try to correlate your data for you.
Hope this helps!
-Graham
Thanks, I'm attaching the 1st serie to the ItemSource, and it seems to work. There is another problem, though.
Consider I have points with X values of 4, 5, 6, 7, 20, 21, 22, 23.Just now on the X axis I have no space between 7 and 20, and I would like to make it so that the marks for 8, 9, ..., 19 were present. Is that possible without adding stub points to the 1st serie just for the tickmarks to appear? Should I use ScatterLineSeries instead of LineSeries with NumericXAxis instead of CategoryXAxis?
If you have a situation where both of your axes are numerical it can often make sense to use a scatter type series rather than a category series. I really depends on your other requirements. If you want some of the other capabilities of the category series, clustering series by category, for example. Then you may want to use category series by padding the data such that you have zero values for a series where data was not present for that index. If you are dealing with large volumes of data the category series is also better performing than the scatter series, as we are able to make more assumptions about the shape of the data.
Meanwhile, if you have a very sparse representation of data, but must represent the spaces between the data points based on their differing x values then scatterlineseries may be much more appropriate.
If you could describe what you are trying to achieve in more detail I may be able to point you in the right direction.
Thanks for your reply!
I tried the scatter series, and it seems to do the trick, so I think I'll leave it as it is, at least for now.
Now I have another question. If I have data with X values being dates, I think that's where the CategoryDateTimeXAxis comes into play, doesn't it? And sometimes the chart rendering fails with the message:
Message: Unhandled Error in Silverlight Application Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.Collections.Generic.List`1.get_Item(Int32 index) at Infragistics.FastItemColumn.get_Item(Int32 index) at Infragistics.Controls.Charts.AnchoredCategorySeries.PrepareFrame(CategoryFrame frame) at Infragistics.Controls.Charts.CategorySeries.RenderSeries(Boolean animate) at Infragistics.Controls.Charts.CategorySeries.ViewportRectChangedOverride(Rect oldViewportRect, Rect newViewportRect) at Infragistics.Controls.Charts.Series.<OnApplyTemplate>b__a(Object o, SizeChangedEventArgs e) at System.Windows.FrameworkElement.OnSizeChanged(Object sender, SizeChangedEventArgs e) at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)Line: 1Char: 1Code: 0Message: Unhandled Error in Silverlight Application Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.Collections.Generic.List`1.get_Item(Int32 index) at Infragistics.FastItemColumn.get_Item(Int32 index) at Infragistics.Controls.Charts.AnchoredCategorySeries.PrepareFrame(CategoryFrame frame) at Infragistics.Controls.Charts.CategorySeries.RenderSeries(Boolean animate) at Infragistics.Controls.Charts.XamDataChart.<.ctor>b__d(Object o, AxisRangeChangedEventArgs e) at Infragistics.Controls.Charts.Axis.RaiseRangeChanged(AxisRangeChangedEventArgs ea) at Infragistics.Controls.Charts.NumericAxisBase.UpdateRange() at Infragistics.Controls.Charts.NumericYAxis.ViewportChangedOverride(Rect oldRect, Rect newRect) at Infragistics.Controls.Charts.Axis.<.ctor>b__5(Object o, SizeChangedEventArgs e) at System.Windows.FrameworkElement.OnSizeChanged(Object sender, SizeChangedEventArgs e) at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)Line: 1Char: 1Code: 0I suspect the problem is that we have a setting in our system that limits the number of points rendered in the chart. So it may happen that there are 4 series with 24 points, and 1 serie with 4 points -- and that's when the exception happens. For now I've put an IF checking that if a serie has less points than the 1st one, it doesn't get added -- but is that a proper solution, or just a workaround, and is there a better solution in the latter case?
Hi,
Which version are you using? This sounds like a bug that has already been resolved. Could you provide a small sample that replicates it?
With categoryXAxis, you can use dates, they are just treated like string values, so you wont see a larger space between values if there is a large time between them. If your sampling rate is constant though, this shouldn't matter. CategoryDateTimeXAxis will allow for different time spans between different data points to be represented as different spacings, rather than everything being equidistant.
This is for use with category type series though, so if you are using a scatter line series, you will have to use a NumericXAxis for the dates. If you do a search on these forums you should see examples of using a numericXAxis with date time values.
For CategoryDateTimeXAxis I use LineSeries of course instead of ScatterLineSeries, and apart from this issue this seems to work quite ok.
I will put a sample tomorrow, if I have time. The version we use is 10.2For now I think you very much for your support! :)
Certainly there have been some issues fixed with CategoryDateTimeXAxis since the first version of 10.2. I would recommend updating to the latest service release if you can, and a later volume release if possible, as there have also been some performance improvements to all series types since 10.2.