We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Apply custom format to data label locale wise

I want to format data labels of y axis according to locale. For example, in German number format comma is used as a decimal separator and dot (.) is used as a thousand separator whereas in US format, it’s totally opposite. How can i achieve this with custom formatting? What format should be applied?

@wajiha You can use the following format code for Axis labels #,##0.0. However, you should note that MS Word uses the current locale too format the values in the charts. For example the following code:

CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");

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

Chart chart = builder.InsertChart(ChartType.Line, 300, 300).Chart;
chart.Series.Add("My fruit",
    new[] { "Apples", "Bananas", "Cherries" },
    new[] { 12345678.123, 98765432.9876, 56473829.494 });

chart.AxisY.NumberFormat.FormatCode = @"#,##0.0";

doc.Save(@"C:\temp\out.docx");
doc.Save(@"C:\temp\out.pdf");

Thread.CurrentThread.CurrentCulture = currentCulture;

As you can see CurrentThread.CurrentCulture is specified to de-DE this makes Aspose.Words to use de-DE culture upon formatting values in the chart upon rendering document to PDF. Here are the output documents produced on my side:out.docx (8.8 KB)
out.pdf (20.2 KB)

@alexey.noskov can i specify currency symbol too? Also i want to add ‘K’ to represent a thousand value. Is it possible to add this in format?

@alexey.noskov i’m unable to set Thread.CurrentThread.CurrentCulture as i’m using java. I’ve tried by setting default locale like this Locale.setDefault(new Locale(“de”, “DE”)) but no luck!

@wajiha You can use CurrentThreadSettings class to set locale in Java. Also, you can use number format like this to use ‘K’ to represent a thousand value "#,##0,\"K\"". For example see the following code:

Locale currentCulture = CurrentThreadSettings.getLocale();
CurrentThreadSettings.setLocale(Locale.GERMANY);

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

Chart chart = builder.insertChart(ChartType.LINE, 300, 300).getChart();
chart.getSeries().add("My fruit",
      new String[] { "Apples", "Bananas", "Cherries" },
new double[] { 123467.123, 987643.9876, 564382.494 });

chart.getAxisY().getNumberFormat().setFormatCode("#,##0,\"K\"");

doc.save("C:\\temp\\out.docx");
doc.save("C:\\temp\\out.pdf");

CurrentThreadSettings.setLocale(currentCulture);

Thank you so much @alexey.noskov. It works. :slight_smile: