Skip to main content

WebChartControl.CustomizeStackedBarTotalLabel Event

Occurs when the WebChartControl draws total labels for Stacked Bar series.

Namespace: DevExpress.XtraCharts.Web

Assembly: DevExpress.XtraCharts.v24.2.Web.dll

NuGet Package: DevExpress.Web.Visualization

#Declaration

public event CustomizeStackedBarTotalLabelEventHandler CustomizeStackedBarTotalLabel

#Event Data

The CustomizeStackedBarTotalLabel event's data class is CustomizeStackedBarTotalLabelEventArgs. The following properties provide information specific to this event:

Property Description
Argument Returns a series point argument value.
Text Gets or sets the total label text.
TextColor Gets or sets the total label’s text color.
TotalValue Returns the total label value.

#Remarks

This example shows how to change the color of the Stacked Bar series’s total label depending on the total value of points:

The images show stacked bar total labels before and after customization

using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Web;
using System;
using System.Collections.Generic;
using System.Drawing;

namespace TotalLabels {
    public partial class WebForm1 : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {

            WebChartControl chart = new WebChartControl();
            chart.RenderFormat = RenderFormat.Svg;
            chart.ID = "WebChart";
            this.Controls.Add(chart);
            chart.Height = 315;
            chart.Width = 560;

            chart.DataSource = DataPoint.GetDataPoints();
            chart.SeriesTemplate.ArgumentDataMember = "Argument";
            chart.SeriesTemplate.ValueDataMembers.AddRange("Value");
            chart.SeriesTemplate.SeriesDataMember = "Index";
            chart.SeriesTemplate.ChangeView(ViewType.StackedBar);
            chart.SeriesTemplate.LegendTextPattern = "Index: {S}";
            chart.DataBind();

            XYDiagram diagram = (XYDiagram)chart.Diagram;
            diagram.AxisX.QualitativeScaleOptions.AutoGrid = false;
            diagram.AxisX.QualitativeScaleOptions.GridSpacing = 1;
            diagram.AxisX.Tickmarks.MinorVisible = false;            

            StackedBarTotalLabel totalLabel = diagram.DefaultPane.StackedBarTotalLabel;
            totalLabel.Visible = true;

            chart.CustomizeStackedBarTotalLabel += Chart_CustomizeStackedBarTotalLabel;

        }

        private void Chart_CustomizeStackedBarTotalLabel(object sender, CustomizeStackedBarTotalLabelEventArgs e) {
            e.TextColor = (e.TotalValue >= 31) ? Color.Green : Color.Gray;
        }
    }
    public class DataPoint {
        public string Argument { get; set; }
        public double Value { get; set; }
        public int Index { get; set; }

        public static List<DataPoint> GetDataPoints() {
            return new List<DataPoint> {
                    new DataPoint { Index = 0, Argument = "Q1", Value = 17.0752},
                    new DataPoint { Index = 0, Argument = "Q2", Value = 9.98467},
                    new DataPoint { Index = 0, Argument = "Q3", Value = 8.63142},
                    new DataPoint { Index = 0, Argument = "Q4", Value = 6.59696},
                    new DataPoint { Index = 1, Argument = "Q1", Value = 15.0752},
                    new DataPoint { Index = 1, Argument = "Q2", Value = 10.97},
                    new DataPoint { Index = 1, Argument = "Q3", Value = 12.142},
                    new DataPoint { Index = 1, Argument = "Q4", Value = 9.59696},
                    new DataPoint { Index = 2, Argument = "Q1", Value = 14.0752},
                    new DataPoint { Index = 2, Argument = "Q2", Value = 10.8467},
                    new DataPoint { Index = 2, Argument = "Q3", Value = 9.642},
                    new DataPoint { Index = 2, Argument = "Q4", Value = 7.59696},
                };
        }
    }
}
See Also