How to remove gridlines, labels, tickmarks, axis lines, and legends from Charts – VB.NET

The Chart functionality built into Visual Studio 2012 is a great way to provide a user some visual insight into the data your program is providing.
You may discover though that the default chart tends to be a little crowded with gridlines, labels, tickmarks, axis lines, and legends all crowded together with your data.

Visual Studio 2012 - Stock Chart

A stock chart added to a form in VB.net Visual Studio 2012

In some cases, this may be desired, but if you are instead looking to provide the user with a quick visual, or are just opting for a cleaner look, a lot of these options can be turned off.

Visual Studio 2012 - Custom Chart

A custom chart added to a form in VB.net Visual Studio 2012

The majority of these I prefer to handle inside the code editor where we can address:

  • LineWidth
  • LabelStyle
  • MajorGrid
  • MinorGrid
  • MajorTickMark
  • MinorTickMark

This code can be added to an appropriate event in your program, or would even work on Form Load.

Chart1.ChartAreas(0).AxisX.LineWidth = 0
Chart1.ChartAreas(0).AxisY.LineWidth = 0
Chart1.ChartAreas(0).AxisX.LabelStyle.Enabled = False
Chart1.ChartAreas(0).AxisY.LabelStyle.Enabled = False
Chart1.ChartAreas(0).AxisX.MajorGrid.Enabled = False
Chart1.ChartAreas(0).AxisY.MajorGrid.Enabled = False
Chart1.ChartAreas(0).AxisX.MinorGrid.Enabled = False
Chart1.ChartAreas(0).AxisY.MinorGrid.Enabled = False
Chart1.ChartAreas(0).AxisX.MajorTickMark.Enabled = False
Chart1.ChartAreas(0).AxisY.MajorTickMark.Enabled = False
Chart1.ChartAreas(0).AxisX.MinorTickMark.Enabled = False
Chart1.ChartAreas(0).AxisY.MinorTickMark.Enabled = False
Chart1.ChartAreas(0).BackColor = SystemColors.Control
Me.Refresh()

I prefer to handle the legend visibility via the GUI by adjusting the properties section.

1. Click on your chart

2. Locate the Series – Collection in the properties sections and click on the … button

Visual Studio 2012 Chart Series Collection Property

Visual Studio 2012 Chart Series Collection Property

 

3. Set Legend IsVisibleInLegend to False

Visual Studio 2012 Chart Series Collection Property - Legend

Visual Studio 2012 Chart Series Collection Property – Legend

Leave a Reply

Your email address will not be published. Required fields are marked *