Timmo
Timmo

Reputation: 2334

Excel Interop - Hiding Categories in Chart

I'm looking for a way to hide/disable certain categories on a chart. (The Y Axis)

How this works with the filter:

Filter

Does anyone know how i can accomplish this in .NET With Excel Interop?

Upvotes: 1

Views: 416

Answers (1)

haindl
haindl

Reputation: 3221

I hope I'm not too late to the party because this question is already a month old by now, but better late than never, I guess.

If you know the index of the category, you can use this code:

// Replace ActiveChart with your specific chart.
// The index of the ChartGroup is always 1,
// unless you have multiple chart groups in your chart.
var chartGroup = (ChartGroup)_application.ActiveChart.ChartGroups(1);
var category = (ChartCategory)chartGroup.FullCategoryCollection(Index: 2);
category.IsFiltered = true;

If you only know the name, you need to iterate over the categories:

// If you want to skip the already hidden categories,
// you can use .CategoryCollection() instead of .FullCategoryCollection() two times.
var categories = (CategoryCollection)chartGroup.FullCategoryCollection();
for (int i = 1; i <= categories.Count; i++)
{
    var category = (ChartCategory)chartGroup.FullCategoryCollection(i);
    if (category.Name == "W2 - 13/01/17")
        category.IsFiltered = true;
}

Upvotes: 1

Related Questions