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.

Tue Apr 18, 2017 10:01 am

Hello

I'm using spire to insert data into some powerpoint charts. The datainsertion part works fine, but I'm formatting the columns in my chart like this:
Image
As we can see in the image above, i have a center column with a solid fill, and all the other columns with a pattern. The issue is that after inserting data into the chart and saving it looks like this:
Image

There's basicly two things wrong here:
- The formatting on the columns is gone, they are now all using a solid fill, and the parttern from before is gone.
- The series are now red and green instead of blue and red.

Question 1: How can I preserve the pattern formatting of the columns?

Question 2: How can I preserve the series coloring, so it is still blue and red?

Test project producing the above descibed results

Archigo
 
Posts: 21
Joined: Tue Apr 11, 2017 2:00 pm

Wed Apr 19, 2017 8:42 am

Dear Archigo,

Many thanks for your detailed information.
In your code, you reset the SeriesLabel/CategoryLabels for the chart in the method "FillChart" , hence it would reset some default settings.
To avoid the issues you mentioned, please get the settings of the original chart first, and then apply them to changed chart.
Code snippet for your kind reference.
Code: Select all
                ...
                Spire.Presentation.Presentation presentation = new Spire.Presentation.Presentation();
                presentation.LoadFromFile(diag.FileName);
                IChart chart = presentation.Slides[0].Shapes[0] as IChart;

                //the setting of series 1
                FillFormatType Series1Type = chart.Series[0].Fill.FillType;
                Color Series1BColor = chart.Series[0].Fill.Pattern.BackgroundColor.Color;
                Color Series1FColor = chart.Series[0].Fill.Pattern.ForegroundColor.Color;
                PatternFillType Series1Pat =  chart.Series[0].Fill.Pattern.PatternType;
               
                FillFormatType Series1DT = chart.Series[0].DataPoints[0].Fill.FillType;
                Color Series1DC = chart.Series[0].DataPoints[0].Fill.SolidColor.Color;
                int DP1 = chart.Series[0].DataPoints[0].Index;

                //the setting of series 2
                FillFormatType Series2Type = chart.Series[1].Fill.FillType;
                Color Series2BColor = chart.Series[1].Fill.Pattern.BackgroundColor.Color;
                Color Series2FColor = chart.Series[1].Fill.Pattern.ForegroundColor.Color;
                PatternFillType Series2Pat = chart.Series[1].Fill.Pattern.PatternType;

                FillFormatType Series2DT = chart.Series[1].DataPoints[0].Fill.FillType;
                Color Series2DC = chart.Series[1].DataPoints[0].Fill.SolidColor.Color;
                int DP2 = chart.Series[1].DataPoints[0].Index;

                var data = new List<List<string>>
                {
                    new List<string> { "", "some1", "some2"},
                    new List<string> { "-3,00%", "5", "1" },
                    new List<string> { "-2,5%", "4,5", "0,9" },
                    new List<string> { "-2%", "4", "0,8" },
                    new List<string> { "-1.5%", "3,5", "0,7" },
                    new List<string> { "-1%", "3", "0,6" },
                    new List<string> { "-0.5%", "2,5", "0,5" },
                    new List<string> { "0%", "2", "0,4" },
                    new List<string> { "0.5%", "1,5", "0,3" },
                    new List<string> { "1%", "1", "0,2" },
                    new List<string> { "1.5%", "1", "0,1" },
                    new List<string> { "2%", "1", "0,1" },
                    new List<string> { "2.5%", "0,5", "0,1" },
                    new List<string> { "3%", "0,5", "0" },
                    new List<string> { "3%", "0,5", "0" }
                };

                FillChart(presentation.Slides[0].Shapes[0] as IChart, data);
               
                IChart chartChanged = presentation.Slides[0].Shapes[0] as IChart;
                //reset the setting of series 1
                chartChanged.Series[0].Fill.FillType = Series1Type;
                chartChanged.Series[0].Fill.Pattern.BackgroundColor.Color = Series1BColor;
                chartChanged.Series[0].Fill.Pattern.ForegroundColor.Color = Series1FColor;
                chartChanged.Series[0].Fill.Pattern.PatternType = Series1Pat;

                ChartDataPoint cdp1 = new ChartDataPoint(chartChanged.Series[0]);
                cdp1.Index = DP1;
                cdp1.Fill.FillType = Series1DT;
                cdp1.Fill.SolidColor.Color = Series1DC;
                chartChanged.Series[0].DataPoints.Add(cdp1);

                //reset the setting of series 2
                chartChanged.Series[1].Fill.FillType = Series2Type;
                chartChanged.Series[1].Fill.Pattern.BackgroundColor.Color = Series2BColor;
                chartChanged.Series[1].Fill.Pattern.ForegroundColor.Color = Series2FColor;
                chartChanged.Series[1].Fill.Pattern.PatternType = Series2Pat;

                ChartDataPoint cdp2 = new ChartDataPoint(chartChanged.Series[1]);
                cdp2.Index = DP2;
                cdp2.Fill.FillType = Series2DT;
                cdp2.Fill.SolidColor.Color = Series2DC;
                chartChanged.Series[1].DataPoints.Add(cdp2);
                ...

