clickedCandle bug

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Marian
Newbie
Newbie
Posts: 8
Joined: Tue Jan 29, 2008 12:00 am

clickedCandle bug

Post by Marian » Thu Mar 20, 2008 8:54 am

Hi,
There is a bug in 'clickedCandle' method in Candle class. It is used by 'clicked' method and also mouse events I think.
The existing clickedCandle works fine for candles with open price higher than close. For the second case with close higher than open it only returns true when the point passed as the argument lies in the middle of the candle or within 3 points distance from it. If the candle is wide, the sensitive area is not sufficient.
We were able to fix it by replacing the code in line #524 of Candle.java:

int tmpX =calcXPosValue(getDateValues().value[valueIndex]); /* The horizontal position */
int yOpen =calcYPosValue(vOpenValues.value[valueIndex]);
int yHigh =calcYPosValue(vHighValues.value[valueIndex]);
int yLow =calcYPosValue(vLowValues.value[valueIndex]);
int yClose=calcYPosValue(getCloseValues().value[valueIndex]);

by the code:

double openPrice = vOpenValues.value[valueIndex];
double closePrice = getCloseValues().value[valueIndex];
int tmpX =calcXPosValue(getDateValues().value[valueIndex]); /* The horizontal position */
int yOpen =calcYPosValue(openPrice);
int yClose=calcYPosValue(closePrice);
int yHigh =calcYPosValue(vHighValues.value[valueIndex]);
int yLow =calcYPosValue(vLowValues.value[valueIndex]);

and also replacing code in line 578:

Rectangle tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);

by the code:

Rectangle tmpR;
if (openPrice > closePrice)
{
tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yOpen,tmpX+tmpRightWidth+1,yClose);
}
else
{
tmpR=Rectangle.fromLTRB(tmpX-tmpLeftWidth,yClose,tmpX+tmpRightWidth+1,yOpen);
}


We were only trying to fix the 2D chart/2D candles case.

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

Post by Narcís » Thu Mar 20, 2008 9:44 am

Hi Marian,

I'm not able to reproduce the issue here using latest TeeChart for Java version available at the client area.

The code I'm using is this:

Code: Select all

        tChart.removeAllSeries();
        com.steema.teechart.styles.Candle candle1 = new com.steema.teechart.styles.Candle(tChart.getChart());
        
        candle1.add(0,4,4,1,1);
        candle1.add(1,4,4,1,1);
        candle1.add(2,1,1,4,4);
        candle1.add(3,1,1,4,4);        


        tChart.addMouseListener(new java.awt.event.MouseListener() {
            public void mouseClicked(MouseEvent e) {
                tChartMouseListened(e);
            }
            public void mouseEntered(MouseEvent e) {
            }
            public void mouseExited(MouseEvent e) {
            }
            public void mousePressed(MouseEvent e) {
            }
            public void mouseReleased(MouseEvent e) {
            }
        });



    private void tChartMouseListened(java.awt.event.MouseEvent e) {
        
        com.steema.teechart.styles.Candle c = (com.steema.teechart.styles.Candle)tChart.getSeries(0);
        
        int index = tChart.getSeries(0).clicked(e.getX(),e.getY());
        Point p = new Point(e.getX(), e.getY());
        
        if (c.clickedCandle(index, p)) {
            tChart.getHeader().setText(String.valueOf(index));            
        }

//        Code below also works fine        
//        if (tChart.getSeries(0).clicked(e.getX(),e.getY()) != -1) {
//            tChart.getHeader().setText(String.valueOf(tChart.getSeries(0).clicked(e.getX(),e.getY())));            
//        }
    }
Could you please modify it and let us know the exact steps we should follow to reproduce the issue here?

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

Marian
Newbie
Newbie
Posts: 8
Joined: Tue Jan 29, 2008 12:00 am

Post by Marian » Thu Mar 20, 2008 12:04 pm

I am quite sure I am using the latest (November 14th) version.
Please try to widen your candles as:

candle1.setCandleWidth(40);

and use this listener:

private void tChartMouseListened(java.awt.event.MouseEvent e) {
Candle c = (Candle)tChart.getSeries(0);
int index = tChart.getSeries(0).clicked(e.getX(),e.getY());
if (index == -1)
{
tChart.getHeader().setText("No candle onclick");
}
else
{
Point p = new Point(e.getX(), e.getY());

if (c.clickedCandle(index, p)) {
tChart.getHeader().setText(String.valueOf(index));
}
}
// Code below also works fine
// if (tChart.getSeries(0).clicked(e.getX(),e.getY()) != -1) {
// tChart.getHeader().setText(String.valueOf(tChart.getSeries(0).clicked(e.getX(),e.getY())));
// }
}

If you now click on the one of the rising (white) candles body, more than tri pixels off its x center, you'll get the "No candle onclick" message although you're clicking the candle body.

Post Reply