This is a migrated thread and some comments may be shown as answers.

[Solved] How do I use the CategoricalSeriesDescriptor?

3 Answers 711 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Per
Top achievements
Rank 1
Per asked on 06 Feb 2013, 11:09 PM
Hi!
I'm using the series provider to bind dynamic series to my chart. Everything is working fine but now I want to use a property to select the type of serie I want to include in the graph.

I have found that I should be able to set the TypePath property to the property in my object but can't get it to work :(
1) Where should my property be located? At the same level as ValuePath and CategoryPath or higher up in the hirarchy?
2) What values are valid? "Line", "LineSerie", "LineSeries" ?

Regards
Per

This is my code so far:
<telerik:RadCartesianChart.SeriesProvider >
     <telerik:ChartSeriesProvider Source="{Binding SeriesData}" x:Name="provider" >
            <telerik:ChartSeriesProvider.SeriesDescriptors>
                  <telerik:CategoricalSeriesDescriptor ValuePath="Value" CategoryPath="Category" TypePath="?" >
                  </telerik:CategoricalSeriesDescriptor>
            </telerik:ChartSeriesProvider.SeriesDescriptors>
      </telerik:ChartSeriesProvider>
</telerik:RadCartesianChart.SeriesProvider>

3 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 08 Feb 2013, 09:53 AM
Hello Per,

CategoricalSeriesDescriptor.TypePath property should be located higher up the hierarchy -- it should be defined on the enumerable source level for each series. Also the property type should be System.Type and its actual value should be chart series type like typeof(LineSeries), typeof(AreaSeries), etc:
<telerik:RadCartesianChart Width="250" Height="250" PaletteName="DefaultDark">
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis></telerik:CategoricalAxis>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis></telerik:LinearAxis>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.SeriesProvider >
        <telerik:ChartSeriesProvider Source="{Binding}" x:Name="provider" >
            <telerik:ChartSeriesProvider.SeriesDescriptors>
                <telerik:CategoricalSeriesDescriptor ValuePath="Value" CategoryPath="Category" TypePath="SeriesType" />
            </telerik:ChartSeriesProvider.SeriesDescriptors>
        </telerik:ChartSeriesProvider>
    </telerik:RadCartesianChart.SeriesProvider>
</telerik:RadCartesianChart>

public sealed partial class MainPage2 : Page
{
    public MainPage2()
    {
        this.InitializeComponent();
 
        List<CategoricalDataItemCollection> collection = new List<CategoricalDataItemCollection>();
        Random r = new Random();
 
        for (int i = 0; i < 5; i++)
        {
            CategoricalDataItemCollection data = new CategoricalDataItemCollection();
            data.Add(new CategoricalDataItem { Category = "Apple", Value = r.Next(1, 20) });
            data.Add(new CategoricalDataItem { Category = "Orange", Value = r.Next(1, 20) });
            data.Add(new CategoricalDataItem { Category = "Lemon", Value = r.Next(1, 20) });
 
            if (i < 3)
            {
                data.SeriesType = typeof(BarSeries);
            }
            else
            {
                data.SeriesType = typeof(LineSeries);
            }
 
            collection.Add(data);
        }
 
        provider.Source = collection;
    }
 
    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }
}
 
public class CategoricalDataItemCollection : ObservableCollection<CategoricalDataItem>
{
    public Type SeriesType
    {
        get;
        set;
    }
}
 
public class CategoricalDataItem
{
    public double Value
    {
        get;
        set;
    }
 
    public string Category
    {
        get;
        set;
    }
}


Alternatively, if no CategoricalSeriesDescriptor.TypePath is specified, the series type for the dynamic series will be retrieved from the CategoricalSeriesDescriptor.Style property (if it exists):
<telerik:RadCartesianChart Width="250" Height="250" PaletteName="DefaultDark">
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis></telerik:CategoricalAxis>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis></telerik:LinearAxis>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.SeriesProvider >
        <telerik:ChartSeriesProvider Source="{Binding}" x:Name="provider" >
            <telerik:ChartSeriesProvider.SeriesDescriptors>
                <telerik:CategoricalSeriesDescriptor ValuePath="Value" CategoryPath="Category">
                    <telerik:CategoricalSeriesDescriptor.Style>
                        <Style TargetType="telerik:LineSeries">
                            <!-- the series type will be retrieved from the Style.TargetType if CategoricalSeriesDescriptor.TypePath is not set -->
                            <Setter Property="StrokeThickness" Value="3" />
                        </Style>
                    </telerik:CategoricalSeriesDescriptor.Style>
                </telerik:CategoricalSeriesDescriptor>
            </telerik:ChartSeriesProvider.SeriesDescriptors>
        </telerik:ChartSeriesProvider>
    </telerik:RadCartesianChart.SeriesProvider>
</telerik:RadCartesianChart>

If neither CategoricalSeriesDescriptor.TypePath, nor CategoricalSeriesDescriptor.Style properties are defined, the default BarSeries will be created.

Hope this helps.


Greetings,
Giuseppe
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Per
Top achievements
Rank 1
answered on 08 Feb 2013, 07:48 PM
Hi and thanks for your reply.
The only differens I see in your code compared to mine is that I bind my items to series this way:
<telerik:RadCartesianChart.SeriesProvider >
    <telerik:ChartSeriesProvider Source="{Binding collection}" x:Name="provider">
         <telerik:ChartSeriesProvider.SeriesDescriptors>
             <telerik:CategoricalSeriesDescriptor ValuePath="Value" CategoryPath="Category" TypePath="SeriesType"/>
          </telerik:ChartSeriesProvider.SeriesDescriptors>
    </telerik:ChartSeriesProvider>
</telerik:RadCartesianChart.SeriesProvider>

(my chart is also in a DataTemplate)

If I remove TypePath="SeriesType" everything works.

If I add it, I receive this error:

System.ArgumentException
   at System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName)
   at Telerik.Core.BindingExpressionHelper.CreateGetValueFunc(Type itemType, String propertyPath)
   at Telerik.Core.DynamicHelper.CreatePropertyValueGetter(Type type, String propertyName)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDescriptor.ResolveType(Object context)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDescriptor.CreateDefaultInstance(Object context)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDescriptor.CreateInstanceCore(Object context)
   at Telerik.UI.Xaml.Controls.Chart.CategoricalSeriesDescriptor.CreateInstanceCore(Object context)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesDescriptor.CreateInstance(Object context)
   at Telerik.UI.Xaml.Controls.Chart.ChartSeriesProvider.<CreateSeries>d__0.MoveNext()
   at Telerik.UI.Xaml.Controls.Chart.RadChartBase.UpdateDynamicSeries()
   at Telerik.UI.Xaml.Controls.Chart.RadChartBase.OnTemplateApplied()
   at Telerik.UI.Xaml.Controls.RadControl.OnApplyTemplate()

Regards
Per
0
Giuseppe
Telerik team
answered on 11 Feb 2013, 09:23 AM
Hello Per,

We are still unable to reproduce the problematic behavior in our local tests. Please review the attached runnable sample application that references the latest official SDK of our controls and behaves as expected inside a DataTemplate and let us know if we are missing something out.


Kind regards,
Giuseppe
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
Chart for XAML
Asked by
Per
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Per
Top achievements
Rank 1
Share this question
or