Example E452
Visible to All Users

Chart for WinForms - How to Conditionally Hide Series Labels

This example conditionally hides series labels of charts. Handle the ChartControl.CustomDrawSeriesPoint event and change the e.LabelText parameter's value.

The example hides all point's labels except the last one:

Hidden point labels in a Chart

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using System; using System.Windows.Forms; using DevExpress.XtraCharts; using DevExpress.XtraCharts.Designer; using System.Linq; namespace ConditionallyHideSeriesLabels { public partial class Form1 : Form { public Form1() { InitializeComponent(); // This line of code is generated by Data Source Configuration Wizard // Create a new DataSet System.Data.DataSet xmlDataSet = new System.Data.DataSet(@"XML DataSet"); // Load the XML document to the DataSet xmlDataSet.ReadXml(@"Data\GDPofG7.xml"); // This line of code is generated by Data Source Configuration Wizard chartControl1.DataSource = xmlDataSet.Tables[@"GDP"]; chartControl1.SeriesTemplate.ArgumentDataMember = @"Year"; chartControl1.SeriesTemplate.ValueDataMembers.AddRange(@"Product"); } private void chartControl1_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) { // Hide all point's labels except the last one. var test = e.Series.Points.Max(p => p.ArgumentX.NumericalArgument); if(!e.Series.Points.Max(p => p.ArgumentX.NumericalArgument).Equals(e.SeriesPoint.NumericalArgument)) { e.LabelText = ""; } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.