Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3220
Generic Tooltip template for StackedFragmentSeries created in code behind
posted

Hello,

My StackedColumnSeries is created in code behind, because the number of stacks are dynamically.

To show the value I just need to assign the proper ValueMemberPath:

StackedFragmentSeries serie = new StackedFragmentSeries();
            serie.Title = "Object Count";
            serie.ValueMemberPath = "ObjectCount[1]";
            serie.Brush = brushConverter.ConvertFromString("#FF64C480") as Brush;
            serie.Outline = serie.Brush;
 
            dataChartSeries.Series.Add(serie);

That works fine. But how should the Tooltip DataTemplate look like, in order to show the proper value of the series. Here is my template:

<DataTemplate x:Key="tooltipTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,5,0">
                    <Run Text="{Binding Path=Series.Title}"/><Run Text=":"/>
                </TextBlock>
                <TextBlock Grid.Row="0" Grid.Column="1">
                    <Run Text="{Binding Path=??????????, StringFormat={}{0:0.##}, Mode=OneWay}"/>
                    <Run Text="{Binding Path=Item.Uom}"/>
                </TextBlock>

                <TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,5,0">
                    <Run Text="{x:Static l:lang.ChartStatistic_Label_Timestamp}"/><Run Text=":"/>
                </TextBlock>
                <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Item.Timestamp, StringFormat={}{0:HH:mm:ss}}" />
            </Grid>
        </DataTemplate>

The yellow highlighted line ineeds the proper binding.

  • 34830
    Offline posted

    Hello Bin,

    The best recommendation I have for you to be able to show the value of an item in your stacked series when you don’t really know exactly what the ValueMemberPath is going to be is to use a converter. You will need to bind to the DataContext of the element that you are passing into the converter, like so, where “conv” is the x:Key of your converter:

    <Run Text="{Binding RelativeSource={RelativeSource Self}, Path=DataContext, Converter={StaticResource conv}}" />

    From there, you can use a converter like the following to get the ValueMemberPath off of the fragment that will own the tooltip and use reflection to get the value off of your underlying data item. In this case, "SampleData" is the data item object type:

        public class StackedColumnSeriesValueConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (value != null)
                {
                    Infragistics.Controls.Charts.DataContext context = value as Infragistics.Controls.Charts.DataContext;
                    SampleData sd = context.Item as SampleData;
                    ColumnFragment fragment = context.Series as ColumnFragment;
                    var propInfo = sd.GetType().GetProperty(fragment.ValueMemberPath);
                    return propInfo.GetValue(sd);
                }
    
                return 0;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    Please let me know if you have any other questions or concerns on this matter.