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

Bind items from a gridview after a transformation

1 Answer 57 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Romain
Top achievements
Rank 1
Romain asked on 20 Jul 2010, 03:57 PM
Hi,

On a page, I have a gridview which shows data which come from a binding to a collection of a class A.

What I want to do is to get the currently showed items on the grid view, transform the items into new items of a class B and bind the new item collection of the class B to a pie chart.

To do that, the only solution I could see was to use a converter.
What I've done compile fine, but when I run the application, the pie chart is empty whereas the grid view contains elements.

Here is the XAML code with the mapping on ItemsSource :

<telerikGrid:RadGridView x:Name="GridView"></telerikGrid:RadGridView>
<telerikChart:RadChart ItemsSource="{Binding ElementName=GridView,Path=Items,Converter={StaticResource Converter}}">
<telerikChart:RadChart.SeriesMappings>
    <telerikCharting:SeriesMapping>
        <telerikCharting:SeriesMapping.SeriesDefinition>
            <telerikCharting:Pie3DSeriesDefinition/>
        </telerikCharting:SeriesMapping.SeriesDefinition>
        <telerikCharting:SeriesMapping.ItemMappings>
            <telerikCharting:ItemMapping DataPointMember="LegendLabel" FieldName="Key" />
            <telerikCharting:ItemMapping DataPointMember="YValue" FieldName="Value" />
        </telerikCharting:SeriesMapping.ItemMappings>
    </telerikCharting:SeriesMapping>
</telerikChart:RadChart.SeriesMappings>
<telerikChart:RadChart.DefaultView>
    <telerikCharting:ChartDefaultView>
        <telerikCharting:ChartDefaultView.ChartArea>
            <telerikCharting:ChartArea LegendName="chartLegend">
            </telerikCharting:ChartArea>
        </telerikCharting:ChartDefaultView.ChartArea>
        <telerikCharting:ChartDefaultView.ChartLegend>
            <telerikCharting:ChartLegend x:Name="chartLegend" UseAutoGeneratedItems="True" />
        </telerikCharting:ChartDefaultView.ChartLegend>
    </telerikCharting:ChartDefaultView>
</telerikChart:RadChart.DefaultView>
</telerikChart:RadChart>

And here is the converter code :

[ValueConversion(typeof(DataItemCollection), typeof(ObservableCollection<KeyValuePair<string, int>>))]
public class Converter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        ObservableCollection<KeyValuePair<string, int>> convertedItems = new ObservableCollection<KeyValuePair<string, int>>();
 
        DataItemCollection dataItemCollection = (DataItemCollection)value;
        if (dataItemCollection.ItemCount > 0)
        {
            // I put here transformed elements in the collection convertedItems.
        }
             
        return convertedItems;
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

In debug mode, when I look at dataItemCollection, it's empty !
So, converter can be use is that case ?
If not, how can I do it ?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Romain
Top achievements
Rank 1
answered on 22 Jul 2010, 01:16 PM
Tags
Chart
Asked by
Romain
Top achievements
Rank 1
Answers by
Romain
Top achievements
Rank 1
Share this question
or