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.

Thu Feb 03, 2022 1:57 pm

Hi,
I want to remove a chart's data format at slide .Template.pptx slide index 3. ( Sample pptx file: https://docs.google.com/presentation/d/ ... ue&sd=true )


Data Behind Chart
02.png


It should look like:

Data
03.png


Slide
04.png

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Fri Feb 04, 2022 12:29 pm

Hi,

Thanks for your inquiry.
Sorry I can't download your template file from the link. According to your description, I think what you want is to change the number format of datalabel, please try the following code to achieve your need. If there is any question, please send your template to our email (support@e-iceblue.com) for a better investigation.
Code: Select all
            IChart chart = presentation.Slides[0].Shapes[0] as IChart;
            chart.Series[0].DataLabels.LabelValueVisible = true;
            chart.Series[0].DataLabels.PercentValueVisible = false;
            chart.Series[0].DataLabels.NumberFormat = "#,##0.00";
            chart.Series[0].DataLabels.HasDataSource = false;

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Mon Feb 07, 2022 7:59 am

Hi,
Thank you for your reply. It works fine for this "#,##0.00" format. But when I click the edit data button data is viewed in a percentage format. I don't want also data formating.

Also, I don't want to give any number format or any other format. How can I do that?

05.png

Because we have added an additional row (sixth row) it doesn't have data formatting. I want this behavior for all data.

I sent the template file via email.

Thank you.

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Mon Feb 07, 2022 9:24 am

Hi Omur,

Thanks for your sharing.
Sorry for the fact that our Spire.Presentation cannot change the number format of chart datasource at present. It will be considered as a new feature for our upgrade list, if a plan to achieve it has been made, I will inform you immediately.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Mon Feb 07, 2022 10:04 am

Thank you, Nina. I'm willing to hear the upgraded version.

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Mon Feb 28, 2022 10:09 am

Hi,

Thanks for your patient waiting.
We just released the Spire.Presentation Pack Hotfix Version:7.2.5 which supports changing the number format of chart datasource. Please download the hotfix from the link below and try the following code.
Website download link: https://www.e-iceblue.com/Download/download-presentation-for-net-now.html
Nuget download link: https://www.nuget.org/packages/Spire.Presentation/7.2.5
Sample code:
Code: Select all
 //Load a PowerPoint document
 Presentation ppt = new Presentation();
 ppt.LoadFromFile("template.pptx");
 //Get the third slide
 ISlide slide = ppt.Slides[2];
 //loop through shapes
 foreach (IShape shape in slide.Shapes)
 {
     //if the shape is chart
     if (shape is IChart)
     {
         IChart chart = shape as IChart;
         if (chart.Type.Equals(ChartType.BarClustered))
         {
             for (int i = 0; i < 5; i++)
             {
                 //change numberformat of chart datasource
                 chart.ChartData[i, 1].NumberFormat = "#,##0.00";

                 //change numberformat of chart datalabel
                 chart.Series[0].DataLabels.LabelValueVisible = true;
                 chart.Series[0].DataLabels.PercentValueVisible = false;
                 chart.Series[0].DataLabels.NumberFormat = "#,##0.00";
                 chart.Series[0].DataLabels.HasDataSource = false;
             }
         }
     }
 }
 ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Fri Mar 04, 2022 8:29 am

Thank you, Nina.

Can I also remove the chart data number format from the following code? I want to remove data formating.

Code: Select all
chart.ChartData[i, 1].NumberFormat = "#,##0.00";


Thank you.

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Fri Mar 04, 2022 9:19 am

Hello,

Thank you for your inquiry.
Please use the following code to remove data formatting.
Code: Select all
chart.ChartData[i, 1].NumberFormat = "G/ General";

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Sat Mar 05, 2022 8:35 am

Thank you Annika,

I can't compile my code. It views an exception at the following line.

Code: Select all
chart.ChartData[i, 1].NumberFormat = "G/ General";


01.jpg


Sample Template File:
template-chart-data-label.zip


Source Code:

