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

Free Support Forum - aspose.com

Y-axis formatted scale

Is it possible to format y-axis scale values for e.g: to represent 12,000 as 12K, 12,000,000 as 12M.
without changing the actual data in series that’s used for plotting chart.

@wajiha You can use AxisDisplayUnit.Unit property to achieve this. For example see the following code:

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

Shape shape = builder.insertChart(ChartType.SCATTER, 450.0, 250.0);
Chart chart = shape.getChart();

ChartAxis axis = chart.getAxisY();

// Set the tick labels to display their value in millions.
axis.getDisplayUnit().setUnit(AxisBuiltInUnit.MILLIONS);

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

Or you can specify an appropriate format code for axis labels:

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

@alexey.noskov yeah you’re right but my data is dynamic, it could be in hundreds, thousands, millions etc. In short, it could be anything. In this case what would you suggest.

@wajiha You can try using conditional number format like in the code example below:

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("[>=1000000]#,##0,,\"M\";[>=1000]#,##0,\"K\";0");

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

But it will work only in DOCX format, upon rendering conditional number format will not be handled properly. This problem is logged as WORDSNET-23447. We will let you know once it is resolved.
If you are building charts from scratch, you can check your data and set format code according to the values used in data.