Spline Series chart has odd starting angle when data series starts with nulls.

8 posts, 0 answers
  1. Martin
    Martin avatar
    5 posts
    Member since:
    Jul 2012

    Posted 10 Jul 2012 Link to this post

    Hello,

    We are using Telerik RadControls for WPF Q2 2011 SP1. We're attempting to create a chart having two data series (viz. history and forecast) using two spline series. The data history series starts with values and ends with a series of nulls. The forecast starts with nulls (where the history has values) and ends with values (where history has nulls).

    Now, the history series starts at the left and renders correctly. The problem is the forecast series that only starts further to the right. The initial line starts at a totally inappropriate angle and tends to do some looping effect. The further right, the worse it is. I guess this has to do with the spline initial control points, but as far as I can see I can't control those...

    Below is a very simple example that should illustrate the problem. Also see the example images attached.

    I have tried setting the EndPointBehaviour but it doesn't fix the problem (and we cannot use Zero since the data doesn't start from zero).

    Any assistance would be greatly appreciated.
    thanks

    public MainWindow()
    {
        InitializeComponent();
     
        var data = new DataTable();
        data.Columns.Add(new DataColumn { ColumnName = "X", DataType = typeof(int) });
        data.Columns.Add(new DataColumn { ColumnName = "Y", DataType = typeof(double) });
        var rnd = new Random();
        for (var i = 0; i < 40; i++)
        {
            var row = data.NewRow();
            row[0] = i;
            row[1] = (i < 30) ? (object)DBNull.Value : (double)rnd.Next(500);
            data.Rows.Add(row);
        }
        chart.ItemsSource = data;
     
        var seriesDefinition = new SplineSeriesDefinition();
        seriesDefinition.ShowPointMarks = false;
        seriesDefinition.ShowItemLabels = false;
        seriesDefinition.EmptyPointBehavior = EmptyPointBehavior.Gap;   // Gap, Drop, Zero
     
        var mapping = new SeriesMapping();
        mapping.SeriesDefinition = seriesDefinition;
        mapping.SeriesDefinition.Appearance.Stroke = new SolidColorBrush(Colors.Red);
        mapping.ItemMappings.Add(new ItemMapping(data.Columns[0].ColumnName, DataPointMember.XCategory) { FieldType = data.Columns[0].DataType });
        mapping.ItemMappings.Add(new ItemMapping(data.Columns[1].ColumnName, DataPointMember.YValue) { FieldType = data.Columns[1].DataType });
        chart.SeriesMappings.Add(mapping);
    }
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 13 Jul 2012 Link to this post

    Hi Martin,

    Indeed there seems to be an issue with this. I can only suggest that you do not add rows that do not carry information - meaning do not add the row if the value is null.

    All the best,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Martin
    Martin avatar
    5 posts
    Member since:
    Jul 2012

    Posted 13 Jul 2012 Link to this post

    Hi Petar,

    Thanks for your response.

    I'm not sure, maybe what you suggest isn't possible in my situation. My example only illustrated with a single series for simplicity, but as I mentioned, we will have two data series in our application. They are pulled together from the database into a DataTable, and that data table is then assigned to chart.ItemSource. The DataTable looks something like this:

    X        Value1        Value2
    0        100              null
    1        200              null
    2        300              null
    3        null              150
    4        null              250

    It is the Value2 series that is the problematic one. As far as i can see (though maybe I'm mising something) one has to use the same chart.ItemSource for all of the series on that chart. If so, I can't then provide it also with a different data table that doesn't have those initial nulls. Do you possibly have any alternate suggestions?

    Regards,
    Martin

  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 16 Jul 2012 Link to this post

    Hi Martin,

    I can see that the bigger picture is more complex. RadChart exposes a property called ItemsSource, which you can use. Each series mapping also exposes an ItemsSource property. When you don't set this property, the series mapping gets its items source from the chart's ItemsSource property. So there, you can use a different collection for each series you define.

    If you only have these missing values (nulls) at the start and at the end of your table - you can use the previously suggested approach - remove these empty points, create two different collections and pass them to the corresponding series mapping.

    I suspect that this will not be the case. If your data is fractional (12, 23, 1, 2, null, null, null, 56, 65, null, null, 54, 45, 11 and so on..) then a more complex solution is needed.

    1. One thing I can suggest is to break the incoming data into small collections with no empty items in them. From the example above - (12, 23, 1, 2), (56, 65), (54, 45, 11). And then for each collection you can create a new series. If you go this way you will also need to put the legend into a manual mode. I have attached a simple app to demonstrate this.

    2. You can try the Zero mode, instead of Gap and see if you like the results.

    3. Another suggestion I can make is not to use the Spline series and use Line series, where such an issue will not exist.

    Greetings,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Martin
    Martin avatar
    5 posts
    Member since:
    Jul 2012

    Posted 16 Jul 2012 Link to this post

    Hi Petar,

    Many thanks, I didn't know about the separate ItemsSource for each series. I will see whether we can make use of that for now. Hopefully this can be fixed in some future version though.

    From what I remember doing previously, it didn't appear that nulls within the series gave issues; when the EndPointBehaviour was set to e.g. Gap it left gaps as I would have expected. It was just the intial nulls that were problematic.

    Regards,
    Martin
  7. Martin
    Martin avatar
    5 posts
    Member since:
    Jul 2012

    Posted 18 Jul 2012 Link to this post

    Hi,

    The suggestion about creating a "private" subset of the data for the series using its mapping's ItemSource did the trick.

    The only real complication from our side was ensuring that such graphs are added to the chart after we've already added those that start from the first X value. Otherwise the X axis values can get out of sequence (such as 3, 4, 0, 1, 2 instead of 0, 1, 2, 3, 4 in my example).

    Many thanks,
    Martin
  8. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 19 Jul 2012 Link to this post

    Hi Martin,

    I am glad that you have managed to find a solution. Only one thing bugs me, though:
    Otherwise the X axis values can get out of sequence (such as 3, 4, 0, 1, 2 instead of 0, 1, 2, 3, 4 in my example).

    The reason you get this is because you are using XCategory and not XValue. Categories are usually very different and cannot be compared and sorted (Bananas, Apples ..) and this is why the output is not sorted. If you change the mapping to use XValue it should be fine without any work-around. See if your project will benefit out of this change.
     
    Regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Martin
    Martin avatar
    5 posts
    Member since:
    Jul 2012

    Posted 19 Jul 2012 Link to this post

    Hello,

    It's largely appropriate for our greater system to use categories in this case, as it's part of a more generalised setup that can (depending on what the user decides) use names on the X axis instead of values. But thanks for pointing this out. I do maybe need to rethink whether to change it when the X axis data type is numeric.

    Regards,
    Martin

Back to Top
UI for WPF is Visual Studio 2017 Ready