TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
-
roman@astarus.com
- Newbie
- Posts: 2
- Joined: Tue Aug 26, 2014 12:00 am
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 (14.94 KiB) Viewed 39037 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
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
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);
}