Hope this can helps. If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Wed Apr 19, 2017 12:43 pm

Thank you for your reply. I was able to achieve what I want with inspiration from your code. I have however found an issue with this approach:

If you only have one series in the dataset, the chart will read the categories as series names.

if you remove

Code: Select all
//the setting of series 2
                FillFormatType Series2Type = chart.Series[1].Fill.FillType;
                Color Series2BColor = chart.Series[1].Fill.Pattern.BackgroundColor.Color;
                Color Series2FColor = chart.Series[1].Fill.Pattern.ForegroundColor.Color;
                PatternFillType Series2Pat = chart.Series[1].Fill.Pattern.PatternType;

                FillFormatType Series2DT = chart.Series[1].DataPoints[0].Fill.FillType;
                Color Series2DC = chart.Series[1].DataPoints[0].Fill.SolidColor.Color;
                int DP2 = chart.Series[1].DataPoints[0].Index;


and remove
Code: Select all
//reset the setting of series 2
                chartChanged.Series[1].Fill.FillType = Series2Type;
                chartChanged.Series[1].Fill.Pattern.BackgroundColor.Color = Series2BColor;
                chartChanged.Series[1].Fill.Pattern.ForegroundColor.Color = Series2FColor;
                chartChanged.Series[1].Fill.Pattern.PatternType = Series2Pat;

                ChartDataPoint cdp2 = new ChartDataPoint(chartChanged.Series[1]);
                cdp2.Index = DP2;
                cdp2.Fill.FillType = Series2DT;
                cdp2.Fill.SolidColor.Color = Series2DC;
                chartChanged.Series[1].DataPoints.Add(cdp2);


and then use this as data:
Code: Select all
var data = new List<List<string>>
                {
                    new List<string> { string.Empty, "some1" },
                    new List<string> { "-3,00%", "5" },
                    new List<string> { "-2,5%", "4,5" },
                    new List<string> { "-2%", "4" },
                    new List<string> { "-1.5%", "3,5" },
                    new List<string> { "-1%", "3" },
                    new List<string> { "-0.5%", "2,5" },
                    new List<string> { "0%", "2" },
                    new List<string> { "0.5%", "1,5" },
                    new List<string> { "1%", "1" },
                    new List<string> { "1.5%", "1" },
                    new List<string> { "2%", "1" },
                    new List<string> { "2.5%", "0,5" },
                    new List<string> { "3%", "0,5" },
                    new List<string> { "3%", "0,5" }
                };


you will get this:

Image

This seems to be an issue with how powerpoint is designed to interpret the names of legends, where it will switch to reading categories as legends, if there is only one data column.

There is no problem if I have more than one column of data.

Question: Is there any way around this, so that I would see one series named "some1"?

Archigo
 
Posts: 21
Joined: Tue Apr 11, 2017 2:00 pm

Thu Apr 20, 2017 7:28 am

Dear Archigo,

Thanks for your feedback.
I have noticed the issue and posted it to our Dev team, once there is any progress, we will inform you.
Sorry for inconvenience caused.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue Apr 25, 2017 8:56 am

Dear Archigo,

After investigation, we found the result generated by Spire.Presentaion was correct. In MS PowerPoint, if the chart only has one series and it has more than one kind of fill format for datapoints( The chart in your original file has two fill formats, one is Pattern fill, the another is Solid fill), then it will read categories as legends. And I attached the file generated by MS PowerPoint for checking.
So if there is only one series, to avoid the legend issue, we suggest commenting out the code I provided before as below.
Code: Select all
ChartDataPoint cdp1 = new ChartDataPoint(chartChanged.Series[0]);
cdp1.Index = DP1;
cdp1.Fill.FillType = Series1DT;
cdp1.Fill.SolidColor.Color = Series1DC;
chartChanged.Series[0].DataPoints.Add(cdp1);

Hope this helps. If you still have questions, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.Presentation