Android - Custom Drawing.

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
roman@astarus.com
Newbie
Newbie
Posts: 2
Joined: Tue Aug 26, 2014 12:00 am

Android - Custom Drawing.

Post by roman@astarus.com » Thu Sep 04, 2014 11:27 am

Hello.

I need help with custom chart drawing. What I have now:
chart.png
chart.png (14.94 KiB) Viewed 2273 times
Bars show count of sold goods and red triangle shows target count. Code looks like this:

Code: Select all

chart.addChartPaintListener(new ChartPaintAdapter() {
                @Override
                public void chartPainted(ChartDrawEvent chartDrawEvent) {
                    final int target = 300;
                    IGraphics3D graphics = holder.chart.getGraphics3D();
                    graphics.getPen().setColor(Color.black);
                    graphics.getBrush().setColor(Color.red);
                    Point point0 = new Point(target+10, graphics.getYCenter()*2);
                    Point point1 = new Point(target-10, graphics.getYCenter()*2);
                    Point point2 = new Point(target, graphics.getYCenter()*2 - 20);
                    graphics.triangle(point0, point1, point2, 0);
                }
            });
As you can see target equals 300, but on the chart it near 1000. Seems point.x is not value showed on X axis. But what is correct way to calculate the triangle position?
Also Y coordinate of triangle base is not correct to. How to put it exactly on X axis?

Thank you and best regards.

Yeray
Site Admin
Site Admin
Posts: 8738
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Android - Custom Drawing.

Post by Yeray » Fri Sep 05, 2014 8:22 am

Hello,
roman wrote:As you can see target equals 300, but on the chart it near 1000. Seems point.x is not value showed on X axis. But what is correct way to calculate the triangle position?
If 300 is an axis value, you have to transform it to screen pixels to use drawing techniques. The axes' calcPosValue() functions do this.
roman wrote:Also Y coordinate of triangle base is not correct to. How to put it exactly on X axis?
You could use the axis getPosition() method to get it.

This seems to work fine for me here:

Code: Select all

        chart.addChartPaintListener(new ChartPaintAdapter() {
                @Override
                public void chartPainted(ChartDrawEvent chartDrawEvent) {
                    final int target = tChart1.getAxes().getBottom().calcPosValue(300);
                    final int posAxis = tChart1.getAxes().getBottom().getPosition();
                    IGraphics3D graphics = tChart1.getGraphics3D();
                    graphics.getPen().setColor(Color.black);
                    graphics.getBrush().setColor(Color.red);
                    Point point0 = new Point(target+10, posAxis);
                    Point point1 = new Point(target-10, posAxis);
                    Point point2 = new Point(target, posAxis - 20);
                    graphics.triangle(point0, point1, point2, 0);
                }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

roman@astarus.com
Newbie
Newbie
Posts: 2
Joined: Tue Aug 26, 2014 12:00 am

Re: Android - Custom Drawing.

Post by roman@astarus.com » Fri Sep 05, 2014 10:35 am

Perfect, thanks.

Post Reply