How can I do to show percentage in a ColumnChart3d in the same way we show percentage in a pie chart?
See images.
Thanks.
Hello Dariogs,
Maybe one possible approach to achieve this behavior is to handle ultraChart1_FillSceneGraph() event and include the code below:
private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e) { TextList.Clear(); string IsAddedKey = null; foreach (Primitive pr in e.SceneGraph) { if (pr.Row != -1 && pr.Column != -1 && IsAddedKey != (pr.Row.ToString() + "-" + pr.Column.ToString())) { decimal tempPercent= (Convert.ToDecimal(pr.Value) / CalcSum(dt.Rows[pr.Row]))*100; Text textLable = new Text(new Point((int)((Infragistics.UltraChart.Core.Primitives.Path)(pr)).GraphicsPath.PathPoints[0].X, (int)((Infragistics.UltraChart.Core.Primitives.Path)(pr)).GraphicsPath.PathPoints[0].Y), tempPercent.ToString("0.00") + " %"); textLable.PE.Fill = Color.Black; IsAddedKey = pr.Row.ToString() + "-" + pr.Column.ToString(); TextList.Add(textLable); } } foreach (var item in TextList.Distinct()) e.SceneGraph.Add(item); }
private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e)
{
TextList.Clear();
string IsAddedKey = null;
foreach (Primitive pr in e.SceneGraph)
if (pr.Row != -1 && pr.Column != -1 && IsAddedKey != (pr.Row.ToString() + "-" + pr.Column.ToString()))
decimal tempPercent= (Convert.ToDecimal(pr.Value) / CalcSum(dt.Rows[pr.Row]))*100;
Text textLable = new Text(new Point((int)((Infragistics.UltraChart.Core.Primitives.Path)(pr)).GraphicsPath.PathPoints[0].X, (int)((Infragistics.UltraChart.Core.Primitives.Path)(pr)).GraphicsPath.PathPoints[0].Y), tempPercent.ToString("0.00") + " %");
textLable.PE.Fill = Color.Black;
IsAddedKey = pr.Row.ToString() + "-" + pr.Column.ToString();
TextList.Add(textLable);
}
foreach (var item in TextList.Distinct())
e.SceneGraph.Add(item);
Please take a look at the attached sample for more details. Please let me know if you have any questions.
Regards
Have you been able to resolve your issue ? Did you have a time to take a look at the attached sample. Please let me know if you have any questions.
I will try the example and let you know.
Thanks
Dario
Thanks for the feedback Dario. If you have any questions, do not hesitate to write us.
Hi again,
Thanks for attached screenshots. Generally this behavior is expected, because our control try to drawn the lables in the most suitable place in the chart (depending of empty space, other elements, angle of rotation and so on). If you try to rotate or scalling your chart, you will see that these lables will change their possition in the chart area. Maybe one possible approach could be if you rotate your chart with few degrees.
Please let me know if you have any questions.
I know 2 months had passed from my last request, but just today I've been testing you suggestion, and with a small change it worked, but still having a issue. I am attaching an image with my results to show you my problem. How do I do to positionate the labels in the top of each column, it looks like sometimes it works and sometimes it doesn't.
Here my code....
private void FillSceneGraphEvent(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e)
List<Text> TextList = new List<Text>();
+ pr.Column.ToString()))
decimal value = pr.Value != null ? Convert.ToDecimal(pr.Value) : 0;
if (value > 0)
Text textLabel = new Text(new Point((int)((Infragistics.UltraChart.Core.Primitives.Path)(pr)).GraphicsPath.PathPoints[0].X, (int)((Infragistics.UltraChart.Core.Primitives.Path)(pr)).GraphicsPath.PathPoints[0].Y), value.ToString(), new Infragistics.UltraChart.Shared.Styles.LabelStyle(new Font("Arial", 8, FontStyle.Bold), Color.Black, true, true, true, StringAlignment.Center, StringAlignment.Center, Infragistics.UltraChart.Shared.Styles.TextOrientation.Horizontal));
textLabel.PE.Fill =
Color.FromArgb(51, 51, 51);
IsAddedKey = pr.Row.ToString() +
"-" + pr.Column.ToString();
TextList.Add(textLabel);