We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How To Apply chart style as in Excel Sheet

Hi All,

I am working On Charts and I am having this requirement.

I have done with creating chart but my problem is I want to apply chart styles through coding.

I am working on Pie chart.

Now if you open Excel sheet and go to chart tools --> there will be three tabbs below that . Click on Design tab -- > you will see chart style block.In that block the style 2 or the second diagram of pie is there..

I want my pie chart to look like that.

how to apply this chart style to my pie chart through coding.

I hope you all Understand my question.

Please provide example and code.

I am using Excel 2007.

Thanks,

Hi Jack,

Please use the following code snippet to generate the Pie chart as desired. If there is any thing which need clarification, please feel free to reach us.

Code snippet:

string sInputFileName = @"C:\excelTrash\PieChartText.xlsx";
Workbook workbook = new Workbook();
Worksheet ws = workbook.Worksheets[0];
ws.Type = SheetType.Chart;
Worksheet data = workbook.Worksheets.Add("Data");
Cells cells = data.Cells;
cells["A1"].PutValue("Aspose.Cells");
cells["A2"].PutValue("Aspose.Words");
cells["A3"].PutValue("Aspose.PDF");
cells["B1"].PutValue(35);
cells["B2"].PutValue(50);
cells["B3"].PutValue(15);
ChartCollection charts = ws.Charts;
int index = charts.Add(ChartType.Pie, 5, 0, 15, 5);
Chart chart = charts[index];
chart.NSeries.Add("Data!B1:B3", true);
chart.NSeries.CategoryData = "Data!A1:A3";
chart.NSeries[0].DataLabels.ShowPercentage = true;
chart.NSeries[0].Points[0].Area.ForegroundColor = Color.Green;
chart.NSeries[0].Points[1].Area.ForegroundColor = Color.CornflowerBlue;
chart.NSeries[0].Points[2].Area.ForegroundColor = Color.Wheat;
workbook.Save(sInputFileName, SaveFormat.Xlsx);

Thanks,

how can set chart style like MS excel.


set the chart style quick.

Hi,

Thanks for your posting and using Aspose.Cells.

Please use the Chart.Style property to set the style of the chart. Please see the following sample code that explains how to make use of this property. I have also attached the source excel file used in this code and the output excel file generated by it for your 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];

chart.Style = 3;


workbook.Save(“output.xlsx”);

hi, Faiz


thank you very much.

but there has another question, how can i know someone style’s effect(looks like)? is any table of comparisons?

Hi,

Thanks for your feedback and using Aspose.Cells.

What you can do is to manually apply your chart style using Microsoft Excel and save the workbook on disk. Then load the same workbook using Aspose.Cells API and check the Chart.Style number. It will tell you which number value refers to which chart style.Mostly these numbers are in sequence, 1 means Style 1, 2 means Style 2 and 3 means Style 3 so on…

thanks, i got it.

hi,Faiz


i have test your idea and find some unexpected output.
you can follow below step to check:
1, use excel open your ‘output.xlsx’ and change style by quickstyle menu, for example, we select the first style.
2, use test code to get chart’s style,
3, open in excel again and change style to a diff style.
4, use test code to get chart’s style again.
5, repeat step 3 & 4

you will found the chart’s style value always be 3, will never change.
i think there has some bug here. please check it.

thanks

Hi,

Thanks for your feedback and using Aspose.Cells.

I have tested this issue with the latest version: Aspose.Cells for .NET (Latest Version) with the following sample code and it is giving correct results.

I changed the chart style to style 1 and it printed 1, then I changed the chart style to style 4 and it printed 4, so it is working fine.

C#


Workbook workbook = new Workbook(“output.xlsx”);


Worksheet worksheet = workbook.Worksheets[0];


Chart chart = worksheet.Charts[0];

Console.WriteLine(chart.Style);

hi

i use version 8.5.2 too, did you change the style by excel application?


Hi,

Thanks for your posting and using Aspose.Cells.

Yes, I changed the chart style using Microsoft Excel 2010 and then saved it and then executed the above code to see what it prints.

Strange ah


i use excel2013 x64.

hi, Faiz


i have used excel2010 for testing. the style number will be changed if using excel2010.

but if use 2013, the style number not be changing.

i think aspose implementation used 2010 style template other than 2013.


thanks.

Hi,

Thanks for your feedback and using Aspose.Cells.

You might be right. This issue is being caused by Excel 2013. We will check it with Excel 2013 and let you know.

Hi,

Thanks for using Aspose.Cells.

We were able to observe this issue. When chart style is updated with Excel 2013, then Chart.Style property
does not change. However, when Chart Style is updated with Excel 2010,
then Chart.Style property does change.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43844 - Chart.Style number does not change when chart style is updated with Excel 2013