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
295
Stacked Bar Chart Section Label on Chart
posted

Is it possible to have the label of each section of a stacked column chart show up on the chart itself? Is it possible to also change the width of each bar?

I'd like each section to have a label. I changed the tooltip format to show the value and label but I don't know how to display the label on the chart. I'd also like to change the default width of the bar. Currently I have one series of data and when it's displayed on the chart it expands to the full width of the chart. Is there a way to change the width?

  • 295
    Verified Answer
    posted

    Here is an answer I received from Infragistics support which solved the problem.

    -------------------------------------------------------------------

    Thank you for submitting your query with Infragistics Developer Support and providing the screenshot.

    In order to set the label of each section of Stacked Column Chart, you need to use "ChartTextAppearance".

    You can use the following code:

    private void Form1_Load(object sender, EventArgs e)
            {
                NumericSeries seriesB = this.GetNumericSeriesUnBound();
                for (int i = 0; i < seriesB.Points.Count; i++)
                {
                    ChartTextAppearance ch = new ChartTextAppearance();
                    ch.Row = 0;
                    ch.Column = i;
                    ch.ItemFormatString = "Label " + (i + 1).ToString();
                    ch.Visible = true;
                    this.ultraChart1.ColumnChart.ChartText.Add(ch);
                }
                this.ultraChart1.Series.Add(seriesB);
                this.ultraChart1.Axis.X.RangeType = Infragistics.UltraChart.Shared.Styles.AxisRangeType.Custom;
                this.ultraChart1.Axis.X.RangeMin = 0;
                this.ultraChart1.Axis.X.RangeMax = 3;

            }
            private NumericSeries GetNumericSeriesUnBound()
            {
                NumericSeries series = new NumericSeries();
                series.Label = "Series B";
                series.Points.Add(new NumericDataPoint(5.0, "Point A", false));
                series.Points.Add(new NumericDataPoint(4.0, "Point B", false));
                series.Points.Add(new NumericDataPoint(3.0, "Point C", false));
                series.Points.Add(new NumericDataPoint(2.0, "Point D", false));
                series.Points.Add(new NumericDataPoint(1.0, "Point E", false));
                return series;
            }
    }