Custom drawing on canvas fails

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Happy
Newbie
Newbie
Posts: 10
Joined: Thu Nov 22, 2007 12:00 am

Custom drawing on canvas fails

Post by Happy » Fri Feb 29, 2008 8:02 am

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>

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Feb 29, 2008 10:25 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Happy
Newbie
Newbie
Posts: 10
Joined: Thu Nov 22, 2007 12:00 am

Post by Happy » Fri Feb 29, 2008 10:28 am

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?!?)

Happy
Newbie
Newbie
Posts: 10
Joined: Thu Nov 22, 2007 12:00 am

Post by Happy » Fri Feb 29, 2008 10:54 am

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.

Happy
Newbie
Newbie
Posts: 10
Joined: Thu Nov 22, 2007 12:00 am

Post by Happy » Fri Feb 29, 2008 11:37 am

I changed my class structure to fit into the teechart model. Thanks for your help!

Post Reply