This project has moved and is read-only. For the latest updates, please go here.

Removing Major Gridlines from chart?

Mar 29, 2012 at 4:55 AM

I'm generating a line chart and all looks as it should, except I can't figure out how to remove the major gridlines from the chart itself.

Take a look at the screenshot here: http://www.eco.ca/gridlines.png to see what I mean. I don't want the 4 black lines going across my chart.

Mar 30, 2012 at 6:07 AM

I'm not sure if there is a better way, but after much messing around, I compared the two Excel files XML and found the section for the gridLines. Here's how I removed them:

' remove the major gridlines       
Dim nl As System.Xml.XmlNodeList = chart.ChartXml.GetElementsByTagName("c:majorGridlines")       
For i As Integer = 0 To nl.Count - 1           
Dim n As System.Xml.XmlNode = nl(i)           
Dim pn As System.Xml.XmlNode = n.ParentNode
pn.RemoveChild(n)       
Next

Apr 2, 2012 at 6:40 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Dec 6, 2012 at 8:02 PM

Here is some C# for people who care.

System.Xml.XmlNodeList nl = chart.ChartXml.GetElementsByTagName("c:majorGridlines");
for (int i = 0; i < nl.Count; i++)
{
    nl[i].ParentNode.RemoveChild(nl[i]);
}