Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents from any .NET(C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Mon Mar 09, 2015 7:38 pm

I managed to pass the data to the chart, but I have the following problem.

I set up a pie chart that sometimes have 5 values, sometimes 3 or more and the graphic does not increase the amount of parts as my values.

The same applies to the bar graph.
- Created with 6 bars in powerpoint, but sometimes pass 5 values, sometimes 8 points, to step over it does not show in the graph, if the graph is less step with the values that we set up originally in columns that I have not spent the value .

Do you have any tips or example for this?

Sorry my English is not good

psuporte
 
Posts: 6
Joined: Fri Mar 06, 2015 4:57 pm

Tue Mar 10, 2015 8:57 am

Hello,

Thanks for your inquiry.
Can you please provide the detailed information(output document and codes) about the scenario you mentioned?

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Wed Mar 11, 2015 9:33 am

Hello,

Has your issue been resolved? Could you please share your output document and codes? Could you give me some feedback?

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Wed Mar 11, 2015 2:40 pm

Hello,

I want to design the ppt with 2 charts, only I will pass an xml to them that may have more or less you will be the original design.

In the example the original ppt has:
1) bar graph with 8 series
2) Graphical pizza with 2 series

Step one xml with 6 series for the two graphs:
1) bar graph - the test he continues with 8 series
2) Pie Chart - the test he continues with two series

What I need is to know add / decrease you will be on the graph as the amount of xml items.

I attached the examples

Best Regards,
Cassio
Brazil
You do not have the required permissions to view the files attached to this post.

psuporte
 
Posts: 6
Joined: Fri Mar 06, 2015 4:57 pm

Thu Mar 12, 2015 9:41 am

Hello,

Thanks for sharing.
Could you share the test document("C:\Teste.pptx") in the code you provided for our testing? It would be helpful to reproduce the issue and work out the solution for you ASAP.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Thu Mar 12, 2015 12:01 pm

I have attached the ppt
You do not have the required permissions to view the files attached to this post.

psuporte
 
Posts: 6
Joined: Fri Mar 06, 2015 4:57 pm

Fri Mar 13, 2015 10:38 am

Hello,

Thanks the information, we will investigate it and update to you ASAP.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Mon Mar 16, 2015 8:55 am

Hello,

Sorry for late reply as weekend.
You can try the following codes:
Code: Select all
Sub Main(ByVal args As String())
        Dim ppt As New Spire.Presentation.Presentation("..\teste.pptx", Spire.Presentation.FileFormat.Pptx2010)
        Dim chart As IChart = TryCast(ppt.Slides(0).Shapes(0), IChart)
        Dim dataTable As DataTable = LoadData()
        InitChartData(chart, dataTable)
        ppt.SaveToFile("SS4559.pptx", Spire.Presentation.FileFormat.Pptx2010)
        System.Diagnostics.Process.Start("SS4559.pptx")

    End Sub
    'function to load data from XML file to DataTable
    Private Function LoadData() As DataTable
        Dim ds As New DataSet()
        ds.ReadXmlSchema("D:\spire.office\Demos\PresentationDemos\Data\data-schema.xml")
        ds.ReadXml("F:\testing\4559\data.xml")
        Return ds.Tables(0)
    End Function

    'function to load data from DataTable to IChart
    Private Sub InitChartData(ByVal chart As Spire.Presentation.Charts.IChart, ByVal dataTable As DataTable)
        For c As Integer = 0 To dataTable.Columns.Count - 1

            chart.ChartData(0, c).Text = dataTable.Columns(c).Caption
        Next
        For r As Integer = 0 To dataTable.Rows.Count - 1
            Dim data As Object() = dataTable.Rows(r).ItemArray
            For c As Integer = 0 To data.Length - 1
                chart.ChartData(r + 1, c).Value = data(c)
            Next
        Next
        Dim newDataCountIndex As Integer = dataTable.Rows.Count
        Dim originalDataCountIndex As Integer = chart.Categories.Count
        If newDataCountIndex < originalDataCountIndex Then
            'remove redundant data
            chart.ChartData.Clear(newDataCountIndex + 1, 0, originalDataCountIndex + 1, dataTable.Columns.Count)
            'remove redundant categories
            For i As Integer = originalDataCountIndex To newDataCountIndex + 1 Step -1
                chart.Categories.RemoveAt(i - 1)
            Next
        ElseIf newDataCountIndex > originalDataCountIndex Then
            'add categories for the beyond data
            For i As Integer = originalDataCountIndex To newDataCountIndex - 1
                chart.Categories.Append(chart.ChartData(i + 1, 0).Value)
            Next
        End If
        'reset series
        For i As Integer = 0 To chart.Series.Count - 1
            chart.Series(i).Values = chart.ChartData(1, i + 1, newDataCountIndex, i + 1)
        Next
    End Sub

If there are any questions, welcome to get it back to us.
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Mon Mar 16, 2015 12:05 pm

It worked

Thank you.

psuporte
 
Posts: 6
Joined: Fri Mar 06, 2015 4:57 pm

Tue Mar 17, 2015 1:52 am

Hello,

Please feel free to contact us if you have any questions or needs. We are here for help.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 804
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Presentation