SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

0
0

Hi,

I created a chart legend based on the online example. I have three data series: an XyScatterRenderableSeries, a FastColumnRenderableSeries, and a FastLineRenderableSeries. The plot itself is fine. But the legend isn’t. In addition to the checkboxes bug (I don’t need these and so have set ShowVisibilityCheckboxes=False, to no effect), I’m seeing color samples for the scatter and column data, but nothing for the line. All three series names appear as expected, but I’m missing the color sample for the line plot. What’s up?

Thanks,
–George

  • You must to post comments
0
0

Hi George,

I’m guessing if you set a SeriesColor on the ScatterSeries it will be picked up by the legend and display a small dot for that series. Can you try this?

Some tips for you – the LegendControl is just an ItemsControl which binds to the LegendModifier.LegendData.SeriesInfo collection (again an ObservableCollection<SeriesInfo>). So theoretically you can create anything you want by creating your own ItemsControl.

Here – this is the ControlTemplate for the LegendControl. Note there are some bindings to brushes here, you can substitute any colour or brush:

<!-- SciChart 1.5.x SciChartLegend ControlTemplate. Using this you can create your own custom -->
<!-- templates, or you can see how to create some UI from an ItemsControl which mimics -->
<!-- the Legend behaviour --> 
<!--                                   -->
<!-- It simply binds to LegendControl.LegendData.SeriesInfo and uses --> 
<!-- an ItemsControl just like the RolloverModifier to present data -->
<ControlTemplate TargetType="SciChart:SciChartLegend">
                    <Border x:Name="PART_Border"
                            HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalAlignment}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding="{TemplateBinding Padding}">
                        <ItemsControl x:Name="PART_LegendItems"
                                      BorderThickness="0"
                                      DataContext="{TemplateBinding LegendData}"
                                      ItemsSource="{Binding SeriesInfo}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>

                                        <CheckBox Grid.Column="0"
                                                  Width="16"
                                                  HorizontalAlignment="Left"
                                                  VerticalAlignment="Center"
                                                  IsChecked="{Binding IsVisible,
                                                                      Mode=TwoWay}"
                                                  Visibility="{Binding DataContext.ShowVisibilityCheckboxes,
                                                                       ElementName=PART_LegendItems,
                                                                       Converter={StaticResource BooleanToVisibilityConverter}}" />

                                        <Rectangle Grid.Column="1"
                                                   Width="10"
                                                   Height="10"
                                                   Margin="5,0,20,0"
                                                   HorizontalAlignment="Left"
                                                   VerticalAlignment="Center"
                                                   Fill="{Binding SeriesColor,
                                                                  Converter={StaticResource ColorToBrushConverter}}" />
                                        <TextBlock Grid.Column="2"
                                                   HorizontalAlignment="Center"
                                                   Text="{Binding SeriesName}" />

                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>

                        </ItemsControl>
                    </Border>
                </ControlTemplate>

I hope this helps!

Andrew

  • You must to post comments
0
0

PS:

If you want to hide Visibility Checkboxes then you might be able to do this:

<Grid>
  <Grid.Resources>
      <Style TargetType="CheckBox">
           <Setter Property="Visibility" Value="Collapsed"/>
      </Style>
  </Grid.Resources>

   <!-- Your scichart code here , inc. Legend --> 
</Grid>

This should hide all checkboxes in the scope of Grid. If not – re-templating, or creating a custom ItemsControl to bind to SeriesInfo collection is also an option.

Best regards,
Andrew

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.