Pre loader

RolloverModifier

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

I have a RolloverModifier based primarily on the example:

    <Border 
        Grid.Row="0" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Top" 
        BorderBrush="#55000000" 
        BorderThickness="1" 
        Margin="70,0,15,0"
        Padding="5"
        CornerRadius="5"
        MinWidth="850" >

        <ItemsControl DataContext="{Binding ElementName=rolloverModifier}" ItemsSource="{Binding Path=RolloverData.SeriesInfo}" HorizontalAlignment="Left">
            <ItemsControl.Style>
                <Style TargetType="{x:Type ItemsControl}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=RolloverData.SeriesInfo,Converter={StaticResource EmptyCollectionConverter}}" Value="True">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ItemsControl}">
                                        <TextBlock Text="No data selected" Margin="5,0" HorizontalAlignment="Center" />
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ItemsControl.Style>

            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding XValue,Converter={StaticResource StringFormatConverter},ConverterParameter={}{0:dd MMM yyyy HH:mm:ss}}"
                                   Margin="5,0">
                            <TextBlock.Style>
                                <Style TargetType="{x:Type TextBlock}">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding SeriesName}" Value="Load">
                                            <Setter Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>

                        <Polygon 
                            Points="0 0.5 0.5 1 1 0.5 0.5 0" 
                            Stretch="Fill" 
                            HorizontalAlignment="Stretch" 
                            VerticalAlignment="Stretch" 
                            Fill="{Binding SeriesColor,Converter={StaticResource ColourToBrushConverter}}" 
                            StrokeThickness="0" 
                            Width="7" Height="7"
                            Margin="10,0,5,0" />

                        <TextBlock Text="{Binding .,Converter={StaticResource SeriesValueConverter}}" Margin="5,0" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" IsItemsHost="True" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </Border>

The FastLineRenderableSeries is displayed depending on a databound BaseRenderableSeries.IsVisible.

The serieses always have identical x values. I’ve taken advantage of this to display the x value in the rollover border by using the XValue textblock with a trigger bound to the name of the series, if it’s the first then it displays its x value.

If a series is not visible, there is no Item and therefore the DataTemplate isn’t used. If the first series is hidden, I don’t get an x value in my rollover modifier.

Can you see a way of displaying the x value reliably?

Thanks for your time,
Andy C

  • You must to post comments
0
0

As is so often the case, walked away for the weekend and came up with using an IValueConverter, passing it the entire SeriesInfo collection and extracting the date of the first item in the collection:

    <Border 
        Grid.Row="0" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Top" 
        BorderBrush="#55000000" 
        BorderThickness="1" 
        Margin="70,0,15,0"
        Padding="5"
        CornerRadius="5"
        MinWidth="850" >

        <StackPanel Orientation="Horizontal">
            <TextBlock DataContext="{Binding ElementName=rolloverModifier,Path=RolloverData.SeriesInfo,Converter={StaticResource TimestampConverter},ConverterParameter={}{0:dd MMM yyyy HH:mm:ss}}" Text="{Binding}" />

            <ItemsControl DataContext="{Binding ElementName=rolloverModifier}" ItemsSource="{Binding Path=RolloverData.SeriesInfo}" HorizontalAlignment="Left">
                <ItemsControl.Style>
                    <Style TargetType="{x:Type ItemsControl}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=RolloverData.SeriesInfo,Converter={StaticResource EmptyCollectionConverter}}" Value="True">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ItemsControl}">
                                            <TextBlock Text="No data selected" Margin="5,0" HorizontalAlignment="Center" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ItemsControl.Style>

                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Polygon 
                                Points="0 0.5 0.5 1 1 0.5 0.5 0" 
                                Stretch="Fill" 
                                HorizontalAlignment="Stretch" 
                                VerticalAlignment="Stretch" 
                                Fill="{Binding SeriesColor,Converter={StaticResource ColourToBrushConverter}}" 
                                StrokeThickness="0" 
                                Width="7" Height="7"
                                Margin="10,0,5,0" />

                            <TextBlock Text="{Binding .,Converter={StaticResource SeriesValueConverter}}" Margin="5,0" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>

                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" IsItemsHost="True" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

        </StackPanel>

    </Border>


public class TrendSeriesTimestampConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var series = value as ICollection<SeriesInfo>;

        if (series == null)
        {
            return null;
        }

        var firstInSeries = series.FirstOrDefault();

        if (firstInSeries == null)
        {
            return null;
        }

        var objectConverter = new IComparableToObjectConverter();
        var timestamp = objectConverter.Convert(firstInSeries.XValue, typeof(DateTime), null, culture);

        if (timestamp is DateTime)
        {
            var format = parameter as string;

            if (string.IsNullOrEmpty(format))
            {
                return timestamp;
            }

            return string.Format(format, timestamp);
        }

        return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Hope it helps someone else!
AC

  • Yuriy Zadereckiy
    Hi Andy, I'm glad you sorted it out and thanks for posting your solution! I think it'll be useful for others, Best regards, Yuriy
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies