No Data Series

2 posts, 0 answers
  1. Mark
    Mark avatar
    13 posts
    Member since:
    Aug 2012

    Posted 01 Aug 2012 Link to this post

    Graph shows No Data Series:

                            <telerik:RadChart x:Name="radOASHistory" Grid.Row="1" Margin="0,0,0,0" UseLayoutRounding="True" BorderThickness="0"
                                                   VerticalAlignment="Top" VerticalContentAlignment="Stretch" HorizontalAlignment="Left" HorizontalContentAlignment="Stretch"
                                                   Height="500" Width="1300" MinHeight="300" MinWidth="700" MaxHeight="700" MaxWidth="1300"
                                           >
                                <telerik:RadChart.DefaultView>
                                    <telerik:ChartDefaultView>
                                        <telerik:ChartDefaultView.ChartArea>
                                            
                                            <telerik:ChartArea>

                                                <telerik:ChartArea.AxisX>
                                                    <telerik:AxisX AutoRange="True" />
                                                </telerik:ChartArea.AxisX>
                                                
                                                <telerik:ChartArea.AxisY>
                                                    <telerik:AxisY Title="OAS [bp/yr]" AxisLabelsVisibility="Collapsed" />
                                                </telerik:ChartArea.AxisY>

                                                <telerik:ChartArea.AdditionalYAxes>
                                                    <telerik:AxisY AutoRange="True"/>
                                                </telerik:ChartArea.AdditionalYAxes>

                                            </telerik:ChartArea>
                                        </telerik:ChartDefaultView.ChartArea>
                                    </telerik:ChartDefaultView>
                                </telerik:RadChart.DefaultView>

                                <telerik:RadChart.SeriesMappings>
                                    <telerik:SeriesMapping>
                                        <telerik:SeriesMapping.SeriesDefinition>
                                            <telerik:LineSeriesDefinition ShowItemLabels="False" ShowPointMarks="False" />
                                        </telerik:SeriesMapping.SeriesDefinition>
                                        <telerik:SeriesMapping.ItemMappings>
                                            <telerik:ItemMapping DataPointMember="YValue" />
                                        </telerik:SeriesMapping.ItemMappings>
                                    </telerik:SeriesMapping>
                                </telerik:RadChart.SeriesMappings>

                            </telerik:RadChart>

            public void ProcessChart(ObservableCollection<PcyaSimServiceReference.PCYAsimServiceHistoryItem> results)
            {
                if (results                                                     == null)
                    return;

                _data                                                            = results;

                radOASHistory.SeriesMappings.Clear();
                radOASHistory.DefaultView.ChartArea.DataSeries.Clear();

                foreach (PcyaSimServiceReference.PCYAsimServiceHistoryItem hi in results)
                {
                    DataSeries lineSeries                                        = new DataSeries();
                    lineSeries.Definition                                        = new LineSeriesDefinition { ShowItemLabels = false, ShowPointMarks = false };

                    foreach (CorporateBondCalculator.PcyaSimServiceReference.PCYAsimServiceHistoryRung item in hi.OAS)
                    {
                        lineSeries.Add(new Telerik.Windows.Controls.Charting.DataPoint() { YValue = item.Value, XValue = item.PriceDate.ToOADate() });
                    }

                    SeriesMapping seriesMapping                                  = new SeriesMapping();
                    seriesMapping.LegendLabel                                    = hi.Description;
                    seriesMapping.SeriesDefinition                               = lineSeries.Definition;

                    seriesMapping.ItemMappings.Add(new ItemMapping("PriceDate", DataPointMember.XValue));
                    seriesMapping.ItemMappings.Add(new ItemMapping("Value", DataPointMember.YValue));
                    seriesMapping.ItemMappings.Add(new ItemMapping("Label", DataPointMember.Label));

                    radOASHistory.SeriesMappings.Add(seriesMapping);

                    radOASHistory.DefaultView.ChartArea.AxisX.IsDateTime         = true;
                    radOASHistory.DefaultView.ChartArea.AxisX.LayoutMode         = AxisLayoutMode.Inside;
                    radOASHistory.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "MM/dd/yyyy";
                    radOASHistory.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;

                    radOASHistory.DefaultView.ChartArea.DataSeries.Add(lineSeries);
                }
  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 06 Aug 2012 Link to this post

    Hello Mark,

    I examined your code and here are my suggestions:
    • You don't need to manually add all of the DataPoints to each of the series. Just set each SeriesMapping an ItemSource and the RadChart will handle the rest: 
      foreach (var hi in results) 
      //var is PcyaSimServiceReference.PCYAsimServiceHistoryItem
      {
          SeriesMapping seriesMapping = new SeriesMapping();
          seriesMapping.SeriesDefinition = new LineSeriesDefinition();
          //adding ItemMapping-s to current SeriesMapping:
          //seriesMapping.ItemMappings.Add(...)
       
          /*NEW*/ seriesMapping.ItemsSource = hi.OAS;
       
          radOASHistory.SeriesMappings.Add(seriesMapping);
      } 
    • That said you also don't need to manually add DataSeries to the RadChart, because when a SeriesMapping has an ItemSource it handles that for you. Either use the approach with SeriesMapping(s) (easier) or use the DataSeries, because they can't work at same time.
    • When specifying a seriesMapping.SeriesDefinition you can just set it to a new SeriesDefinition as shown in the above code snippet.
    • You can delete the SeriesMapping(s) from the XAML, because they are redundant when you are actually adding them in code behind.
    Here is a modified version of your ProcessChart method:
    public void ProcessChart(
        ObservableCollection<PcyaSimServiceReference.PCYAsimServiceHistoryItem> results)
    {
        if (results == null) return;
        _data = results;
     
        //If your setting the Chart only once these two lines are not needed:
        radOASHistory.SeriesMappings.Clear();
        radOASHistory.DefaultView.ChartArea.DataSeries.Clear();
        //
     
        foreach (var hi in results)
            //var is PcyaSimServiceReference.PCYAsimServiceHistoryItem
        {
            //DataSeries lineSeries                                        = new DataSeries();
            //lineSeries.Definition                                        = new LineSeriesDefinition { ShowItemLabels = false, ShowPointMarks = false };
     
            //foreach (CorporateBondCalculator.PcyaSimServiceReference.PCYAsimServiceHistoryRung item in hi.OAS)
            //{
            //    lineSeries.Add(new Telerik.Windows.Controls.Charting.DataPoint() { YValue = item.Value, XValue = item.PriceDate.ToOADate() });
            //}
     
            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.LegendLabel   = hi.Description;
            seriesMapping.SeriesDefinition = /*lineSeries.Definition*/
        new LineSeriesDefinition { ShowItemLabels = false, ShowPointMarks = false };
     
            seriesMapping.ItemMappings.Add(
            new ItemMapping("PriceDate", DataPointMember.XValue));
            seriesMapping.ItemMappings.Add(
            new ItemMapping("Value", DataPointMember.YValue));
            seriesMapping.ItemMappings.Add(
            new ItemMapping("Label", DataPointMember.Label));
     
            /*NEW*/
            seriesMapping.ItemsSource = hi.OAS;
     
            radOASHistory.SeriesMappings.Add(seriesMapping);
     
            radOASHistory.DefaultView.ChartArea.AxisX.IsDateTime = true;
            radOASHistory.DefaultView.ChartArea.AxisX.LayoutMode =
                AxisLayoutMode.Inside;
            radOASHistory.DefaultView.ChartArea.AxisX.DefaultLabelFormat =
                "MM/dd/yyyy";
            radOASHistory.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
     
            //radOASHistory.DefaultView.ChartArea.DataSeries.Add(lineSeries);
        }
    }

    All the best,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top