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
799
Positioning Labels on UltraChart.StackColumnChart
posted

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.White
cta.Visible = True
cta.Row = -2
cta.Column = -2
cta.PositionFromRadius = 100
cta.HorizontalAlign = StringAlignment.Center
cta.VerticalAlign = StringAlignment.Near
chrtData.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..

 

Parents
No Data
Reply
  • 26458
    Verified Answer
    Offline posted

    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);
        }
    }

Children