Page 1 of 1
Custom drawing on canvas fails
Posted: Fri Feb 29, 2008 8:02 am
by 7666477
I try to put text on my chart. I follow example in documentation:
String text = "mytext";
IGraphics3D g = chart.getGraphics3D();
g.textOut(0, 0, text);
CRASH!!!!
Exception in thread "main" java.lang.NullPointerException
at com.steema.teechart.drawing.Graphics3DAWT.drawString(Graphics3DAWT.java:706)
at com.steema.teechart.drawing.Graphics3D.textOut(Graphics3D.java:1936)
at com.steema.teechart.drawing.Graphics3DAWT.textOut(Graphics3DAWT.java:726)
at ................ <my code reference here>
Posted: Fri Feb 29, 2008 10:25 am
by narcis
Hi Happy,
This works fine for me here using this code:
Code: Select all
com.steema.teechart.styles.Shape shape1 = new com.steema.teechart.styles.Shape(tChart.getChart());
shape1.setX0(0);
shape1.setY0(0);
shape1.setX1(100);
shape1.setY1(100);
shape1.getMarks().setVisible(true);
shape1.setStyle(ShapeStyle.DIAMOND);
shape1.setText(new String[] {"This is my shape"});
shape1.getFont().setSize(20);
shape1.getGradient().setVisible(true);
shape1.getGradient().setStartColor(Color.RED);
shape1.getGradient().setEndColor(Color.RED);
shape1.getGradient().setTransparency(50);
tChart.addChartPaintListener( new ChartPaintAdapter() {
public void chartPainted(ChartDrawEvent pce) {
IGraphics3D g = tChart.getGraphics3D();
g.textOut(tChart.getAxes().getBottom().iStartPos + 5,
tChart.getSeries(0).getVertAxis().iStartPos + 5,
"My custom text");
};
});
Can you please try if it works fine at yoru end?
Thanks in advance.
Posted: Fri Feb 29, 2008 10:28 am
by 7666477
I cannot add in a addChartPaintListener method because I am creating the chart in a headless environment (that is, in a Java servlet).
So I need to add the custom text in the same function as the chart is being drawn.
(not sure if I am making myself clear?!?)
Posted: Fri Feb 29, 2008 10:54 am
by 7666477
ok, I added your code and it works, but I still have an issue with adding in the even listener because the method in which I create the chart is static, and so the listener doesn't have access to the chart object.
For testing purposes I made the chart object a static member of the class, but this is not an ideal thing to do when it comes to servlet programming because that object will be shared amongst all the web-server's threads.
and I don't want to synchronize the variable because our web server serves about 50 requests per second.
Posted: Fri Feb 29, 2008 11:37 am
by 7666477
I changed my class structure to fit into the teechart model. Thanks for your help!