Code: Select all
using Spire.Presentation;
using System.Linq;
using Spire.Presentation.Charts;
using System;

namespace PptxTesterPaidVersion
{
    class Program
    {
        static void Main(string[] args)
        {
            TestChartDataLabels();
        }

        private static void TestChartDataLabels()
        {
            //Load template presentation
            Presentation templatePresentation = new Presentation();
            templatePresentation.LoadFromFile("template-chart-data-label.pptx");

            //Create New Presentation
            Spire.Presentation.Presentation presentation = new Spire.Presentation.Presentation();
            presentation.Slides.RemoveAt(0);

            //Get slide from template presentation. index:1
            ISlide cloneSlide = templatePresentation.Slides.ToArray().ElementAtOrDefault(0);

            //---
            //Get Chart                       
            IChart chart = cloneSlide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 20") as IChart;

            if (chart.Type.Equals(ChartType.BarClustered))
            {
                for (int i = 0; i < 5; i++)
                {
                    //change numberformat of chart datasource
                    chart.ChartData[i, 1].NumberFormat = "G/ General";

                    //change numberformat of chart datalabel
                    chart.Series[0].DataLabels.LabelValueVisible = true;
                    chart.Series[0].DataLabels.PercentValueVisible = false;
                    chart.Series[0].DataLabels.NumberFormat = "G/ General";
                    chart.Series[0].DataLabels.HasDataSource = false;
                }
            }

            int seriesCount = 1;
            int categoryCount = 2;

            chart.ChartData.Clear(0, 0, categoryCount + 1, seriesCount + 1);

            chart.ChartData[0, 1].Text = "Total";

            chart.ChartData[1, 0].Text = "Cat A";
            chart.ChartData[2, 0].Text = "Cat B";
            chart.ChartData[3, 0].Text = "Cat C";
            chart.ChartData[4, 0].Text = "Cat D";
            chart.ChartData[5, 0].Text = "Cat E";

            chart.ChartData[1, 1].NumberValue = 43.15;
            chart.ChartData[2, 1].NumberValue = 44.13;
            chart.ChartData[3, 1].NumberValue = 44.22;
            chart.ChartData[4, 1].NumberValue = 47.14;
            chart.ChartData[5, 1].NumberValue = 32.36;

            presentation.Slides.Append(cloneSlide);

            //Save and launch to view the PPTX document.
            presentation.SaveToFile("TestChartDataLabels_03.pptx", Spire.Presentation.FileFormat.Pptx2013);
        }

        public static string GetColumnName(int index)
        {
            const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var value = "";

            if (index >= letters.Length)
                value += letters[index / letters.Length - 1];

            value += letters[index % letters.Length];

            return value;
        }
    }
}

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Mon Mar 07, 2022 3:16 am

Hello,

Thanks for your feedback.
I tested your case, but didn't reproduce the issue you mentioned. I have attached my test project here, please download and test it on your side. If the issue still exists after testing, please provide your test environment(such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese)) for further investigation. Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Mar 07, 2022 8:54 am

It works. Thank you.
I forgot to upgrade Spire.Presentation 7.2.5.

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Mon Mar 07, 2022 8:58 am

Hello,

You are welcome.

If you encounter other issues related to our products in the future, please feel free to contact us.

Have a nice day!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Tue Apr 05, 2022 1:49 pm

Hello,
I also wonder to know that can I get the ChartData number format like the following code. It's not supported right now but would be very helpful.

Code: Select all
var numberFormat = chart.ChartData[j,1].NumberFormat;

omur.ertanis
 
Posts: 22
Joined: Mon Feb 21, 2022 6:49 am

Wed Apr 06, 2022 3:23 am

Hello,

Thank you for your inquiry.
I've added your request as a new feature with the ticket SPIREPPT-1905 to our upgrade list. Once it is available, I will let you know immediately.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Apr 06, 2022 10:50 am

Great! Thanks.

omur.ertanis
 
Posts: 22
Joined: Mon Feb 21, 2022 6:49 am

Return to Spire.Presentation