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

0
0

Hi,

How can I change the fontsize of a LegendModifier programmatically? By trying the code below changes the backgound color but not the font size:

var style = new Style(typeof(LegendModifier));
style.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.DarkSlateGray));
style.Setters.Add(new Setter(Control.FontSizeProperty, 34d));
MainChart = new SciChartSurface
{
    HorizontalAlignment = HorizontalAlignment.Stretch,
    VerticalAlignment = VerticalAlignment.Stretch,
    Padding = new Thickness(30,20,16,0),
    Background = new SolidColorBrush(Color.FromRgb(32,32,33)),
    YAxis = new NumericAxis(),
    ChartModifier = new ModifierGroup
    {
        ChildModifiers = new ObservableCollection<IChartModifier>
        {
            new LegendModifier
            {
                Margin = new Thickness(10),
                VerticalAlignment = VerticalAlignment.Top,
                GetLegendDataFor = SourceMode.AllSeries,
                LegendPlacement = LegendPlacement.Inside,
                ShowLegend = true,
                ShowVisibilityCheckboxes = true,
                Style = style,
            }
        }
    }
};
Version
4
  • You must to post comments
0
0

Hi Daniel,

Thanks for your question. To change FontSize for a Legend, you need to set a property on a legend control itself, not on a LegendModifier. LegendModifier creates a SciChartLegend control internally and provides an API to access and change properties on it to some degree. Here is a relevant documentation article, where you can find more info about how it works.

So to have an impact on a legend control itself, you can add an implicit style for SciChartLegend. The value then will be propagated down the VisualTree to legend items:

    <Style TargetType="s:SciChartLegend">
        <Setter Property="FontSize" Value="5" />
    </Style>

Hope this helps!

Best regards,
Yuriy

  • You must to post comments
0
0

Thanks Yuriy,

That works great as a global override, but how would I do it programmatically?

I need to change (temporarily) the fontsize of the Legends of my graph before saving a snapshot of it depending on the output size of the graph. (The bigger the graph, the bigger the text in the legends). Ideally I’d need to:

  1. Let the user pick the output size of the graph.
  2. Change the fontsize of the legent accordingly.
  3. Save the snapshot.
  4. Reset the fontsize to the original one.

Thanks,
Daniel

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.