Bar rising high [message #115116] |
Wed, 25 January 2006 01:47  |
Eclipse User |
|
|
|
Originally posted by: amitgolwala.gmail.com
Hi I am using BIRT Chart Engine in an SWT application. I have created
ChatWithAxes and have set the Data for Y - axis. I m using BarSeries for
viewing the data values. However, on runtime I can see all the set values
alongwith the Bars but due to some reasons all the bars rise upto to the
maximum height of the chart irrespective of the data value set for that
bar.
|
|
|
|
Re: Bar rising high [message #118208 is a reply to message #115208] |
Thu, 26 January 2006 18:32   |
Eclipse User |
|
|
|
Originally posted by: amitgolwala.gmail.com
Hi,
following is the code written inorder to view the Chart with BarSeries in
SWT.
public class Snippet84 {
private static final class MyPaintListener implements PaintListener {
public void paintControl(PaintEvent e) {
IDeviceRenderer deviceRenderer = null;
try {
System.setProperty("STANDALONE", "true");
deviceRenderer = PluginSettings.instance().getDevice("dv.SWT");
} catch (Exception ex) {
System.err.println("Oops, can't find the device renderer.");
ex.printStackTrace();
System.exit(1);
}
deviceRenderer.setProperty(IDeviceRenderer.GRAPHICS_CONTEXT, e.gc);
Rectangle rect = ((Composite) e.widget).getClientArea();
final Bounds bounds = BoundsImpl.create(rect.x + 2, rect.y + 2,
rect.width - 4, rect.height - 4);
bounds.scale(72d /
deviceRenderer.getDisplayServer().getDpiResolution());
Chart chart = createSimpleLineChart();
if (chart == null)
return;
final Generator gr = Generator.instance();
GeneratedChartState state;
try {
state = gr.build(deviceRenderer.getDisplayServer(), chart,
bounds, null, new RunTimeContext (), null);
gr.refresh(state);
gr.render(deviceRenderer, state);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("TestLineChart");
Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.addPaintListener(new MyPaintListener());
shell.setSize(400, 400);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
/**
* Creates a line chart model as a reference implementation *
*
* @return An instance of the simulated runtime chart model (containing
filled
* datasets)
*/
public static final Chart createSimpleLineChart() {
ChartWithAxes cwaBar = ChartWithAxesImpl.create();
cwaBar.getBlock().setBackground(ColorDefinitionImpl.WHITE()) ;
Plot p = cwaBar.getPlot();
p.getClientArea().setBackground(ColorDefinitionImpl.create(2 55, 255,
225));
p.getOutline().setVisible(false);
cwaBar.getTitle().getLabel().getCaption().setValue("");
Legend lg = cwaBar.getLegend();
LineAttributes lia = lg.getOutline();
lia.setStyle(LineStyle.SOLID_LITERAL);
lg.getText().getFont().setSize(16);
lg.getInsets().set(10, 5, 0, 0);
lg.getOutline().setVisible(false);
lg.setAnchor(Anchor.NORTH_LITERAL);
Axis xAxisPrimary = (Axis) cwaBar.getPrimaryBaseAxes()[0];
xAxisPrimary.setType(AxisType.TEXT_LITERAL);
xAxisPrimary.getMajorGrid().setTickStyle(TickStyle.BELOW_LIT ERAL);
xAxisPrimary.getOrigin().setType(IntersectionType.VALUE_LITE RAL);
xAxisPrimary.getTitle().setVisible(false);
Axis yAxisPrimary = (Axis) cwaBar
.getOrthogonalAxes(xAxisPrimary, true)[0];
yAxisPrimary.getMajorGrid().setTickStyle(TickStyle.LEFT_LITE RAL);
yAxisPrimary.setType(AxisType.LINEAR_LITERAL);
yAxisPrimary.setPercent(true);
Vector vs = new Vector();
vs.add("one");
vs.add("two");
vs.add("three");
ArrayList vn1 = new ArrayList ();
vn1.add(new Double(10));
vn1.add(new Double(20));
vn1.add(new Double(30));
if (vn1 == null)
return null;
TextDataSet categoryValues = TextDataSetImpl.create(vs);
NumberDataSet orthoValues1 = NumberDataSetImpl.create(vn1);
Series seCategory = SeriesImpl.create();
seCategory.setDataSet(categoryValues);
BarSeries bs = (BarSeries) BarSeriesImpl.create();
bs.setSeriesIdentifier("");
bs.setDataSet(orthoValues1);
bs.getLabel().setVisible(true);
SeriesDefinition sdX = SeriesDefinitionImpl.create();
sdX.getSeriesPalette().update(0);
xAxisPrimary.getSeriesDefinitions().add(sdX);
SeriesDefinition sdY = SeriesDefinitionImpl.create();
sdY.getSeriesPalette().update(1);
yAxisPrimary.getSeriesDefinitions().add(sdY);
sdX.getSeries().add(seCategory);
sdY.getSeries().add(bs);
return cwaBar;
}
}
|
|
|
|
|
Re: Bar rising high [message #118527 is a reply to message #118358] |
Fri, 27 January 2006 06:40  |
Eclipse User |
|
|
|
I'm glad you found a solution. I am not really understanding how the
rotation of the axis label has anything to do with the bar rising though.
Anyway the most important is that you got it working.
Thanks,
David
"Amit Golwala" <amitgolwala@gmail.com> wrote in message
news:f01d5af9ffc3aece6bc8c1f67c34b19b$1@www.eclipse.org...
> Amit Golwala wrote:
>
>> hey,
>> just want to add another line to the previous posting. The above code is
>> an answer to the FAQ with question as "Q: How can I use charts in SWT?"
>> on this URL: "http://www.eclipse.org/birt/wiki/index.php?n=FAQ.Charts".
>
>> thnx for reading...
>> waiting for help ......
>> cheeeeers !!
>
>> Amit
>
> Sorry to bother any who has read all the previous threads but I m glad to
> say that I have overcome the problem n got the solution. For ne one
> interseted, I must tell that the source code posted in previous postings,
> I missed following line:
> " yAxisPrimary.getLabel().getCaption().getFont().setRotation(9 0); "
>
> Cheers !!
>
> Amit
>
|
|
|
Powered by
FUDForum. Page generated in 0.26707 seconds