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

ChartSeriesDescriptor.CollectionIndex Property

1 Answer 121 Views
Chart
This is a migrated thread and some comments may be shown as answers.
ABI
Top achievements
Rank 1
ABI asked on 06 Jul 2016, 02:38 PM

Hello,

Is this property Bindable? I have a Barseries and a Lineseries, the LineSeries should only apply to the last data series, if i put in the right index it works, but with binding no getter gets called.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 08 Jul 2016, 09:52 AM
Hi Laurentius,

The chart series descriptor doesn't have a data context and its properties cannot be bind. Or at least they won't know from where to get their bound properties. In short, no, the CollectionIndex property won't work with binding because it doesn't have a binding source.

In order to achieve your requirement you can use the SeriesProvider SeriesDescriptorSelector and apply the proper descriptors to the series. Another approach could be to add a single abstract ChartSeriesDescriptor and subscribe for the SeriesProvider's SeriesCreated event, where you can get the CollectionIndex property from the view model and based on it, manually create the corresponding series.
<telerik:RadCartesianChart.SeriesProvider>
    <telerik:ChartSeriesProvider Source="{Binding Data}"
                                 SeriesCreated="ChartSeriesProvider_SeriesCreated">
        <telerik:ChartSeriesProvider.SeriesDescriptors>
            <telerik:ChartSeriesDescriptor ItemsSourcePath="MyDataPointsCollection" />                
        </telerik:ChartSeriesProvider.SeriesDescriptors>
    </telerik:ChartSeriesProvider>
</telerik:RadCartesianChart.SeriesProvider>

private void ChartSeriesProvider_SeriesCreated(object sender, ChartSeriesCreatedEventArgs e)
{
    var mySeriesModel = (MySeriesViewModel)e.Context;
    var index = mySeriesModel.CollectionIndex;
    CategoricalSeries series = null;
    if (index is the corresponding index of the line series)
    {
        series = new LineSeries();
         
    }
    else
    {
        series = new BarSeries();               
    }
 
    series.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "MyCategory" };
    series.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "MyValue" };
    e.Series = series;
}

I hope those approaches are suitable for your scenario.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Chart
Asked by
ABI
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or