Setting NumberFormat for ChartDataLabel

In .NET i’m able to set the NumberFormat for a ChartDataTabel with the below code

dataLabelCollection[j].NumberFormat.FormatCode = "0.0000";

However, this doesn’t seem to have any effect on my chart. I’ve also tried “0.00%” and couple other suggestions from your documentation here ChartNumberFormat.FormatCode | Aspose.Words for .NET

Can someone advise if this is working?

@dlepre,

Please try running the following code. Hope, this helps.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add chart with default data.
Shape shape = builder.InsertChart(ChartType.Line, 432, 252);
Chart chart = shape.Chart;
chart.Title.Text = "Data Labels With Different Number Format";

// Delete default generated series.
chart.Series.Clear();

// Add new series
ChartSeries series0 = chart.Series.Add("AW Series 0", new string[] { "AW0", "AW1", "AW2" }, new double[] { 2.5, 1.5, 3.5 });

// Add DataLabel to the first point of the first series.
ChartDataLabel chartDataLabel0 = series0.DataLabels.Add(0);
chartDataLabel0.ShowValue = true;

// Set currency format code.
chartDataLabel0.NumberFormat.FormatCode = "\"$\"#,##0.00";

ChartDataLabel chartDataLabel1 = series0.DataLabels.Add(1);
chartDataLabel1.ShowValue = true;

// Set date format code.
chartDataLabel1.NumberFormat.FormatCode = "d/mm/yyyy";

ChartDataLabel chartDataLabel2 = series0.DataLabels.Add(2);
chartDataLabel2.ShowValue = true;

// Set percentage format code.
chartDataLabel2.NumberFormat.FormatCode = "0.0000";
chartDataLabel2.ShowValue = true;

doc.Save(MyDir + @"18.3.docx");

This didn’t seem to work. I’m running this code and seeing no difference in the format.
I’ll mention I’m modifying an existing chart not creating a new one.

               for (int i = 0; i < posDS.Series.Count; i++)
               {
                   //Add the series and data points to the chart
                   double[] vals = Array.ConvertAll<object, double>(posDS.Data[i].ItemArray, x => (double)x);
                   ChartSeries series = s.Chart.Series.Add(posDS.Series[i].SeriesName, categories, vals);

                    s.Chart.AxisY.CategoryType = AxisCategoryType.Category;
                

                   for (int j = 0; j < categories.Count(); j++)
                   {
                       ChartDataLabel chartDataLabel = series.DataLabels.Add(j);
                       chartDataLabel.NumberFormat.FormatCode = "\"$\"#,##0.00";
                       chartDataLabel.ShowValue = true;
                       chartDataLabel.ShowCategoryName = false;
                       chartDataLabel.ShowLegendKey = false;
                       chartDataLabel.ShowSeriesName = false

                   }

               }

@dlepre,

Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your input Word document
  • Aspose.Words generated output DOCX file showing the undesired behavior
  • Your expected document. Please create this document by using MS Word
  • Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.