How to create chart/graph in excel sheet OpenXML 2.0 C#

openxmlopenxml-sdk

Previously I have posted a question how to populate data from Dataset into excel sheet and than how to create chart with that data. Not much luck with that post but now I have managed to populate data from dataset but struggling to create chart on the basis of that data also, I want chart in the same sheet as of my data. I dont want to create chart in "chart sheet". Could please anyone help me and if possible to give a code example of OpenXML chart creation.

following is the sample data that I have in my excel sheet and I want to create chart programatically based on this data.

CountryName             AnnualGrowth

UK                      757565

America                 568965

Canada                  555544

Italy                   665533

Germany                 558899

France                  995577

Regards!

Best Answer

Charts are really much more complicated to create with Open XML SDK. I wrote a spreadsheet library that creates the basic charts that Excel offers. Standard layout and no more (as yet). You can get it here: SpreadsheetLight.

Source code is available with the library, so you can use that to come up with something that suits you better. The main difficulty (and tedium) has to do with filling in the category/date axis (X-axis) and the value axis (Y-axis). And each chart type has its own classes in the SDK. For example, the column and bar charts have the BarChartSeries class. Doughnut charts and pie charts have the PieChartSeries class.

Related Topic