Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm working on creating an Excel Chart from my C# application that pulls data out of my SQL Server database, and using that data, creates some Charts in an Excel instance. I have a pie chart that displays with the data, and all is well, accept I want to change the background color of the ChartArea and maybe use a gradient to add a little visual variation. I'm having trouble figuring out how do do that in C# using OLE. It looks like Office 16 is installed. This should be simple, but I'm having trouble with this. I saw a chart.ChartArea.Fill.BackColor property, but it's read only (I can't set it). Not sure how to do this programmatically. Any ideas would be helpful. Thanks.

What I have tried:

I've searched (bing, google)around, but can't find anything. There are variations, but not my particular problem. I can change it manually, when the chart in my worksheet comes up, but I want to be able to do it programmatically.
Posted
Updated 30-Oct-18 4:03am

1 solution

Access it by the RGB property of Backcolor.
chart.ChartArea.Fill.BackColor.RGB = RGB(221, 221, 221)
Also if you want hints at how to do something using C# programatically in Excel that you know how to do manually, record a macro. Do it manuually with the macro recording. review the macro code afterwards for how to do the task in VBA. Then you have hints of how to do it in C#.
Cheers!

FillFormat Object (Excel) | Microsoft Docs[^]
 
Share this answer
 
v3
Comments
Matthew Menard 30-Oct-18 10:21am    
I realized that I needed the ForeColor afterall. But that same structure work great. Any idea on how to create a gradient on that, from one color to another?
Alek Massey 30-Oct-18 11:10am    
I updated the solution with a link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900