SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
I am trying to create a custom CursorModifier Tooltip. It works in that it shows both of my lines on the screen and all the data associated with the lines. But what I would like to do is only report information about the first line, as the second line is only there for visual purposes as default. Here is a sample of my code.
<ItemsControl Margin="6" ItemsSource="{Binding SeriesData.SeriesInfo}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical"> <StackPanel Orientation ="Horizontal"> <TextBlock Style="{StaticResource HintDataItemsStyle}" Text="Available Imports:"></TextBlock> <TextBlock Style="{StaticResource HintDataItemsStyle}" Text="{Binding Value, StringFormat=\{0:###\,##0\}}" /> </StackPanel> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>
What I’ve tried to do is change the ItemsSource to SeriesData.SeriesInfo[0] which seems to get only the line I want, but then the Value bindings below no longer work.
Hmmm, ok so if you have a collection of SeriesInfo as a binding source (and the above works), you can always use indexing in the XAML to bind to the first element in the collection, e.g. your template for the Cursor will look like this
<StackPanel Orientation ="Horizontal" DataContext="{Binding SeriesData.SeriesInfo[0]}"> <TextBlock Style="{StaticResource HintDataItemsStyle}" Text="Available Imports:"></TextBlock> <TextBlock Style="{StaticResource HintDataItemsStyle}" Text="{Binding Value, StringFormat={0:###,##0}}" /> </StackPanel>
or … if that doesn’t work, this should
<StackPanel Orientation ="Horizontal"> <TextBlock Style="{StaticResource HintDataItemsStyle}" Text="Available Imports:"></TextBlock> <TextBlock Style="{StaticResource HintDataItemsStyle}" Text="{Binding SeriesData.SeriesInfo[0].Value, StringFormat={0:###,##0}}" /> </StackPanel>
Does this solve the problem?
Best regards,
Andrew
<Window.Resources> <!-- Define a control template for the first series rollover marker --> <!-- Interally, this will be used to template a blank control which will be overlaid on --> <!-- the ChartModifierSurface (canvas) which exists over the SciChartSurface --> <ControlTemplate x:Key="FirstSeriesRolloverTemplate"> <Ellipse Fill="Black" Stroke="Green" Width="11" Height="11" StrokeThickness="2"/> </ControlTemplate> <!-- Define a control template for the second series rollover marker --> <ControlTemplate x:Key="SecondSeriesRolloverTemplate"> <Ellipse Fill="Black" Stroke="Yellow" Width="11" Height="11" StrokeThickness="2"/> </ControlTemplate> <ControlTemplate x:Key="ThirdSeriesRolloverTemplate"> <Ellipse Fill="Black" Stroke="Cyan" Width="11" Height="11" StrokeThickness="2"/> </ControlTemplate> </Window.Resources> <Grid> <SciChart:SciChartSurface x:Name="MainChart" Margin="0,0,0,38" > <SciChart:SciChartSurface.RenderableSeries> <SciChart:FastLineRenderableSeries SeriesColor="Red" RolloverMarkerTemplate="{StaticResource FirstSeriesRolloverTemplate}"/> <SciChart:FastLineRenderableSeries SeriesColor="Blue" RolloverMarkerTemplate="{StaticResource SecondSeriesRolloverTemplate}"/> <SciChart:FastLineRenderableSeries SeriesColor="Purple" RolloverMarkerTemplate="{StaticResource ThirdSeriesRolloverTemplate}"/> </SciChart:SciChartSurface.RenderableSeries> <SciChart:SciChartSurface.ChartModifier> <SciChart:RolloverModifier/> </SciChart:SciChartSurface.ChartModifier> <SciChart:SciChartSurface.XAxis> <SciChart:NumericAxis> <!--<SciChart:NumericAxis.VisibleRange> <SciChart:DoubleRange Min="0" Max="1200"/> </SciChart:NumericAxis.VisibleRange> --> </SciChart:NumericAxis> </SciChart:SciChartSurface.XAxis> <SciChart:SciChartSurface.YAxis> <SciChart:NumericAxis> <!--<SciChart:NumericAxis.GrowBy> <SciChart:DoubleRange Min="0.1" Max="0.5"/> </SciChart:NumericAxis.GrowBy> --> </SciChart:NumericAxis> </SciChart:SciChartSurface.YAxis> </SciChart:SciChartSurface> <ItemsControl Grid.IsSharedSizeScope="True" Margin="23,23,0,0" Padding="5" BorderBrush="#55000000" BorderThickness="2" VerticalAlignment="Top" HorizontalAlignment="Left" Background="#77978989" DataContext="{Binding ElementName=MainChart, Path=ChartModifier}" ItemsSource="{Binding RolloverData.SeriesInfo}" Height="92" Width="236"> <ItemsControl.ItemTemplate> <DataTemplate DataType="SciChart:SeriesInfo"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="ColumnA"/> <ColumnDefinition SharedSizeGroup="ColumnB"/> </Grid.ColumnDefinitions> <!-- Bind to the SeriesName using the SeriesColor as text foreground --> <TextBlock Grid.Column="0" Text="{Binding SeriesName}" Margin="3,3,20,3" FontSize="13" FontWeight="Bold" Foreground="Black" /> <!-- Bind to the Series Value, using the SeriesColor as text foreground --> <TextBlock Grid.Column="1" Text="{Binding Value, StringFormat={}{0:0.000}}" Margin="3,3,3,3" FontSize="13" FontWeight="Bold" Foreground="Black" /> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid>
Ok – its purely a binding / XAML issue, you just need to point to the first item in the SeriesInfo collection
I’ve taken the code in the RolloverFeedback demo (shipped with the trial) and modified it as follows. just use a Grid and bind directly to SeriesInfo[0] as datacontext. It works on my side:
<Border Grid.Row="1" Margin="23,23" HorizontalAlignment="Left" VerticalAlignment="Top" Background="#77FFFFFF" BorderBrush="#55000000" BorderThickness="2" Padding="5"> <!-- This new block binds to a specific SeriesInfo instance --> <Grid DataContext="{Binding ElementName=rolloverModifier, Path=RolloverData.SeriesInfo[0]}"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Margin="3,3,20,3" FontSize="13" FontWeight="Bold" Foreground="{Binding SeriesColor, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding SeriesName}" /> <TextBlock Grid.Column="1" Margin="3,3,3,3" FontSize="13" FontWeight="Bold" Foreground="{Binding SeriesColor, Converter={StaticResource ColorToBrushConverter}}" Text="{Binding Value}" /> </Grid> <!-- This is the ItemsControl in the Rollover Feedback demo which I have commented out --> <!-- <ItemsControl DataContext="{Binding ElementName=rolloverModifier}" ItemsSource="{Binding RolloverData.SeriesInfo}">--> <!-- <ItemsControl.ItemTemplate>--> <!-- <DataTemplate>--> <!-- <Grid>--> <!-- <Grid.ColumnDefinitions>--> <!-- <ColumnDefinition />--> <!-- <ColumnDefinition />--> <!-- </Grid.ColumnDefinitions>--> <!----> <!-- <TextBlock Grid.Column="0"--> <!-- Margin="3,3,20,3"--> <!-- FontSize="13"--> <!-- FontWeight="Bold"--> <!-- Foreground="{Binding SeriesColor,--> <!-- Converter={StaticResource ColorToBrushConverter}}"--> <!-- Text="{Binding SeriesName}" />--> <!-- <TextBlock Grid.Column="1"--> <!-- Margin="3,3,3,3"--> <!-- FontSize="13"--> <!-- FontWeight="Bold"--> <!-- Foreground="{Binding SeriesColor,--> <!-- Converter={StaticResource ColorToBrushConverter}}"--> <!-- Text="{Binding Value}" />--> <!-- </Grid>--> <!-- </DataTemplate>--> <!-- </ItemsControl.ItemTemplate>--> <!-- </ItemsControl>--> </Border>
Please login first to submit.