Chart.toImage - Category Axis Tick Labels are wrongly placed when All values are negative and we configure TickLabelPositionType.LOW

Hi,

Please run the following sample code and see the issues mentioned.

1. Category Axis Tick Labels are wrongly placed. It should be at extreme left, as we configured it using - chart.getCategoryAxis().setTickLabelPosition(TickLabelPositionType.LOW)

2. Value X Axis labels are overlaped - looks like due to wrong scale in the image.

3. -0 in the image instead of 0

Thanks
Muhammed

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Array;

import com.aspose.cells.ASeries;
import com.aspose.cells.CellsHelper;
import com.aspose.cells.Chart;
import com.aspose.cells.ChartType;
import com.aspose.cells.Color;
import com.aspose.cells.DisplayUnitType;
import com.aspose.cells.FileFormatType;
import com.aspose.cells.GradientColorType;
import com.aspose.cells.GradientDirectionType;
import com.aspose.cells.GradientFill;
import com.aspose.cells.GradientFillType;
import com.aspose.cells.GradientStyleType;
import com.aspose.cells.ImageFormat;
import com.aspose.cells.ImageOptions;
import com.aspose.cells.LegendEntries;
import com.aspose.cells.PatternFill;
import com.aspose.cells.TickLabelPositionType;
import com.aspose.cells.TrendlineType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class LowTickLabelNegOnly {

public static void main(String args[]) {

try {
String[] colTitle = new String[] { "Main Wash",
"Special Wash",
"Wash Treatment"
};

//Array of cell data
double[][] data = new double[][] {
{-17060100, -30207780, -481208}
};

Workbook wb = new Workbook();
Worksheet dataSheet = wb.getWorksheets().addSheet();

String dataSheetName = "DataSheet";
dataSheet.setName(dataSheetName);

int rowIndex = 0;
for (int i = 0; i < colTitle.length; i++) {
dataSheet.getCells().getCell(rowIndex, i).setValue(colTitle[i]);
}

for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
dataSheet.getCells().getCell(i + 1, j).setValue(data[i][j]);
}
}

//Add a chart sheet
Worksheet chartSheet = wb.getWorksheets().addSheet();
chartSheet.setName("ChartSheet");
int chartSheetIdx = chartSheet.getIndex();

//Add a chart in ChartSheet with data series from DataSheet
int chartWidth = 600;
int chartHeight = 400;

int chartHeightInRows = 0;
int chartWidthInCols = 0;
int cellWidth = dataSheet.getCells().getColumnWidthPixel(0);
int cellHeight = dataSheet.getCells().getRowHeightPixel(0);
chartWidthInCols = (int)(chartWidth / cellWidth);
chartHeightInRows = (int)(chartHeight / cellHeight);
chartWidth = chartWidthInCols * cellWidth;
chartHeight = chartHeightInRows * cellHeight;

Chart chart = chartSheet.getCharts().addChart(ChartType.BAR_CLUSTERED, 0, 0, 0, 0, chartWidth, chartHeight);

String dataRef = dataSheet.getName() + "!" + CellsHelper.convertCellIndexToName(0, 0) + ":" + CellsHelper.convertCellIndexToName(data.length, colTitle.length - 1);
chart.getNSeries().add(dataRef, false);

String categoryAreaRef = dataSheet.getName() + "!" + CellsHelper.convertCellIndexToName(0, 0) + ":" + CellsHelper.convertCellIndexToName(0, colTitle.length - 1);
chart.getNSeries().setCategoryData(categoryAreaRef);

chart.getCategoryAxis().setDisplayUnitLabelShown(false);
chart.getCategoryAxis().setTickLabelPosition(TickLabelPositionType.LOW);

//Get Chart as image.
ImageOptions imgOpts = new ImageOptions();
imgOpts.setImageFormat(ImageFormat.PNG);
imgOpts.setFashion(FileFormatType.EXCEL2003);

chart.toImage(new FileOutputStream("D:\\Temp\\chart.png"), imgOpts);

wb.getWorksheets().setActiveSheet(chartSheetIdx);
wb.setOleSize(0, chartHeightInRows - 1, 0, chartWidthInCols - 1);

//Save the workbook to stream
ByteArrayOutputStream bout = new ByteArrayOutputStream();
wb.save(bout);
wb.save(new FileOutputStream("D:\\Temp\\output.xls"));

System.out.println("successfully completed!!!" + CellsHelper.getReleaseVersion());

}
catch (Exception e) {
e.printStackTrace();
}
}

}

Hi,

After an initial test, I found all your mentioned issues, we will figure it out soon.

Your issue has been logged into our issue tracking system with an issue id: CELLSJAVA-16149.

Thank you.