Inserting Aspose.Chart into Powerpoint via streaming


#1

I'm having difficulty inserting an Aspose.Chart, created in memory, into my PowerPoint presentation.

Dim oMemoryStream As New MemoryStream

' - Generate Chart - '

Dim oChart As New Aspose.Chart.Chart

Dim oSeries As New Aspose.Chart.ASeries

oSeries .ChartType = Aspose.Chart.ChartType.Line

For Each oDataRow In oDataSet.Tables(0).Rows

oSeries .DataPoints.Add(1, 1)

Next

oChart.NSeries.Add(oSeries)

oChart.Save(oMemoryStream, System.Drawing.Imaging.ImageFormat.Bmp)

oSlide.Shapes.AddOleObjectFrame(280, 1000, 5200, 2000, "Chart", oMemoryStream.ToArray)

The above code will insert the OLE object and give me the text "Object Changed" but, when I click the object to update it, it gives me the following error message:

The server application, source file, or item can't be found, or returned an unknown error. You may need to reinstall the server application.

I have successfully saved the chart to disk but I'd rather do it by memory stream so I don't have to change permissions on the server. Any suggestions?


#2

Charts created with Aspose.Chart can be inserted to a presentation as Picture only.


#3

Okay, thanks. How do you stream a picture into the chart? I've got it working with a file on disk:

oChart.Save(PathName & "\charts\" & "chart.bmp")

Dim oPicture As New Aspose.PowerPoint.Picture(oPresentation, PathName & "\charts\" & "chart.bmp")

Dim intPicID As Integer = oPresentation.Pictures.Add(oPicture)

oSlide.Shapes.AddPictureFrame(intPicID, 280, 1000, 2500, 2000)

I've tried to replace this line

Dim oPicture As New Aspose.PowerPoint.Picture(oPresentation, PathName & "\charts\" & "chart.bmp")

with this (after saving the chart to oMemoryStream):

Dim oPicture As New Aspose.PowerPoint.Picture(oPresentation, oMemoryStream)

but it does not work.


#4

Dim bmp As Bitmap = oChart.Save()

Dim oPicture As New Aspose.PowerPoint.Picture(oPresentation, bmp)



But your code should work too. Try to add this line before creating Picture object:

oMemoryStream.Position = 0

Dim oPicture As New …


#5

Thanks! Both ways work now. I think your suggestion is more elegant so I will go with that. Thanks again.

Is there any way to display the X-Axis labels at an angle instead of just flat?


#6

Sorry, I can’t help with it. Please ask questions about creating charts in Aspose.Chart forum.