|
Re: Create pie chart programatically? [message #43945 is a reply to message #43709] |
Tue, 07 June 2005 15:27 |
Eclipse User |
|
|
|
Originally posted by: mpadhye.actuate.com
Hi,
Take a look at the code to create a Line chart programmatically as
given in a separate thread in this group 'create a line chart
programmatically'.
Here is the code for creating a Pie chart programmatically. It is
loosely based on the code for the line chart so you can get a better
feel for the structural differences between these two chart types.
NOTE: It is also possible to take a look at how basic models for other
chart types are created if you have downloaded the code. The code for
the chart types resides in the org.eclipse.birt.chart.ui.extension
plug-in under the org.eclipse.birt.chart.ui.swt.type package. (Take a
look at the getModel() method in the various classes.
// Code Start
/**
* Creates a pie chart model as a reference implementation
* @return An instance of a pie chart model (with sample data)
*/
public static final Chart createSimplePieChart()
{
ChartWithoutAxes cwoaPie = ChartWithoutAxesImpl.create();
cwoaPie.setType("Pie Chart");
cwoaPie.setSubType("Standard Pie Chart");
cwoaPie.setDimension(ChartDimension.TWO_DIMENSIONAL_WITH_DEP TH_LITERAL);
cwoaPie.getBlock().setBackground(ColorDefinitionImpl.WHITE() );
Plot p = cwoaPie.getPlot();
p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55,
255, 225));
cwoaPie.getTitle().getLabel().getCaption().setValue("Sample Pie
Chart");
Legend lg = cwoaPie.getLegend();
LineAttributes lia = lg.getOutline();
lg.getText().getFont().setSize(16);
lia.setStyle(LineStyle.SOLID_LITERAL);
lg.getInsets().set(10, 5, 0, 0);
lg.getOutline().setVisible(false);
lg.setAnchor(Anchor.NORTH_LITERAL);
// CREATE THE CATEGORY SERIES
Series seCategory = SeriesImpl.create();
// CREATE THE PRIMARY DATASET
PieSeries ls = (PieSeries) PieSeriesImpl.create();
ls.setSeriesIdentifier("My Pie Series");
ls.setSliceOutline(ColorDefinitionImpl.CREAM());
ls.getLabel().setVisible(true);
SeriesDefinition sdX = SeriesDefinitionImpl.create();
sdX.getSeriesPalette().update(0); // SET THE COLORS IN THE PALETTE
sdX.setQuery(QueryImpl.create(""));
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getSeriesPalette().update(1); // SET THE COLORS IN THE PALETTE
sdY.setQuery(QueryImpl.create(""));
sdX.getSeriesDefinitions().add(sdY);
sdX.getSeries().add(seCategory);
sdY.getSeries().add(ls);
cwoaPie.getSeriesDefinitions().add(sdX);
addSampleData(cwoaPie);
return cwoaPie;
}
// Code End
Thanks,
Milind
jungcw@kr.ibm.com wrote:
> Hello folks,
>
> Eclipse Chart Engine seems promising for chartting with SWT.
> Can anyone upload snippet for creating pie chart (2d with depth) with SWT
> programatically?
> I'd like to use pie chart within SWT application.
> Thanks in advance.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03320 seconds