Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Fri Jul 13, 2018 9:02 am

Hello!
I have some issues about Plot Area Align.
The problem is that input ppt template have normal alignment(Input.jpg), but output ppt have different one(Output.jpg).
I tried to play with Chart.PlotArea.Left property, but it didn't help.
Can you advise me anything?
Maybe there are other ways to control Plot Area alignment?
If you know possible reasons why it happens it would be useful too.

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Fri Jul 13, 2018 9:29 am

Dear rokaf,

Thanks for your inquiry.
I just loaded your file and then saved with the Spire.Office Platinum (DLL Only) Version:3.6.0, but didn't find the issue you mentioned, the result file was correct. Below is my testing code:
Code: Select all
            Presentation ppt = new Presentation(@"F:\Input.pptx", Spire.Presentation.FileFormat.Pptx2013);
            ppt.SaveToFile("14396.pptx", Spire.Presentation.FileFormat.Pptx2013);

I noticed your output file had other slide which was not existed in input file. There should be other operation for your original file. Could please share us the full code you were using so that we could reproduce your issue on our side ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jul 18, 2018 8:35 am

Dear rokaf,

How is your issue going now ?
Could you please give us some feedback at your convenience ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jul 18, 2018 1:12 pm

Hello!
I've created Console App to show you how it works, so here is my code:
Code: Select all
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation(@"D:\Input.pptx", Spire.Presentation.FileFormat.Pptx2013);
            var list = new List<List<object>>
            {
                new List<object>
                {
                    0
                },
                new List<object>
                {
                    -164.329663115674
                },
                new List<object>
                {
                    -114.319358389203
                },
                new List<object>
                {
                    -264.350675455229
                },
                new List<object>
                {
                    10146.6111100013
                },
                new List<object>
                {
                    5220.46062032565
                },
            };
     

            var chart = ppt.Slides[0].Shapes[2] as IChart;
     
            InitChartData(chart,list);
            var seriesCount = list.Count/2;

            chart.Series.SeriesLabel = chart.ChartData[0, 0, 0, seriesCount - 1];
            for (int i = 0; i < seriesCount ; i++)
            {
                chart.Series[i].YValues = chart.ChartData[1, i, list[i].Count, i];
                chart.Series[i].XValues = chart.ChartData[1, seriesCount + i, list[i].Count, seriesCount + i];
            }

            BuildAxisX(chart);
            BuildAxisY(chart);

            ppt.SaveToFile("14396.pptx", Spire.Presentation.FileFormat.Pptx2013);
            Process.Start("14396.pptx");

            Console.ReadKey();
        }

        private static void InitChartData(IChart chart, List<List<object>> dataTable)
        {
            int seriesCount = dataTable.Count / 2;

            for (int c = 0; c < seriesCount; c++)
            {
                chart.ChartData[0, c].Text = c.ToString();
            }

            for (int r = 0; r < dataTable.Count; r++)
            {
                for (int c = 0; c < dataTable[r].Count; c++)
                {
                    chart.ChartData[c+1, r].Value = dataTable[r][c];
                }
            }
        }

        private static void BuildAxisX(IChart Chart)
        {
           
            Chart.PrimaryValueAxis.IsAutoMajor = false;
            Chart.PrimaryValueAxis.IsAutoMinor = false;
            Chart.PrimaryValueAxis.MajorUnit = 1500;
            Chart.PrimaryValueAxis.MinorUnit = 150;

            Chart.PrimaryValueAxis.IsAutoMax = false;
            Chart.PrimaryValueAxis.IsAutoMin = false;

            Chart.PrimaryValueAxis.MaxValue = 20069.770808224304f;
            Chart.PrimaryValueAxis.MinValue = -10500;
        }

        private static void BuildAxisY(IChart Chart)
        {
            Chart.SecondaryValueAxis.IsAutoMajor = false;
            Chart.SecondaryValueAxis.IsAutoMinor = false;
            Chart.SecondaryValueAxis.MajorUnit = 1500;
            Chart.SecondaryValueAxis.MinorUnit = 150;

            Chart.SecondaryValueAxis.IsAutoMax = false;
            Chart.SecondaryValueAxis.IsAutoMin = false;

            Chart.SecondaryValueAxis.MaxValue = 10500;
            Chart.SecondaryValueAxis.MinValue = -1500;
        }

    }


In the output ppt Plot Area have different alignment.


Betsy.jiang wrote:Dear rokaf,

How is your issue going now ?
Could you please give us some feedback at your convenience ?

