Find Type of X and Y Values of Points in Chart Series

Possible Usage Scenarios

Sometimes, you want to know the type of X and Y values of chart points in a series. Aspose.Cells provides ChartPoint.XValueType and ChartPoint.YValueType properties that can be used for this purpose. Please note, you will have to call Chart.calculate() method before you could use these properties effectively.

Find Type of X and Y Values of Points in Chart Series

The following sample code loads the sample Excel file and accesses the first chart inside the first worksheet. It then calls the Chart.calculate() method and finds the type of X and Y values of first chart point and prints them on the console. Please see the console output shown below for a reference.

Sample Code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Converting integer enums to string enums
java.util.HashMap<Integer, String> cvTypes = new java.util.HashMap<Integer, String>();
cvTypes.put(CellValueType.IS_NUMERIC, "IsNumeric");
cvTypes.put(CellValueType.IS_STRING, "IsString");
//Load sample Excel file containing chart.
Workbook wb = new Workbook(srcDir + "sampleFindTypeOfXandYValuesOfPointsInChartSeries.xlsx");
//Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
//Access first chart.
Chart ch = ws.getCharts().get(0);
//Calculate chart data.
ch.calculate();
//Access first chart point in the first series.
ChartPoint pnt = ch.getNSeries().get(0).getPoints().get(0);
//Print the types of X and Y values of chart point.
System.out.println("X Value Type: " + cvTypes.get(pnt.getXValueType()));
System.out.println("Y Value Type: " + cvTypes.get(pnt.getYValueType()));

Console Output

X Value Type: IsString

Y Value Type: IsNumeric