Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
405
Dynamically resizing ChartText Labels based on Column Width
posted

Hoping for advice from the IG chart gurus...

Desired Result: I need to truncate ChartText labels (based on ITEM_LABEL) to fit within the column bounds of a 2d stacked column chart.

Progress so far: After searching the docs & boards, I've successfully implemented a custom class that implements IRenderLabel and I can truncate the labels based on a fixed size or number of characters.

Problem: How can I get a reference to the rectangle element that the label is being drawn within so that my custom IRenderLabel class can truncate the text to fit within the column. (The column width is subject to change as the form is resized, so a fixed width truncation would not allow long lables to to be displayed in their entirity once the chart is wide enough to display them.)

 I appreciate your help and insight.

 At your service,

Jeff

Parents
  • 26458
    Offline posted
    I think the simplest solution is to use a clip text behavior for x axis series labels. It will automatically determine if the series label needs to be trimmed.

    ClipTextAxisLabelLayoutBehavior behavior = new ClipTextAxisLabelLayoutBehavior();
    behavior.ClipText =
    true;
    behavior.Enabled =
    true;
    behavior.EnableRollback =
    false;
    behavior.HideText =
    false;
    behavior.Trimming =
    StringTrimming.EllipsisCharacter;
    behavior.UseOnlyToPreventCollisions =
    false;

    ultraChart1.Axis.X.Labels.SeriesLabels.Layout.Behavior = AxisLabelLayoutBehaviors.UseCollection;
    ultraChart1.Axis.X.Labels.SeriesLabels.Layout.BehaviorCollection.Clear();
    ultraChart1.Axis.X.Labels.SeriesLabels.Layout.BehaviorCollection.Add(behavior);

    Of course, you can still use IRenderLabel instead, you'll just have to find the column width. If you handle FillSceneGraph event, use the axis.Map method to find it. You will also need to measure your strings in IRenderLabel.ToString using Infragistics.UltraChart.Core.Util.Platform.GetStringSizePixels() because the label's font will affect the its width.

    IAdvanceAxis
    xAxis = (IAdvanceAxis)e.Grid["X"];
    if (xAxis != null)
    {
       double width = xAxis.Map(1) - xAxis.Map(0);
    }

Reply Children