Hi,
I'm trying to put on some custom labels on my chart, and I've been succeeding in parts..
I've gotten the custom label on the items using
Dim cta As Infragistics.UltraChart.Resources.Appearance.ChartTextAppearance
cta = New Infragistics.UltraChart.Resources.Appearance.ChartTextAppearance()cta.ChartTextFont = New Font("Arial", 7)cta.ItemFormatString = "<DATA_VALUE_ITEM:00.00>"cta.FontColor = Color.Whitecta.Visible = Truecta.Row = -2cta.Column = -2cta.PositionFromRadius = 100cta.HorizontalAlign = StringAlignment.Centercta.VerticalAlign = StringAlignment.NearchrtData.ColumnChart.ChartText.Add(cta)
but I want to succeed in adding a total ABOVE the columns.
Any ideas? Thanks in advance for the time spent.
What I got..
What I Want..
The chart doesn't have this built-in, so you will have to add these labels manually. I suggest using FillSceneGraph event for this. For example:private void ultraChart1_FillSceneGraph(object sender, FillSceneGraphEventArgs e){ if (e.Grid.Count <= 0) return;
List<string> labels = new List<string>(); IAdvanceAxis xAxis = (IAdvanceAxis)e.Grid["X"]; IAdvanceAxis yAxis = (IAdvanceAxis)e.Grid["Y"];
IChartData chartData = e.ChartCore.GetCurrentDataRef(); int rowCount = chartData.GetRowCount(); int columnCount = chartData.GetColumnCount();
for (int i=0; i<rowCount; i++) { double value = 0.0;
for (int j = 0; j < columnCount; j++) { value += chartData.GetValue(i, j); }
Point location = new Point((int)xAxis.Map(i + 0.5), (int)yAxis.Map(value)); Text label = new Text();
SizeF labelSize = Platform.GetStringSizePixels(value.ToString(), label.labelStyle.Font); location.X -= (int)labelSize.Width / 2; location.Y -= (int)labelSize.Height;
label.SetTextString(value.ToString()); label.bounds = new Rectangle(location, new Size((int)labelSize.Width, (int)labelSize.Height));
e.SceneGraph.Add(label); }}
Hi Max,
Thanks a lot for the post above. It works like a charm. I could space my X and Y labels neatly in the center of my axis for my Heatmap chart.
Could you guide me how to rotate my labels created as above, by a certain degree? I need my labels to be aligned by some degree (eg 30 degrees).
Thanka a lot.
I tried with the following code but it didn't work as expected: it rotates the first label correctly by 30 degrees, but the second label by 60 and third by 90 and so on. I have used the Matrix object's RotateAt method. I am rotating the Y axis labels.
for (int i = 0; i < columnCount; i++) { string value = chartData.GetColumnLabel(i).ToString();
GraphicsContext gc = new GraphicsContext(); Matrix m = new Matrix();
Point location = new Point((int)xAxis.Map(-.07), (int)yAxis.Map(i + 0.5)); Text label = new Text();
m.RotateAt(-30f, new PointF(location.X, location.Y)); gc.Transform = m;
//gc.SetClipBounds(e.ChartCore.GetChartLayer().GetOuterBounds());
e.SceneGraph.Add(gc);
e.SceneGraph.Add(label); }
Please let me know what I am missing here.
You should create a single GraphicsContext for all the labels you want to rotate. You're adding a new one for each label, so each GraphicsContext is contained within another GraphicsContext, compounding the angle.
The label rotation can be done much simpler by using this: label.labelStyle.Orientation = TextOrientation.Custom; label.labelStyle.RotationAngle = 30;
Yup, dont know how I missed that!. Thanks a ton - it works beautifully.