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

Free Support Forum - aspose.com

chart.toImage - title and series name issues

Could you please look into two issues?

1) When the chart title gets too long to display in one line, the generated image doesn’t wrap like the chart in the Excel workbook.

2) NSeries names are not stacking to extra rows in the generated image like the chart in the Excel workbook.

Thanks,
Frank

package com.test;

import java.io.FileOutputStream;

import com.aspose.cells.CategoryAxis;
import com.aspose.cells.Cells;
import com.aspose.cells.CellsHelper;
import com.aspose.cells.Chart;
import com.aspose.cells.ChartType;
import com.aspose.cells.Color;
import com.aspose.cells.Font;
import com.aspose.cells.ImageFormat;
import com.aspose.cells.ImageOptions;
import com.aspose.cells.Legend;
import com.aspose.cells.LegendPositionType;
import com.aspose.cells.NSeries;
import com.aspose.cells.TickMarkerType;
import com.aspose.cells.ValueAxis;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class ChartImage {

private static Chart chart;
private static String dir = “c:\temp\”;

public static void main( String[] arguments) throws Exception
{
final Workbook wb = new Workbook();
final Worksheet ws = wb.getWorksheets().getActiveSheet();
final Cells c = ws.getCells();

for (int i=1, value=1; i<4; i++)
{
c.getCell(“A” + i).setValue(“R” + i);
for (int j=1; j<5; j++, value++)
c.getCell(CellsHelper.convertColumnIndexToName(j) + i).setValue(value);
}

final Worksheet worksheet = wb.getWorksheets().getActiveSheet();
chart = worksheet.getCharts().addChart(ChartType.COLUMN_CLUSTERED, 5, 1, 18, 4);
drawReportViewerBarChart();
final ImageOptions imgOpts = new ImageOptions();
imgOpts.setImageFormat(ImageFormat.PNG);
try {
chart.toImage(new FileOutputStream(dir + “chart1.png”), imgOpts);
} catch (Exception e) {
e.printStackTrace();
}
chart = worksheet.getCharts().addChart(ChartType.PIE, 5, 6, 18, 9);
drawReportViewerPieChart();
try {
chart.toImage(new FileOutputStream(dir + “chart2.png”), imgOpts);
} catch (Exception e) {
e.printStackTrace();
}
wb.save(dir + “chart.xls”);
}

private static void drawReportViewerPieChart() throws Exception
{
chart.setType(ChartType.PIE);
chart.getNSeries().add(“Sheet1!$A$1:$E$3”, true);
chart.getPlotArea().getArea().setVisible(false);
drawReportViewerChart();
}

private static void drawReportViewerBarChart() throws Exception
{
chart.setType(ChartType.COLUMN_CLUSTERED);
chart.getNSeries().add(“Sheet1!$A$1:$E$3”, true);
chart.getPlotArea().getArea().setForegroundColor(Color.GRAY);
drawReportViewerChart();
}

private static void drawReportViewerChart() throws Exception
{
chart.getTitle().setText(“Sometimes this name gets really long and is no longer centered”);
chart.getTitle().getFont().setBold(true);
chart.getTitle().getFont().setSize(10);
chart.getPlotArea().getBorder().setVisible(false);

NSeries nSeries = chart.getNSeries();
final int size = nSeries.size();
for (int i = 0; i < size; )
chart.getNSeries().get(i).setName(“Longer name test - C” + ++i);

Legend legend = chart.getLegend();
legend.getFont().setSize(8);
legend.getBorder().setVisible(false);
legend.setPosition(LegendPositionType.BOTTOM);
chart.setLegendShown(true);

CategoryAxis ca = chart.getCategoryAxis();
Font f = ca.getTitle().getFont();
f.setSize(10);
f.setBold(true);
ca.getFont().setBold(false);
ca.getFont().setSize(8);
ca.setMajorTickMark(TickMarkerType.OUTSIDE);

ValueAxis va = chart.getValueAxis();
va.getFont().setBold(false);
va.getFont().setSize(8);
va.setMajorTickMark(TickMarkerType.OUTSIDE);
}
}

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample code.

We have found your mentioned issue after an initial test. We will look into it and get back to you soon. Your issue has been registered in our internal issue tracking system with issue id CELLSJAVA-14436.

Thank You & Best Regards,

Hi,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please try the attached latest version. We have fixed the issue regarding long title.

Thank You & Best Regards,

The issues you have found earlier (filed as CELLSJAVA-14436) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.