Back to Devexpress

CustomLegendItem.Text Property

corelibraries-devexpress-dot-xtracharts-dot-customlegenditem.md

latest5.7 KB
Original Source

CustomLegendItem.Text Property

Gets or sets the text the custom legend item displays.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XRLocalizable(true)]
[XtraChartsLocalizableCategory(XtraChartsCategory.Data)]
public string Text { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Data)>
<XRLocalizable(True)>
Public Property Text As String

Property Value

TypeDescription
String

A String that specifies the legend item text.

|

Example

This example demonstrates how to add a custom legend item to a legend.

View Example

Create a CustomLegendItem object and add it to the CustomItems collection. Use the following properties to configure the custom item:

CustomLegendItem.MarkerImageReturns the custom legend item’s marker image.CustomLegendItem.TextGets or sets the text the custom legend item displays.

To show custom and automatically generated legend items, set the LegendBase.ItemVisibilityMode to AutoGeneratedAndCustom.

cs
using DevExpress.Drawing;
using DevExpress.XtraCharts;
using System;
using System.IO;
using System.Windows.Forms;

namespace CustomLegendItemSample {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            #region #CustomLegendItems
            // Create a new custom item.
            CustomLegendItem item = new CustomLegendItem();
            chart.Legend.CustomItems.Add(item);
            // Specify its text and marker.
            item.Text = "Custom Legend Item";
            FileStream outfile = new FileStream("Image\\DXLogo_16x16.png", FileMode.Open);
            DXImage image = DXImage.FromStream(outfile);
            item.MarkerImage.DXImage = image;

            // Set a value indicating that both autogenerated and custom items are displayed.
            chart.Legend.ItemVisibilityMode = LegendItemVisibilityMode.AutoGeneratedAndCustom;
            #endregion #CustomLegendItems
        }
    }
}
vb
Imports DevExpress.Drawing
Imports DevExpress.XtraCharts
Imports System
Imports System.IO
Imports System.Windows.Forms

Namespace CustomLegendItemSample

    Public Partial Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
#Region "#CustomLegendItems"
            ' Create a new custom item.
            Dim item As CustomLegendItem = New CustomLegendItem()
            chart.Legend.CustomItems.Add(item)
            ' Specify its text and marker.
            item.Text = "Custom Legend Item"
            Dim outfile As FileStream = New FileStream("Image\DXLogo_16x16.png", FileMode.Open)
            Dim image As DXImage = DXImage.FromStream(outfile)
            item.MarkerImage.DXImage = image
            ' Set a value indicating that both autogenerated and custom items are displayed.
            chart.Legend.ItemVisibilityMode = LegendItemVisibilityMode.AutoGeneratedAndCustom
#End Region ' #CustomLegendItems
        End Sub
    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Text property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-chart-add-a-custom-legend-item/CS/CustomLegendItemSample/Form1.cs#L18

csharp
// Specify its text and marker.
item.Text = "Custom Legend Item";
FileStream outfile = new FileStream("Image\\DXLogo_16x16.png", FileMode.Open);

winforms-chart-add-a-custom-legend-item/VB/CustomLegendItemSample/Form1.vb#L22

vb
' Specify its text and marker.
item.Text = "Custom Legend Item"
Dim outfile As FileStream = New FileStream("Image\DXLogo_16x16.png", FileMode.Open)

See Also

CustomLegendItem Class

CustomLegendItem Members

DevExpress.XtraCharts Namespace