error using 3DSeriesDefinition with DataSeries

2 posts, 0 answers
  1. Brian Graves
    Brian Graves avatar
    48 posts
    Member since:
    May 2010

    Posted 30 Jun 2010 Link to this post

    I'm  getting the following error when attempting to  use Line3DSeriesDefinition (doesn't occur when using LineSeriesDefinition) for my DataSeries Definition:
    Error: Unhandled Error in Silverlight Application
    Code: 4004   
    Category: ManagedRuntimeError      
    Message: System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik.Windows.Controls.Charting.ChartArea.ClearLogicalChildren()
       at Telerik.Windows.Controls.Charting.ChartArea.PopulateLogicalChildren()
       at Telerik.Windows.Controls.Charting.ChartArea.OnApplyTemplate()
       at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)    

    I'm using the lastest SP of Telerik version 3 (not able to update to version 4 without VS2010).  The examples I've seen use SeriesMapping for 3D but I want to use DataSeries like I do with 2D...is this possible?  Here's my code:

                chartReport.DefaultView.ChartArea.DataSeries.Clear();
                chartReport.DefaultView.ChartArea.ItemClick += RadChart1ChartItemClicked;

                if (chartReport.DefaultView.ChartArea.AdditionalYAxes.Count > 0)
                {
                    chartReport.DefaultView.ChartArea.AdditionalYAxes[0].AxisName = _rs.ChartSecondaryYAxis;
                }
                else
                {
                    AxisY series2Axis = new AxisY();
                    series2Axis.AxisName = _rs.ChartSecondaryYAxis;
                    chartReport.DefaultView.ChartArea.AdditionalYAxes.Add(series2Axis);
                }

                chartReport.DefaultView.ChartTitle.Visibility = Visibility.Collapsed;
                chartReport.DefaultView.ChartArea.AxisX.LabelRotationAngle = 30;
                chartReport.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.None;
                chartReport.DefaultView.ChartArea.ZoomScrollSettingsY.ScrollMode = ScrollMode.None;
                chartReport.DefaultView.ChartArea.AxisY.AutoRange = true;

                DataSeries dataSeries1 = new DataSeries();

                if (_rs.ChartDimension.ToLower() == "3d")
                    chartReport.DefaultView.ChartArea.Extensions.Add(new CameraExtension());

                if (_rs.ChartType.ToLower() == "line")
                {
                    if (_rs.ChartDimension.ToLower() == "2d")
                        dataSeries1.Definition = new LineSeriesDefinition();
                    else
                        dataSeries1.Definition = new Line3DSeriesDefinition();
                }
                else
                {
                    if (_rs.ChartDimension.ToLower() == "2d")
                        dataSeries1.Definition = new BarSeriesDefinition();
                    else
                        dataSeries1.Definition = new Bar3DSeriesDefinition();
                }

                dataSeries1.LegendLabel = _rs.ChartPrimaryYAxis;
                dataSeries1.Definition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;

                DataSeries dataSeries2 = null;
                if (_rs.UseChartSecondaryYAxis)
                {
                    dataSeries2 = new DataSeries();
                    if (_rs.ChartType.ToLower() == "line")
                    {
                        if (_rs.ChartDimension.ToLower() == "2d")
                            dataSeries2.Definition = new LineSeriesDefinition();
                        else
                            dataSeries2.Definition = new Line3DSeriesDefinition();
                    }
                    else
                    {
                        if (_rs.ChartDimension.ToLower() == "2d")
                            dataSeries2.Definition = new BarSeriesDefinition();
                        else
                            dataSeries2.Definition = new Bar3DSeriesDefinition();
                    }
                    dataSeries2.Definition.AxisName = _rs.ChartSecondaryYAxis;
                    dataSeries2.LegendLabel = _rs.ChartSecondaryYAxis;
                    dataSeries2.Definition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;
                }

                int rowNum = 0;
                foreach (object item in source)
                {
                    if (rowNum == topRows)
                        break;

                    string[] attributes = _rs.ChartXAxis.Split(',');
                    string attributeName = "";
                    foreach (string attribute in attributes)
                    {
                        object name = item.GetType().GetProperty(DynamicDataBuilder.ReplaceProblematicChars(attribute)).GetValue(item, null);
                        if (attributeName.Length > 0)
                            attributeName += " | ";
                        attributeName += Convert.ToString(name);
                    }
                    object value = item.GetType().GetProperty(_rs.ChartPrimaryYAxis).GetValue(item, null);
                    dataSeries1.Add(new DataPoint(attributeName, Convert.ToDouble(value)) { DataItem = item });

                    if (_rs.UseChartSecondaryYAxis)
                    {
                        value = item.GetType().GetProperty(_rs.ChartSecondaryYAxis).GetValue(item, null);
                        dataSeries2.Add(new DataPoint(attributeName, Convert.ToDouble(value)) { DataItem = item });
                    }

                    rowNum++;

                }

                chartReport.DefaultView.ChartArea.DataSeries.Add(dataSeries1);
                if (dataSeries2 != null)
                    chartReport.DefaultView.ChartArea.DataSeries.Add(dataSeries2);
                chartReport.Width = rowNum * 80 + 300;
                chartReport.DefaultView.ChartArea.AxisX.AxisStyles.ItemLabelStyle = LayoutRoot.Resources["AxisXStyleTextBlock"] as Style;



    This works perfectly for 2D, but it looks like I can't simply use the 3D series definition class in place of the regular series definition class.  The example shown here adds the CameraExtension (which I've also coded...getting the same error) but this is the only  major difference I can see (maybe something is being left out here):
    http://demos.telerik.com/silverlight/#Chart/Gallery3D/Line

    Is there a better (working) example that I can use that implements either the Line3DSeriesDefinition or the Bar3DSeriesDefinition classes with the DataSeries?
  2. Nikolay
    Admin
    Nikolay avatar
    397 posts

    Posted 08 Jul 2010 Link to this post

    Hello Brian Graves,

    Please, find attached a sample application, which utilizes Line3DSeriesDefinition and works as expected on our side. Let me note that ZoomScrollSettings and RadChart1ChartItemClicked event would not work with 3D series, however, neither of them should be causing the error you've encountered.

    Please, have a look at the application and if you continue experiencing the same problem, we'd kindly ask you to modify it, so that the issue is reproducible for our developers to look into and provide timely resolution.

    Kind regards,
    Nikolay
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top