We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Show or hide Excel chart legend in C#, VB.NET

Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files. Using this library, you can show or hide Excel chart legend in C#, VB.NET. HasLegend property of IChart interface is used to show or hide Excel chart legend. By default, this property is set to true.

Steps to show or hide Excel chart legend, programmatically:

Step 1: Create a new C# console application project.

Create a new C# console application

Create a new C# console application

Step 2: Install the Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.

Install NuGet package

Install NuGet package

Step 3: Include the following namespace in the Program.cs file.


using Syncfusion.XlsIO;



Imports Syncfusion.XlsIO


Step 4: Use the following code snippet to show or hide Excel chart legend in C#, VB.NET.


using (ExcelEngine excelEngine = new ExcelEngine())
    //Instantiate the application object
    IApplication application = excelEngine.Excel;
    //Open the workbook containing chart
    IWorkbook workbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic);
    //Accessing the first worksheet
    IWorksheet worksheet = workbook.Worksheets[0];
    //Accessig first chart in the worksheet
    IChart chart = worksheet.Charts[0];
    //To hide legend in chart
    chart.HasLegend = false;
    //Save the file
    string fileName = "Output.xlsx";



Using excelEngine As ExcelEngine = New ExcelEngine()
    'Instantiate the application object
    Dim application As IApplication = excelEngine.Excel
    'Open the workbook containing chart
    Dim workbook As IWorkbook = application.Workbooks.Open("Sample.xlsx", ExcelOpenType.Automatic)
    'Accessing the first worksheet
    Dim sheet As IWorksheet = workbook.Worksheets(0)
    'Accessig first chart in the worksheet
    Dim chart As IChart = sheet.Charts(0)
    'To hide legend in chart
    chart.HasLegend = False
    'Save the file
    Dim fileName As String = "Output.xlsx"
End Using


A complete Windows Forms working example of how to copy Excel worksheet to another workbook in C# and VB can be downloaded from Show or hide Excel chart legend.zip.

 Refer here to explore the rich set of Syncfusion Excel (XlsIO) library features.

See Also:

How to make visible the grid lines of primary category axis in the chart?

How to add text box shape in Excel charts?

How to create Excel line with markers chart in C#, VB>NET?

How to customize the items in the ChartLegend?

How to change the chart type?

How to change the color of series?

How to make the secondary axis visible in chart?

How to reverse Excel chart axis order in C#, VB.NET?


Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer the link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile