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!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
1
0

Hi,

After I’ve added some TextAnnotations on the graph, I’ve noticed that the TextAnnotations and CustomaAnnotations doesn’t resize with the view. They all stay constant in size. I’ve found a previous question about this in here: https://www.scichart.com/questions/question/text-annotation-size

But I’m not getting the results I hoped for with this. The test is still not resizing with the surface. Since it’s been a while that a question was asked about this, maybe there are new methods to do this in Scichart?

Thanks

  • You must to post comments
Best Answer
1
0

I decided to go with LayoutTransform because creating a controltemplate didn’t work for me for some reason and it put a background on the annotation and I couldn’t find what property was controlling it.

So, I created a Style:

    <Style x:Key="TextAnnotationStyle" TargetType="s:TextAnnotation">
    <Setter Property="LayoutTransform">
        <Setter.Value>
            <ScaleTransform ScaleY="{Binding ScaleX, RelativeSource={RelativeSource Self}}">
                <ScaleTransform.ScaleX>
                    <Binding Path="ActualWidth" Converter="{StaticResource ControlSizeToTextSizeConverter}" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}">
                    </Binding>
                </ScaleTransform.ScaleX>
            </ScaleTransform>
        </Setter.Value>
    </Setter>
</Style>

And made a converter for resizing to the width,

    public class ControlSizeToTextSizeConverter : IValueConverter
{
    static double MaxSizeWidth = 660;

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        double scale = ((double)value / MaxSizeWidth);
        if(scale > 1)
            scale = 1;

        if (scale < 0.45f)
            scale = 0;
        else if (scale < 0.55d)
            scale = 0.55d;

        return scale;
    }

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

you might notice that it “hides” the text when the graph is too small. You also have to give this a “desired size” in pixels where it shouldn’t apply any scale transforms (that’s what scale = 1 does) so it prevents the text to become too big. You might also notice that the sizing is uniform in this case, but if you are ok with a non uniform resizing, just bind ScaleY to the ActualHeight with the converter instead of ScaleX’s value. You also might need to hold the desired size of the height in the converter as well, that’s one of the setbacks of this approach but it’s acceptable in my case.

Thanks

  • You must to post comments
Great Answer
1
0

Hi Kewur,

Thank you for your inquiry. There isn’t any inbuilt way to get font size adjusted now as well, because this has not been often asked for and a workaround exists. Alternatively, you could achieve the same using the BoxAnnotation, which can be anchored by 4 corners and has a simpler template:

    <Style TargetType="a:BoxAnnotation">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="a:BoxAnnotation">
                <Border x:Name="PART_BoxAnnotationRoot"
                        Margin="{TemplateBinding Margin}"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="{TemplateBinding CornerRadius}" >

                    <Viewbox Stretch="Fill">

                        <!-- TextBlock with adjustable font size -->
                        <TextBlock Text="Some Text" />

                    </Viewbox>

                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Also there is a Behavior which does the same at StackOverflow.

So you could extend the BoxAnnotation class and bind the TextBlock within the template from above to some custom property and get the desired behavior.

Hope this helps! Please feel free to comment if you have any questions/remarks,

Best regards,
Yuriy

  • Andrew
    Good idea. Another idea is use TextAnnotation.LayoutTransform with a ScaleTransform. However, this would require knowing a scale factor (difficult to compute for X and Y Axis). There's about 3 ways to achieve this, it's going to require some research you on your part. If you do find a good solution, please post it as answer! This will help our forums stay current! Thanks! Andrew
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.