Hi, we are using Aspose.slides for generating presentations. Currently we are using aspose.slides 17.7 version and planning to upgrade to 24.9 version
However while testing with the trail version for 24.9 , we observed that there is an issue with the way charts are rendered in the slides. Previously(with version 17.7) when the values provided in the excel for the chart are decimal then it used to render as % value, so if the value in excel is 0.8 then it would show as 80%, but with the new version of aspose(24.9), the decimal value is rendered as is, so 0.8 in excel is rendering as 0.8 in the chart.
Want to know what is causing this and how to fix this, this is one of the blocker for us to move forward with this new version of library
It seems that you are experiencing an issue with how charts are rendered in Aspose.Slides version 24.9 compared to version 17.7, specifically regarding the display of decimal values as percentages. In version 17.7, a value of 0.8 in Excel would be displayed as 80% in the chart, while in version 24.9, it is rendered as 0.8.
To address this issue, you can explicitly set the number format for the chart’s vertical axis and the data labels to display percentages. Here’s a code example that demonstrates how to achieve this:
C# Example
using System.Drawing;
using Aspose.Slides.Charts;
using Aspose.Slides.Export;
using Aspose.Slides;
public class SetDataLabelsPercentageSign
{
public static void Run()
{
// Create an instance of Presentation class
Presentation presentation = new Presentation();
ISlide slide = presentation.Slides[0];
// Add a PercentsStackedColumn chart on a slide
IChart chart = slide.Shapes.AddChart(ChartType.PercentsStackedColumn, 20, 20, 500, 400);
// Set NumberFormatLinkedToSource to false and define the number format
chart.Axes.VerticalAxis.IsNumberFormatLinkedToSource = false;
chart.Axes.VerticalAxis.NumberFormat = "0.00%";
chart.ChartData.Series.Clear();
int defaultWorksheetIndex = 0;
IChartDataWorkbook workbook = chart.ChartData.ChartDataWorkbook;
// Add new series and data points
IChartSeries series = chart.ChartData.Series.Add(workbook.GetCell(defaultWorksheetIndex, 0, 1, "Reds"), chart.Type);
series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 1, 1, 0.30));
series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 2, 1, 0.50));
series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 3, 1, 0.80));
series.DataPoints.AddDataPointForBarSeries(workbook.GetCell(defaultWorksheetIndex, 4, 1, 0.65));
// Set the label format properties
series.Labels.DefaultDataLabelFormat.ShowValue = true;
series.Labels.DefaultDataLabelFormat.IsNumberFormatLinkedToSource = false;
series.Labels.DefaultDataLabelFormat.NumberFormat = "0.0%";
// Save the presentation
presentation.Save("SetDataLabelsPercentageSign_out.pptx", SaveFormat.Pptx);
}
}
Java Example
package com.aspose.slides.examples.charts;
import com.aspose.slides.*;
import java.awt.*;
public class SetDataLabelsPercentageSign
{
public static void main(String[] args)
{
// Create an instance of Presentation class
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
// Add a PercentsStackedColumn chart on a slide
IChart chart = slide.getShapes().addChart(ChartType.PercentsStackedColumn, 20, 20, 500, 400);
// Set NumberFormatLinkedToSource to false and define the number format
chart.getAxes().getVerticalAxis().setNumberFormatLinkedToSource(false);
chart.getAxes().getVerticalAxis().setNumberFormat("0.00%");
chart.getChartData().getSeries().clear();
int defaultWorksheetIndex = 0;
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
// Add new series and data points
IChartSeries series = chart.getChartData().getSeries().add(workbook.getCell(defaultWorksheetIndex, 0, 1, "Reds"), chart.getType());
series.getDataPoints().addDataPointForBarSeries(workbook.getCell(defaultWorksheetIndex, 1, 1, 0.30));
series.getDataPoints().addDataPointForBarSeries(workbook.getCell(defaultWorksheetIndex, 2, 1, 0.50));
series.getDataPoints().addDataPointForBarSeries(workbook.getCell(defaultWorksheetIndex, 3, 1, 0.80));
series.getDataPoints().addDataPointForBarSeries(workbook.getCell(defaultWorksheetIndex, 4, 1, 0.65));
// Set the label format properties
series.getLabels().getDefaultDataLabelFormat().setShowValue(true);
series.getLabels().getDefaultDataLabelFormat().setNumberFormatLinkedToSource(false);
series.getLabels().getDefaultDataLabelFormat().setNumberFormat("0.0%");
// Save the presentation
presentation.save("SetDataLabelsPercentageSign_out.pptx", SaveFormat.Pptx);
}
}
By setting the NumberFormat
for both the vertical axis and the data labels, you should be able to display the decimal values as percentages in the new version of Aspose.Slides. If you continue to experience issues, please ensure that you are using the latest version of the library and check the documentation for any additional changes that may affect chart rendering.
Sources:
[1]: SetDataLabelsPercentageSign.cs
[2]: SetDataLabelsPercentageSign.java