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 Mar 06, 2020 1:56 pm

Greetings, I am trying to change all the bars on the clustered chart to be purple instead of red. Also, how can I put the categories in descending order based on the value of the Value Axis?

dbrewerton-1
 
Posts: 7
Joined: Tue Mar 03, 2020 7:40 pm

Mon Mar 09, 2020 8:23 am

Hello,

Thanks for your inquiry.
Please try the following code to set the color of all the bars on the clustered chart to purple.
Code: Select all
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\test.pptx");
            ISlide slide = presentation.Slides[0];
         
            IChart chart = slide.Shapes[0] as IChart;
            for (int i = 0; i < chart.Series.Count; i++)
            {
                chart.Series[i].Fill.FillType = FillFormatType.Solid;
                chart.Series[i].Fill.SolidColor.Color = Color.Purple;
            }
            String result = "result.pptx";
            presentation.SaveToFile(result, FileFormat.Pptx2013);

Regarding another question(putting the categories in descending order based on the value of the Value Axis), I tried to find the settings on MS Powerpoint but unfortunately I couldn't find it. Could you please share a sample document to show what you want?
Thanks in advance for your assistance.


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Mon Mar 09, 2020 2:16 pm

Ok, the bar color setting is worked out, fantastic. The other question on the sort order, I'm enclosing two charts, one that shows the default order, the other showing the order I want. Thank you!

dbrewerton-1
 
Posts: 7
Joined: Tue Mar 03, 2020 7:40 pm

Mon Mar 09, 2020 3:49 pm

Greetings, I did figure it out to make the chart categories show in reverse order. This is the working code.
Code: Select all
                chart1.ChartTitle.TextProperties.IsCentered = false;
                chart1.ChartTitle.Height = 30;
                chart1.HasLegend = false;
                chart1.HasTitle = true;
                chart1.PrimaryCategoryAxis.IsReversed = true;
                chart1.PrimaryValueAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;
                chart1.PrimaryValueAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = 10;
                chart1.PrimaryValueAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont = new TextFont("Arial");
                chart1.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = 10;
                chart1.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont = new TextFont("Arial");

dbrewerton-1
 
Posts: 7
Joined: Tue Mar 03, 2020 7:40 pm

Tue Mar 10, 2020 2:23 am

Hello,

Thanks for your further details and sharing the working code.
Feel free to contact us if you have any issues.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Presentation

cron