How would I go about adding theme to a chart? The only information I’ve found regarding chart formatting is changing the ChartArea.Area methods (Background, Foreground, FillFormat, etc). Is it possible to get themes applied to a charts as I do with cells using the ForegroundThemeColor etc etc…?
Hi,
Thanks for your posting and using Aspose.Cells for .NET.
By themes, I think, you meant chart styles as shown in the screenshot below. If you meant something else, then please provide me your source and expected output xlsx files.
Normally, you will have to apply foreground, background, fonts etc yourself and there is no direct way to apply chart styles.
For setting chart’s appearance, please refer to this article for more.
Setting Charts Appearance
Hi,
We have logged a ticket for an enhancement for your requirements with an id: CELLSNET-40829
We will soon look into it and enhance this feature of apply themes to charts. Once we have an update on it, we will let you know here.
I’ll look into the previous post of yours which I think may lead me in the correct direction. Essentially I want the colors, font size, font name to change according to which theme is selected from the Page Layout tab. I’ve been able to manually apply the style to my chart if under the Chart Tools > Design, I select one of those items, much like what your screenshot is indicating. Then if I go under the Page Layout > Themes and mouse over other themes that chart’s appearance reflects that theme’s settings.
Hi,
Hi,
Please download and try the latest fix: Aspose.Cells for .NET v7.2.2.7 and let us know your feedback.
Please use the following sample code.
C#
Chart chart = workbook.Worksheets[0].Charts[0];
CellsColor cc = chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor;
cc.ThemeColor = new ThemeColor(ThemeColorType.Accent6, 0.6);
chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor = cc;
Thank you for the prompt response. I updated Aspose.Cells to the version you posted 7.2.2.7, when I tried using the code you supplied, I ran into issues.
Hi,
Thanks for your feedback.
It seems like SolidFill constructor is private so that’s why you are getting the Null Reference exception.
I was able to reproduce your mentioned exception with the following sample code and the source xlsx file attached by me.
We will fix this bug asap and update you.
I have attached the screenshot for a reference.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
Chart chart = worksheet.Charts[0];
CellsColor cc = chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor;
cc.ThemeColor = new ThemeColor(ThemeColorType.Accent6, 0.6);
chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor = cc;
workbook.Save(filePath + “.out.xlsx”);
Screenshot:
Great! Thank you.
Hi,
Thanks for your patience.
Please set the FillFomart.Type before calling FillFormat.SolidFill.
Please see the following code.
C#
string filePath = @“D:\Filetemp\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
Chart chart = worksheet.Charts[0];
chart.NSeries[0].Area.FillFormat.Type = FillType.Solid;
CellsColor cc = chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor;
cc.ThemeColor = new ThemeColor(ThemeColorType.Accent6, 0.6);
chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor = cc;
workbook.Save(filePath + “.out.xlsx”);
The issues you have found earlier (filed as CELLSNET-40829) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Applying the Theme color correctly colors the chart now. However, it appears these colors are static and do not dynamically change with Theme changes in Excel. If I go to Page Layout > Themes in Excel and change to various different Themes, the chart is no different. The rows I have in alternating color to the theme, those are changing according to which theme I hover over. Now, If I manually select the chart then under Chart Tools > Design > Chart Styles, clicking on one of these then going and selecting different themes does provide intended behavior.
Hi,
Thanks for your feedback.
We will look into this issue and update you asap.
Pleas also provide the following things that will help us quickly look into your issue.
1 - Sample project replicating the issue.
2 - Actual and expected output xls/xlsx files, you can create these manually.
3 - Screenshot highlighting your problems with red circles.
philip.betts:Applying the Theme color correctly colors the chart now. However, it appears these colors are static and do not dynamically change with Theme changes in Excel. If I go to Page Layout > Themes in Excel and change to various different Themes, the chart is no different.
kashif.iqbal:Hi Philip,Thank you for the feedback.philip.betts:Applying the Theme color correctly colors the chart now. However, it appears these colors are static and do not dynamically change with Theme changes in Excel. If I go to Page Layout > Themes in Excel and change to various different Themes, the chart is no different.I have tried to reproduce this issue at my end with the lines of code shared by Shakeel in the earlier post, but couldn't get success. If I go to PageLayout >> Themes, I can visualize the effect of hovering over different themes on the Chart. Please have a look at the attached file.If the issue still persists, please help us investigate the issue by providing your Excel file and, if possible, some screen shots to identify the issue.
Hi Philip,
Hi,
Amjad Sahi:Hi,"If I were to change the bolded lines to xls format instead of xlsx, the themeing is not applied in this case. I'm assuming to get these rich formatting of themes applied to charts, the files must be generated in the xlsx format, is this correct?"Yes, this is the limitation of XLS file format (Excel 97 - 2003). If you need to use or apply themes you have to use XLSX or other Excel 2007/2010 file formats as Themes/Colors are the advanced features of MS Excel 2007/2010.Thank you.
Hi,
Thanks for your feedback.
I was able to observe the issue with xls format. For xlsx format, everything is working fine, but when the workbook is exported to xls format and then you hover the mouse on the themes, the colors do not change.
It should be fixed. Also I manually created xls file and when I hover mouse on themes, it gets changed. So it is a bug and should be fixed in Aspose.
We will look into it and fix the problem and update you asap.
This issue has been logged as CELLSNET-40852.
Below is a test code, I have attached the output xls file and the screenshot for a reference.
C#
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
cells[“A1”].PutValue(“High”);
cells[“B1”].PutValue(“Medium”);
cells[“C1”].PutValue(“Low”);
cells[“D1”].PutValue(“Informational”);
cells[“E1”].PutValue(“New”);
cells[“F1”].PutValue(“Reopened”);
cells[“G1”].PutValue(“False Positive”);
cells[“H1”].PutValue(“Fixed”);
cells[“A2”].PutValue(17);
cells[“B2”].PutValue(9);
cells[“C2”].PutValue(41);
cells[“D2”].PutValue(6);
cells[“E2”].PutValue(7);
cells[“F2”].PutValue(31);
cells[“G2”].PutValue(11);
cells[“H2”].PutValue(88);
int chartIndex = sheet.Charts.AddFloatingChart(Aspose.Cells.Charts.ChartType.Bar, 5, 150, 500, 300);
Aspose.Cells.Charts.Chart chart = sheet.Charts[chartIndex];
chart.Title.Text = “test”;
string nSeriesData = “A2:H2”;
string categoryFieldData = “A1:H1”;
chart.NSeries.Add(nSeriesData, false);
chart.NSeries.CategoryData = categoryFieldData;
for (int i = 0; i < chart.NSeries.Count; i++)
{
if (cells[0, i + 1].Value == null)
{
chart.NSeries[i].Name = “”;
}
else
{
chart.NSeries[i].Name = cells[0, i + 1].Value.ToString();
}
}
//Format Chart
chart.Title.Font.Color = Color.Black;
chart.Title.Font.IsBold = true;
chart.Title.Font.Size = 12;
Aspose.Cells.Charts.Series series = chart.NSeries[0];
//Testing themeing
chart.NSeries[0].Area.FillFormat.Type = FillType.Solid;
CellsColor cc = chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor;
cc.ThemeColor = new ThemeColor(ThemeColorType.Accent1, 0.15);
chart.NSeries[0].Area.FillFormat.SolidFill.CellsColor = cc;
/*
series.Area.ForegroundColor = Color.FromArgb(171, 197, 228);
series.Area.FillFormat.Type = Aspose.Cells.Drawing.FillType.Solid;
*/
series.Border.IsVisible = false;
series.DataLabels.Font.Size = 10;
//chart.NSeries.IsColorVaried = false;
DataLabels dataLabels = series.DataLabels;
dataLabels.Position = LabelPositionType.OutsideEnd;
dataLabels.ShowCategoryName = false;
dataLabels.ShowValue = true;
dataLabels.ShowPercentage = false;
chart.CategoryAxis.AxisLine.IsVisible = false;
chart.CategoryAxis.MajorGridLines.IsVisible = false;
chart.CategoryAxis.TickLabels.Font.Size = 10;
chart.ValueAxis.MinValue = 0;
chart.ValueAxis.MaxValue = 110;
chart.ValueAxis.IsVisible = false;
chart.ValueAxis.MinorGridLines.IsVisible = false;
chart.ValueAxis.MajorGridLines.IsVisible = false;
chart.PlotArea.Border.IsVisible = false;
//chart.PlotArea.Area.FillFormat.Type = Aspose.Cells.Drawing.FillType.None;
//chart.ChartArea.Area.FillFormat.Type = Aspose.Cells.Drawing.FillType.None;
//chart.ChartArea.Area.ForegroundColor = Color.White;
chart.ShowLegend = false;
workbook.Save(“output.xls”, SaveFormat.Excel97To2003);
Screenshot: