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
Silly me, I gave you a solution for the axis labels instead of chart text labels.
public partial class Form1 : Form{
LabelRenderer myLabelRenderer;
ChartTextAppearance chartText = new ChartTextAppearance(); chartText.Column = chartText.Row = -2; chartText.Visible = true; chartText.ItemFormatString = "<MYLABEL>"; myLabelRenderer.Font = chartText.ChartTextFont; chart.ColumnChart.ChartText.Add(chartText);
private void chart_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e){ foreach (Primitive p in e.SceneGraph) { Box box = p as Box; if (box != null && box.Layer != null && box.Row != -1 && box.Column != -1) { myLabelRenderer.ColumnWidth = box.rect.Width; break; } }}}
public string ToString(Hashtable context){ if (ColumnWidth <= 0) { ChartControl.InvalidateLayers(); return ""; }
string label = (string)context["ITEM_LABEL"]; SizeF labelSize = Platform.GetStringSizePixels(label, this.Font); if (labelSize.Width > ColumnWidth) { return label.Substring(0, Convert.ToInt32(label.Length * ColumnWidth / labelSize.Width)); } return label;}}
Max:
The ClipTextAxisLabelLayoutBehavior behavior is exactly what I would like to accomplish, but I can't seem to apply it to the ChartTextAppearances of my stacked column chart. Any suggestions on how to make the ChartText comply with that behavoir restriction? (I've tried all the permutations I could think of.) In the meantime, I'll move forward with your FillSceneGraph suggestion.
Thanks, O Great Chart Guru!
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);}