Sincerely,
Betsy
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Thu Jul 19, 2018 8:35 am

Dear rokaf,

Thank you for your details.
After investigation, I’m afraid the case is not a problem. This is the standard of MS PowerPoint, even if you try the same operation in PowerPoint, the result is the same as that of Spire.Presentation. Since Spire.Presentation is totally based on the standard of MS PowerPoint, I’m sorry that there’s no solution available. Attached the output from PowerPoint for checking.
Sincerely,
Hogan
E-iceblue support team
User avatar

hogan.tang
 
Posts: 51
Joined: Tue Jul 03, 2018 1:43 am

Fri Jul 20, 2018 8:18 am

Okay. so how can I get round it?
I need to save basic alignment, what I have to do for it?

hogan.tang wrote:Dear rokaf,

Thank you for your details.
After investigation, I’m afraid the case is not a problem. This is the standard of MS PowerPoint, even if you try the same operation in PowerPoint, the result is the same as that of Spire.Presentation. Since Spire.Presentation is totally based on the standard of MS PowerPoint, I’m sorry that there’s no solution available. Attached the output from PowerPoint for checking.

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Fri Jul 20, 2018 10:06 am

Dear rokaf,

Thanks for your response.
After further investigation, I find there is a solution, that is, adjusting the width of the chart. Then the position of the chart will be changed. Please try to use following code.
Code: Select all
chart.Width = 1924;

Hope it helps.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Jul 23, 2018 7:48 am

Can you explain the way you think?
Because it will work in special cases, but I need to get universal solution.
Result width is 1867.40051, how did you figure out that it must be 1924?

Betsy.jiang wrote:Dear rokaf,

Thanks for your response.
After further investigation, I find there is a solution, that is, adjusting the width of the chart. Then the position of the chart will be changed. Please try to use following code.
Code: Select all
chart.Width = 1924;

Hope it helps.

Sincerely,
Betsy
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Mon Jul 23, 2018 9:54 am

Dear rokaf,

Sorry that the solution is not universal.
As for the issue, I find there is another solution, you need to get the position of the table above the chart first, then count the position of the chart. Please refer to below code:
Code: Select all
            BuildAxisX(chart);
            BuildAxisY(chart);

            //get the table position
            var table = ppt.Slides[0].Shapes[3];
            var left = ppt.Slides[0].Shapes[3].Left;
            var tableRight = table.Width + left;

            var leftChange = ppt.Slides[0].Shapes[2].Left;
            var PAleft = chart.PlotArea.Left;
            var adjust = tableRight - PAleft - leftChange;
            //set the chart width first and it must be larger than the value chart.PlotArea.Width
            chart.Width = tableRight - chart.Left + 50;
            //adjust the width of plot area
            chart.PlotArea.Width = adjust;

Looking forward to your feedback.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Jul 24, 2018 8:12 am

Unfortunately, this solution works only in special cases.
Moreover it adds new bugs(DataLabels and table go right).

Betsy.jiang wrote:Dear rokaf,

Sorry that the solution is not universal.
As for the issue, I find there is another solution, you need to get the position of the table above the chart first, then count the position of the chart. Please refer to below code:
Code: Select all
            BuildAxisX(chart);
            BuildAxisY(chart);

            //get the table position
            var table = ppt.Slides[0].Shapes[3];
            var left = ppt.Slides[0].Shapes[3].Left;
            var tableRight = table.Width + left;

            var leftChange = ppt.Slides[0].Shapes[2].Left;
            var PAleft = chart.PlotArea.Left;
            var adjust = tableRight - PAleft - leftChange;
            //set the chart width first and it must be larger than the value chart.PlotArea.Width
            chart.Width = tableRight - chart.Left + 50;
            //adjust the width of plot area
            chart.PlotArea.Width = adjust;

Looking forward to your feedback.

Sincerely,
Betsy
E-iceblue support team

rokaf
 
Posts: 37
Joined: Thu May 10, 2018 9:30 am

Tue Jul 24, 2018 9:12 am

Dear rokaf,

Sorry to hear that.
Our Spire.Presentation follows MS PowerPoint standard, we first need to investigate if your requirement could be achieved by MS PowerPoint. According to the picture you provide, there should be other operations which you do not mention. Kindly note that every line might effect the result, if you add some new content in code, please share the full code and expected file you want, only then can we look into it and provide the solution. In addition, we also need the input file if it is different from the previous one.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jul 27, 2018 9:30 am

Dear rokaf,

Greetings from E-iceblue.
How is your issue going now ? Could you please give us some feedback at your convenience ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Presentation