Chart data label number formatting

Technical support for Presentation

Moderator: iceblue support

Chart data label number formatting

Postby Archigo » Tue Jun 20, 2017 2:20 pm

Hello

I have some chart in a power point template. These charts have data-labels that are formatted "#.##0", to achieve thousand separation on numbers.

Image

This formatting disappears once i insert data into the chart. Therefore, i have saved the data-labels before i edit the data, and then reinsert the formatting after I'm done editing data:

Saving before formatting is lost:
Code: Select all
private static List<SeriesInformation> SaveSeriesFormatting(IChart iChart)
        {
            var seriesFormats = new List<SeriesInformation>();

            foreach (ChartSeriesDataFormat serie in iChart?.Series)
            {
                seriesFormats.Add(
                    new SeriesInformation(
                        serie.Fill.FillType,
                        serie.Fill.Pattern.BackgroundColor.Color,
                        serie.Fill.Pattern.ForegroundColor.Color,
                        serie.Fill.Pattern.PatternType,
                        serie.DataPoints,
                        serie.DataLabels,
                        serie.Distance));
            }
            return seriesFormats;
        }


Inserting formatting after data has been edited:
Code: Select all
private static void ApplySeriesFormatting(List<SeriesInformation> seriesFormats, IChart chart)
        {
            var defaultSeriesFormat = seriesFormats[0];
            for (int index = 0; index < chart.Series.Count; index++)
            {
                var seriesFormat = index < seriesFormats.Count ? seriesFormats[index] : defaultSeriesFormat;

                // explode pie charts
                chart.Series[index].Distance = seriesFormat.Distance;

                // reinsert datalabels
                var dataLabel = seriesFormat.DataLabels;

                var chartDataLabel = chart.Series[index].DataLabels;

                chartDataLabel.Fill.FillType = dataLabel.Fill.FillType;
                chartDataLabel.Fill.SolidColor.Color = dataLabel.Fill.SolidColor.Color;
               
                chartDataLabel.TextProperties.Paragraphs[0].DefaultCharacterProperties.Format.FontHeight =
                    dataLabel.TextProperties.Paragraphs[0].DefaultCharacterProperties.Format.FontHeight;
               
                chartDataLabel.CategoryNameVisible = dataLabel.CategoryNameVisible;
                chartDataLabel.BubbleSizeVisible = dataLabel.BubbleSizeVisible;
                chartDataLabel.LabelValueVisible = dataLabel.LabelValueVisible;
                chartDataLabel.LegendKeyVisible = dataLabel.LegendKeyVisible;
                chartDataLabel.PercentValueVisible = dataLabel.PercentValueVisible;
                chartDataLabel.SeriesNameVisible = dataLabel.SeriesNameVisible;
                chartDataLabel.LeaderLinesVisible = dataLabel.LeaderLinesVisible;
                chartDataLabel.NumberFormat = dataLabel.NumberFormat;
               

                if ((int) dataLabel.Position != -1) chartDataLabel.Position = dataLabel.Position;       
            }
        }


This code works except for number formatting. I can see that the actual number formatting that i want is saved and applied in these two methods, but when i look in the power point, the numbers are not formatted.

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

Re: Chart data label number formatting

Postby Jane.Bai » Wed Jun 21, 2017 4:28 am

Hello,

Thanks for your inquiry.
After an initial test using the latest version(Spire.Presentation Pack Hotfix Version:2.8.10), I could get the correct number format. Attached are my testing code as well as sample original and result files. Please check it. Besides, if there's still any doubt or issue, welcome to write back and share your sample files with us.

Sincerely,
Jane
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar
Jane.Bai
 
Posts: 348
Joined: Tue Nov 29, 2016 1:47 am

Re: Chart data label number formatting

Postby Archigo » Wed Jun 21, 2017 7:41 am

In your example you are not adding a new series. I have uploaded an edited version of your example, where my issue is present.
You do not have the required permissions to view the files attached to this post.
Archigo
 
Posts: 15
Joined: Tue Apr 11, 2017 2:00 pm

Re: Chart data label number formatting

Postby Jane.Bai » Wed Jun 21, 2017 9:26 am

Hello,

Thanks for your reply.
I have noticed the issue and referred it to our dev team for a further investigation. Once there's any progress, I will inform you.
Sorry for the inconvenience caused.

Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 348
Joined: Tue Nov 29, 2016 1:47 am

Re: Chart data label number formatting

Postby Archigo » Thu Jun 29, 2017 8:32 pm

My issue might be a non issue, if I could find a property to set the formatting type (standard, number, percent, date etc.) of a series. As it is, I have been unable to find a way to set this programmatically.
Because of this, it is always "standard", which does not use the formatting string, and as such it is always ignored.
Archigo
 
Posts: 15
Joined: Tue Apr 11, 2017 2:00 pm

Re: Chart data label number formatting

Postby Jane.Bai » Fri Jun 30, 2017 2:38 am

Hello,

Thanks for your post.
After an investigation, we found the number formatting is controlled by both the format you set and the property "HasDataSource".
So, you just need to add this line in your "ApplySeriesFormatting" function to get what you want.
Code: Select all
chartDataLabel.HasDataSource = dataLabel.HasDataSource;

So sorry for the inconvenience caused.

Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 348
Joined: Tue Nov 29, 2016 1:47 am

Re: Chart data label number formatting

Postby Archigo » Fri Jul 07, 2017 8:41 am

Thank you, this solved the issue for me.

Adding this to the tutorial for data labels would be nice :)
Archigo
 
Posts: 15
Joined: Tue Apr 11, 2017 2:00 pm

Re: Chart data label number formatting

Postby Jane.Bai » Mon Jul 10, 2017 1:29 am

Hello,

Thanks for your feedback. We will consider your suggestion.
Please feel free to contact us if you need any assistance.

Sincerely,
Jane
E-iceblue support team
User avatar
Jane.Bai
 
Posts: 348
Joined: Tue Nov 29, 2016 1:47 am


Return to Spire.Presentation

Who is online

Users browsing this forum: No registered users and 0 guests