Back to Devexpress

WebChartControl.CustomizeStackedBarTotalLabel Event

aspnet-devexpress-dot-xtracharts-dot-web-dot-webchartcontrol-3e8c7ca6.md

latest9.3 KB
Original Source

WebChartControl.CustomizeStackedBarTotalLabel Event

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

Namespace : DevExpress.XtraCharts.Web

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

NuGet Package : DevExpress.Web.Visualization

Declaration

csharp
public event CustomizeStackedBarTotalLabelEventHandler CustomizeStackedBarTotalLabel
vb
Public Event CustomizeStackedBarTotalLabel As CustomizeStackedBarTotalLabelEventHandler

Event Data

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

PropertyDescription
ArgumentReturns a series point argument value.
TextGets or sets the total label text.
TextColorGets or sets the total label’s text color.
TotalValueReturns 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:

csharp
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},
                };
        }
    }
}
vb
Imports DevExpress.XtraCharts
Imports DevExpress.XtraCharts.Web
Imports System
Imports System.Collections.Generic
Imports System.Drawing

Namespace TotalLabels
    Public Partial Class WebForm1
        Inherits Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

            Dim chart As WebChartControl = New WebChartControl()
            chart.RenderFormat = RenderFormat.Svg
            chart.ID = "WebChart"
            Me.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()

            Dim diagram As XYDiagram = CType(chart.Diagram, XYDiagram)
            diagram.AxisX.QualitativeScaleOptions.AutoGrid = False
            diagram.AxisX.QualitativeScaleOptions.GridSpacing = 1
            diagram.AxisX.Tickmarks.MinorVisible = False

            Dim totalLabel As StackedBarTotalLabel = diagram.DefaultPane.StackedBarTotalLabel
            totalLabel.Visible = True

            chart.CustomizeStackedBarTotalLabel += AddressOf Chart_CustomizeStackedBarTotalLabel

        End Sub

        Private Sub Chart_CustomizeStackedBarTotalLabel(ByVal sender As Object, ByVal e As CustomizeStackedBarTotalLabelEventArgs)
            e.TextColor = If(e.TotalValue >= 31, Color.Green, Color.Gray)
        End Sub
    End Class
    Public Class DataPoint
        Public Property Argument As String
        Public Property Value As Double
        Public Property Index As Integer

        Public Shared Function GetDataPoints() As List(Of DataPoint)
            Return New List(Of DataPoint) From {
                    New DataPoint With {
                    .Index = 0,
                    .Argument = "Q1",
                    .Value = 17.0752
                },
                    New DataPoint With {
                    .Index = 0,
                    .Argument = "Q2",
                    .Value = 9.98467
                },
                    New DataPoint With {
                    .Index = 0,
                    .Argument = "Q3",
                    .Value = 8.63142
                },
                    New DataPoint With {
                    .Index = 0,
                    .Argument = "Q4",
                    .Value = 6.59696
                },
                    New DataPoint With {
                    .Index = 1,
                    .Argument = "Q1",
                    .Value = 15.0752
                },
                    New DataPoint With {
                    .Index = 1,
                    .Argument = "Q2",
                    .Value = 10.97
                },
                    New DataPoint With {
                    .Index = 1,
                    .Argument = "Q3",
                    .Value = 12.142
                },
                    New DataPoint With {
                    .Index = 1,
                    .Argument = "Q4",
                    .Value = 9.59696
                },
                    New DataPoint With {
                    .Index = 2,
                    .Argument = "Q1",
                    .Value = 14.0752
                },
                    New DataPoint With {
                    .Index = 2,
                    .Argument = "Q2",
                    .Value = 10.8467
                },
                    New DataPoint With {
                    .Index = 2,
                    .Argument = "Q3",
                    .Value = 9.642
                },
                    New DataPoint With {
                    .Index = 2,
                    .Argument = "Q4",
                    .Value = 7.59696
                }
            }
        End Function
    End Class
End Namespace

See Also

WebChartControl Class

WebChartControl Members

DevExpress.XtraCharts.Web Namespace