tags:

views:

135

answers:

1

How to set the legend to overlay on the right of the excel chart using c#?

Refer to MS excel it has a checkbox "show the legend without overlapping the chart" in legend properties window.

Thanks for your help.

+1  A: 

If you're using the excel automation engine (via the COM object and .NET interoperability layer), then the Chart object contains a Legend object, which has a Position property and an IncludeInLayout boolean property. It may be what you're looking for.

M.A. Hanin
Thank you for your answer.I'm using Interop.Excel and this is what I'm using right now.chartPage.Legend.Position = XlLegendPosition.xlLegendPositionCorner;Could you please show me how to access the IncludeInLayout property?
mtfnmtfn
It should be chartPage.Legend.IncludeInLayout = false / true.What version of Excel are you using?
M.A. Hanin
After I update the Interop.Excel dll to the newer version, then the IncludeInLayout property appears and it works now. Thank you very much.
mtfnmtfn
You're welcome. I'd apperciate if you mark my answer as being helpful. Accepting an answer will also encourage other people to help you with future questions (reputation points is the only reward for the people answering you).
M.A. Hanin
"mark my answer as being helpful" << Did you mean setting this answer as my accepted answer by clicking the green check mark? I can't vote up because it requires 15 reputation.This is the first time I post my question here. If I did it wrong, please don't hesitate to let me know. Thanks again.
mtfnmtfn
Accepting the answer is acknoledgement enough. Thank you!
M.A. Hanin
+1 because the OP cannot (and it's a good answer). What a silly rule though. The OP should always be able to vote up on their own threads.
Mike Rosenblum
@Mike Rosenblum, now here's a man with great sense of justice! :-) thank you.
M.A. Hanin