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!
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?
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