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
75
UltraWebChart: How to displaynegative bar value on the bottom of the bar
posted

Is there anyway to display negative bar values on the bottom of the bar and positive values on the top?  

Thanks in advance for your help.

  • 17605
    Suggested Answer
    posted

    We’ve added this functionality recently, so with next hotfix you will be able to achieve this with:

    this.ultraChart1.ColumnChart.ChartTextValueAlignment = ValueAlignment.PositiveAndNegative;

    For now as workaround you can try removing the column labels and adding them manually with:

     

    this.ultraChart1.FillSceneGraph += new Infragistics.UltraChart.Shared.Events.FillSceneGraphEventHandler(ultraChart1_FillSceneGraph);

      void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e)

            {

                // first get a reference to all the columns/bars in the chart.

                ArrayList allBoxes = new ArrayList();

     

                foreach (Primitive p in e.SceneGraph)

                {

                    // Loop through each (box) primitive and load the boxes with non-null non-zero data.

                    Box b = p as Box;

                    if (b != null)

                    {

                        // exclude the chart area (which are also boxes but not part of the data chart)

                        if (b.rect.X != 0 && b.rect.Y != 0)

                        {

                            allBoxes.Add(p);

                        }

                    }

                }

     

                // These boxes represent the chart data

                foreach (Box b in allBoxes)

                {

                    if (b.Value == null)

                    {

                        continue;

                    }

     

                    double boxValue = Convert.ToDouble(b.Value);

     

                    LabelStyle labelStyle = new LabelStyle();

                    SizeF labelSize = Infragistics.UltraChart.Core.Util.Platform.GetLabelSizePixels(b.Value.ToString(), labelStyle);

                   

     

                    // Add a text or the column value on top or on bottom of each column.

     

                    int x = b.rect.X + b.rect.Width / 2 - (int)(labelSize.Width / 2);

                    int y;

     

                    int labelOffset = 2;

     

                    if (boxValue >= 0)

                    {

                        y = b.rect.Y - (int)labelSize.Height / 2 - labelOffset;

                    }

                    else

                    {

                        y = b.rect.Bottom + (int)labelSize.Height / 2 + labelOffset;

                    }

     

                    Point textPoint = new Point(x, y);

     

                    // Create a text object to be displayed on the column (string column value can be used).

                    Text txtColumn = new Text(textPoint, b.Value.ToString(), labelStyle);

     

                    // Add the customized text to the chart.

                    e.SceneGraph.Add(txtColumn);

                }

            }