Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
260
Create series dynamically
posted

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!

Parents
  • 30692
    Offline posted

    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

    {

        public string Label { get; set; }

    }

    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

Reply Children