I've been having a play with this myself and looked at the example code you sent me:
I have attached the pptx file I created SecondExample.pptx. I basically created a new pptx, inserted a chart and deleted the title so the chart was the the first object.
It fails here because i is too big, As a fix I set the for loop to create only the number of series and that produces a corrupt result. Is it possible to have an example that runs?
Public Shared Function ASPOSEGetDataTable() As System.Data.DataTable
Dim table As New System.Data.DataTable()
table.Columns.Add("CatName", GetType(String))
table.Columns.Add("Value", GetType(Double))
table.Rows.Add("London", 200)
table.Rows.Add("Financial", 92)
table.Rows.Add("The Ind", 82)
table.Rows.Add("Evening Mail", 65)
table.Rows.Add("Metro", 161)
table.Rows.Add("Independent", 48)
table.Rows.Add("Daily Star", 133)
table.Rows.Add("Manchester", 116)
table.Rows.Add("Sun", 15)
table.Rows.Add("Guardian", 115)
Return table
End Function
Public Shared Sub ASPOSEModifyColumnChart()
Dim path As String = "C:\bin\Aspose Data\"
Dim pres As New PresentationEx(path & "SecondExample.pptx")
Dim slide As SlideEx = pres.Slides(0)
Dim chart As ChartEx = CType(slide.Shapes(0), ChartEx)
Dim data As ChartDataEx = chart.ChartData
'series.XValues.RemoveAt(0);
'series.YValues.RemoveAt(0);
Dim extractedData As System.Data.DataTable = ASPOSEGetDataTable()
Dim noOfRows As Integer = extractedData.Rows.Count
If noOfRows = 0 OrElse noOfRows > extractedData.Rows.Count Then
noOfRows = extractedData.Rows.Count
End If
Dim catIndex As Integer = 1
chart.ChartDataTable.Format.Equals(noOfRows)
Dim fact As ChartDataCellFactory = chart.ChartData.ChartDataCellFactory
Dim series As ChartSeriesEx = chart.ChartData.Series(0)
'series.Values.Add(fact.GetCell(0, noOfRows, 0, "test"));
'series.Values.Add(fact.GetCell(0, noOfRows, 1, 0));
If chart.ChartData.Categories.Count < noOfRows Then
Dim valuesToAdd As Integer = noOfRows - chart.ChartData.Categories.Count
Dim indToAdd As Integer = noOfRows
Do While indToAdd > chart.ChartData.Categories.Count
chart.ChartData.Categories.Add(fact.GetCell(0, indToAdd, 0, 0))
' series.Values.Add(fact.GetCell(0, indToAdd, 0, 0));
indToAdd -= 1
Loop
End If
If series.Values.Count < noOfRows Then
Dim valuesToAdd As Integer = noOfRows - series.Values.Count
For i As Integer = 0 To valuesToAdd - 1
series.Values.Add(fact.GetCell(0, noOfRows, 1, 0))
Next i
End If
For i As Integer = 0 To noOfRows - 1
Dim insertedValue As String = extractedData.Rows(i)("Value").ToString()
Dim catName As String = extractedData.Rows(i)("CatName").ToString() '.Split('[', ']');
Dim cat As String = catName
If insertedValue.Equals("-") OrElse insertedValue.Equals("") Then
insertedValue = "0"
End If
fact.GetCell(0, catIndex, 0, cat)
catIndex += 1
fact.GetCell(0, 0, 1, "Index")
series.Values(i).Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero)
Next i
pres.Save(path & "GenPres.pptx", Aspose.Slides.Export.SaveFormat.Pptx)
End Sub