Excel charts with JExcel?
Here for someone's benefit is a working example of creating an Excel chart on a worksheet:
private void buildGraph()
{
try {
worksheet.getOleMessageLoop().doInvokeAndWait(new Runnable()
{
public void run()
{
createChart(worksheet);
}
});
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void createChart(Worksheet worksheet)
{
_Worksheet ws = worksheet.getPeer();
IUnknown disp = ws.chartObjects(Variant.createUnspecifiedParameter(),new Int32(0));
ChartObjects objects = new ChartObjectsImpl(disp);
DoubleFloat left = new DoubleFloat(500);
DoubleFloat top = new DoubleFloat(100);
DoubleFloat width = new DoubleFloat(300);
DoubleFloat height = new DoubleFloat(300);
ChartObject chartObject = objects.add(left, top,width, height);
chartObject.setName(new BStr("normalDistChart"));
_Chart chart = chartObject.getChart();
com.jniwrapper.win32.excel.Range valuesRange = ws.getRange(new Variant("distributionRange"),Variant.createUnspecifiedParameter() );
chart.setSourceData(valuesRange, new Variant(2));
chart.setChartType(new XlChartType(4));
chart.setHasLegend(new Int32(0), new VariantBool(true));
chart.getLegend(new Int32(0)).setPosition(new XlLegendPosition(XlLegendPosition.xlLegendPositionBottom));
chart.setHasTitle(new Int32(0), new VariantBool(true));
chart.getChartTitle(new Int32(0)).setText(new BStr("Normal Distribution Demo"));
Series series = new SeriesImpl(chart.seriesCollection(new Variant(1), new Int32(0)));
series.setName(new BStr("Cumulative"));
series = new SeriesImpl(chart.seriesCollection(new Variant(2), new Int32(0)));
series.setName(new BStr("NonCumulative"));
}
Fte: http://support.teamdev.com/thread/2141?tstart=0
No hay comentarios:
Publicar un comentario