Reputation: 329
I'm trying to change the Line color of chart in excel with C# and it's not working. I already tried this solution but it just doesn't work at all.
The graph is displayed correctly with the correct value but the color is the default blue one from excel.
Here is my code for the graph
ChartObject chartObject = excelIndicateur.addChart();
chartObject.Chart.SetSourceData(fullDataRange);
SeriesCollection sc = chartObject.Chart.SeriesCollection();
Series s = sc.Item(1);
s.Format.Line.ForeColor.RGB = ColorTranslator.ToOle(chartColor);
chartObject.Chart.ChartType = XlChartType.xlLine;
Upvotes: 0
Views: 1755
Reputation: 6476
Actually, if you set the ChartType
first the problem goes away.
The default ChartType
is Column which has the Border propety. When you change it to a Line ChartType
, the Border properties are moved to the Line. If you set the ChartType
to Line first then ForeColor will work and your code will be cleaner.
Upvotes: 1
Reputation: 329
For those interested about how to make this work,I did some test with all the property and it finally worked with
s.Border.Color = ColorTranslator.ToOle(chartColor);
Upvotes: 0