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 SciChart support,

we experience problems with clipping x axis values, depending on x-axis value range.
assume we have xaxis range from 1000000 to 1000001 and a diagram with a margin of lets say 10 pixels to the right of the container control. Depending on the zoom, the label of the mostright xaxis value(e.g. “1000001”) may be clipped just because the string is just too long. Would you recommend to change the margin dynamically to avoid the clipping or is there a way to prevent the chart from putting the rightmost xaxis value label if it exceeds the diagram bounds?

Hope you could help me.

Thanks in advance, Andreas

  • You must to post comments
0
0

Hi Andreas,

Thanks for your inquiry. There are several possible solutions available:

  • you can allow to the labels to overlap neighboring controls setting ClipToBounds to False on the axis.

  • it is possible to expand the surface by setting Padding on it.

  • it is possible to shift the labels so they always appear inside the axis. To achieve this, you need to do some overriding:

    public class NumericAxisEx:NumericAxis
    {
    public static readonly DependencyProperty IsLeftMarginalLabelProperty =
    DependencyProperty.RegisterAttached(“IsLeftMarginalLabel”, typeof(bool), typeof(NumericAxisEx), new PropertyMetadata(false, (d, e) => OnIsMarginalLabelChanged(d, e, HorizontalAnchorPoint.Left)));

    public static bool GetIsLeftMarginalLabel(DependencyObject obj)
    {
    return (bool)obj.GetValue(IsLeftMarginalLabelProperty);
    }

    public static void SetIsLeftMarginalLabel(DependencyObject obj, bool value)
    {
    obj.SetValue(IsLeftMarginalLabelProperty, value);
    }

    public static readonly DependencyProperty IsRightMarginalLabelProperty =
    DependencyProperty.RegisterAttached(“IsRightMarginalLabel”, typeof(bool), typeof(NumericAxisEx), new PropertyMetadata(false, (d, e) => OnIsMarginalLabelChanged(d, e, HorizontalAnchorPoint.Right)));

    public static bool GetIsRightMarginalLabel(DependencyObject obj)
    {
    return (bool)obj.GetValue(IsRightMarginalLabelProperty);
    }

    public static void SetIsRightMarginalLabel(DependencyObject obj, bool value)
    {
    obj.SetValue(IsRightMarginalLabelProperty, value);
    }

    protected override void DrawTickLabels(AxisCanvas canvas, TickCoordinates tickCoords, float offset)
    {
    base.DrawTickLabels(canvas, tickCoords, offset);

    foreach (UIElement child in canvas.Children)
    {
        SetIsLeftMarginalLabel(child, false);
        SetIsRightMarginalLabel(child, false);
    }
    
    if (canvas.Children.Count >= 2)
    {
        var leftLabel = canvas.Children[0] as DefaultTickLabel;
        var rightLabel = canvas.Children[canvas.Children.Count - 1] as DefaultTickLabel;
    
        leftLabel.MeasureArrange();
        rightLabel.MeasureArrange();
    
        var isInBounds = leftLabel.Position.X - leftLabel.ActualWidth/2 >= 0;
        if (!isInBounds)
        {
            leftLabel.Position = new Point(0, leftLabel.Position.Y);
            SetIsLeftMarginalLabel(leftLabel, true);    
        }
    
        isInBounds = rightLabel.Position.X + rightLabel.ActualWidth / 2 <= this.ActualWidth;
        if (!isInBounds)
        {
            rightLabel.Position = new Point(0, rightLabel.Position.Y);
            SetIsRightMarginalLabel(rightLabel, true);
        }
    }
    

    }

    private static void OnIsMarginalLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e, HorizontalAnchorPoint anchorPoint)
    {
    var label = d as DefaultTickLabel;
    if (label != null)
    {
    label.HorizontalAnchorPoint = (bool)e.NewValue ? anchorPoint : HorizontalAnchorPoint.Center;
    }
    }
    }

Please try any of these and let us know which works the best for you,

Attachments
  • Yuriy
    It looks like the code snippet appears with wrong formatting. Please find the code attached in the text file.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.