Free Support Forum - aspose.com

Informations about graph

Hello

If a document contains a Shape in which there is a chart, is there any method to get the informations about the chart, such as datas, chart type, etc. ?
I tried using the Shape methods but couldn’t get any valuable datas.

Thank you in advance

Jean-Pascal Lim

Hi Jean,


Thanks for your inquiry. Unfortunately, Aspose.Words does not provide the requested feature. However, you can extract the contents of Excel charts from document as shown in following code snippet. Once you have Excel file, you can use Aspose.Cells to get the chart type, category data, chart data for a series etc. Please read following documentation links for your kind reference.

http://www.aspose.com/docs/display/cellsnet/Chart+Class
http://www.aspose.com/docs/display/cellsnet/Series+Class
http://www.aspose.com/docs/display/cellsnet/SeriesCollection+Class

I am moving this thread to Aspose.Total forum. My colleagues from Aspose.Cells team will reply you shortly about getting chart information.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:green;mso-no-proof:yes”>// Open document<o:p></o:p>

Document doc = new Document(MyDir + "chart.docx");

//get collection of shapes

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

int i = 0;

//Loop through all shapes

foreach (Shape shape in shapes)

{

if (shape.OleFormat != null)

{

//Extract OLE object

if (shape.OleFormat.ProgId == "Excel.Sheet.12")

{

shape.OleFormat.Save(String.Format(MyDir + "out_{0}.xlsx", i));

i++;

}

}

}

Hi,


I am a representative of Aspose.Cells team.

Yes, as my colleague (from Aspose.Words team) Tahir told you that once you have saved the XLSX file either to a physical location or streams, you may load the file by Aspose.Cells APIs and get the designer chart in the template, you may use some attributes for your required needs, e.g


i) To get chart type --> you may use Chart.Type attribute
ii) To get category data area of the chart --> you may use SeriesCollection.CategoryData attribute
iii) To get Chart data for a series --> you may use Series.Values property
iv) Similarly, to get chart X values for a series --> you may use Series.XValues attribute accordingly.

–> How to get the chart in the workbook.
var workbook = new Workbook(filePathString);
//Get the first chart in the first worksheet.
var chart = workbook.Worksheets[0].Charts[0];
//…

Thank you.