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

Using InteractivitySettings with an Aggregate doesn't work correctly

3 Answers 52 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 29 Jul 2011, 11:42 PM
I have the following chart defined below that uses an InteractivitySettings SelectionMode of Single and an ItemMapping with an aggregate function of Sum. Every bar the user clicks on gets selected so the items selected will go past one.

If I remove the aggregate summation then it works fine.
<telerik:RadChart x:Class="Fieldnotebook.Controls.BarChartControl"
    mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"
    ItemsSource="{Binding Path=View}">
 
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping>
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:BarSeriesDefinition>
                    <telerik:BarSeriesDefinition.InteractivitySettings>
                        <telerik:InteractivitySettings  SelectionMode="Single" SelectionScope="Item" />
                    </telerik:BarSeriesDefinition.InteractivitySettings>
                </telerik:BarSeriesDefinition>
            </telerik:SeriesMapping.SeriesDefinition>
            <telerik:SeriesMapping.GroupingSettings>
                <telerik:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                    <telerik:GroupingSettings.GroupDescriptors>
                        <telerik:ChartGroupDescriptor Member="ActivityGroupDescription" />
                    </telerik:GroupingSettings.GroupDescriptors>
                </telerik:GroupingSettings>
            </telerik:SeriesMapping.GroupingSettings>
            <telerik:SeriesMapping.ItemMappings>
                <telerik:ItemMapping FieldName="Rate" DataPointMember="YValue" AggregateFunction="Sum" />
            </telerik:SeriesMapping.ItemMappings>
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
 
    <telerik:RadChart.DefaultView>
        <telerik:ChartDefaultView>
            <telerik:ChartDefaultView.ChartLegend>
                <telerik:ChartLegend x:Name="GroupLegend2"  UseAutoGeneratedItems="True" />
            </telerik:ChartDefaultView.ChartLegend>
 
            <telerik:ChartDefaultView.ChartArea>
                <telerik:ChartArea LegendName="GroupLegend2" SelectionChanged="ChartArea_SelectionChanged">
                    <telerik:ChartArea.AxisX>
                        <telerik:AxisX AutoRange="True" DefaultLabelFormat="0.0" Title="Activity Group" AxisLabelsVisibility="Collapsed" />
                    </telerik:ChartArea.AxisX>
                    <telerik:ChartArea.AxisY>
                        <telerik:AxisY AutoRange="True" DefaultLabelFormat="0" Title="Amount (Sum)"/>
                    </telerik:ChartArea.AxisY>
                </telerik:ChartArea>
            </telerik:ChartDefaultView.ChartArea>
        </telerik:ChartDefaultView>
    </telerik:RadChart.DefaultView>
</telerik:RadChart>





3 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 30 Jul 2011, 12:06 AM
I worked around the problem by doing this:
private void ChartArea_SelectionChanged(object sender, ChartSelectionChangedEventArgs e)
{
    ChartArea chartArea = (ChartArea)sender;
     
    chartArea.SelectionChanged -= ChartArea_SelectionChanged;
    try
    {
        IList<DataPoint> dataPoints = e.AddedItems;
        if (dataPoints.Count == 1)
        {
            DataPoint dataPoint = dataPoints.First();
            chartArea.ClearSelection();
            chartArea.SelectItem(dataPoint);
        }
    }
    finally
    {
        chartArea.SelectionChanged += ChartArea_SelectionChanged;
    }
}

0
Yavor
Telerik team
answered on 03 Aug 2011, 01:15 PM
Hello Scott,

Let me explain first how the selection mode works. When SelectionScope is set to InteractivityScope.Item, when one selects a bar item, only the respective item will be highlighted (i.e. all of the other series as well all of the other bar items within the originating bar series will become temporarily transparent). In your scenario you are grouping your chart and this creates a new data series for each group. Using sum aggregation function you are reducing the number of items in each series to only 1. That's why you can select more than one item.

The solution can be to flatten the result to a single series. This way the selection interactivity will work as expected. Your code can look like this:

<telerik:SeriesMapping.GroupingSettings>
    <telerik:GroupingSettings ShouldCreateSeriesForLastGroup="True" ShouldFlattenSeries="True">
        <telerik:GroupingSettings.GroupDescriptors>
            <telerik:ChartGroupDescriptor Member="ActivityGroupDescription" />
        </telerik:GroupingSettings.GroupDescriptors>
    </telerik:GroupingSettings>
</telerik:SeriesMapping.GroupingSettings>

I have attached a sample application using your code that uses this solution.
Hope this helps!

All the best,
Yavor Ivanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Scott
Top achievements
Rank 1
answered on 03 Aug 2011, 06:07 PM
Thank you very much for the explanation. I'll give it a try.
Tags
Chart
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or