Avatar of gbcbr
gbcbrFlag for Cyprus

asked on 

TimeSeriesChart dataset

I make my class from sample of Dynamic Sample of JFreeChart - MemoryUsageDemo.
http://read.pudn.com/downloads61/sourcecode/graph/210808/src/my/chart/test/dev/guide/MemoryUsageDemo.java__.htm
I arrange all details for my needs, but this class gets dynamic data from Runtime class.
I need to get my data from class SelectData instead of Runtime.
Original method:
public void actionPerformed(ActionEvent event) {   
            long f = Runtime.getRuntime().freeMemory();   
            long t = Runtime.getRuntime().totalMemory();   
            addTotalObservation(t);   
            addFreeObservation(f);   
        }   
    }

Open in new window

My source of dynamic data SelectData class:
public class SelectData extends TimerTask {

    private ConnectDB conn;

    String[] symbol = new String[25];
    double[] openBid = new double[25];
    Timestamp[] timest = new Timestamp[25];
    Timestamp[] ts_buy = new Timestamp[25];
    Timestamp[] ts_sell = new Timestamp[25];
    double[] buy_px = new double[25];
    double[] sell_px = new double[25];
    double bb;
    double bs;

    Timestamp tsb0 = null;
    Timestamp tss0 = null;
    String bot_buy0 = null;
    String bot_sell0 = null;
    
    public SelectData() throws SQLException, ClassNotFoundException,
                               IllegalAccessException, InstantiationException,
                               Exception {
        conn = new ConnectDB();
    }

    public void run() {
        
        try {
            List<DataStream> dataList =
                conn.selectStream("SELECT * FROM EURUSD where timest = ( select max( timest ) from EURUSD ) and rownum = 1 "); 

            for (DataStream data : dataList) {

                String s;
                double bpx;
                Timestamp tst;

                s = data.getSymbol();
                bpx = data.getOpenBid();
                tst = data.getTimest();

                if (s.equals("EUR/USD")) {

                    symbol[0] = s;
                    openBid[0] = bpx;
                    timest[0] = tst;

                }
            }
        } catch (Exception ex) {
            Logger.getLogger(SelectData.class.getName()).log(Level.SEVERE,
                                                             null, ex);
        }

        try {

            List<DataBuy> dataList =
                conn.selectBuy("SELECT * FROM EURUSD_BOT_BUY where ts = ( select max( ts ) from EURUSD_BOT_BUY ) and rownum = 1 ");

            for (DataBuy data : dataList) {

                String s;
                Timestamp tsb;
                String bot_buy;
               
                s = data.getSymbol();
                tsb = data.getTs();  
                bot_buy = data.getBuyPx();

                    if (tsb.equals(tsb0) &&
                        bot_buy.equals(bot_buy0))
                    continue;

                tsb0 = tsb;
                bot_buy0 = bot_buy; 
                                
                bb = Double.parseDouble(bot_buy);

                if (s.equals("EUR/USD"))
                {

                    symbol[0] = s;
                    buy_px[0] = bb;
                    ts_buy[0] = tsb;

                    System.out.println(">>>>>> BUY <<<<<<<   Symbol  " + symbol[0] +
                                       "    ts_buy[0]    " + ts_buy[0] +
                                       "   buy_px[0]  " + buy_px[0]);
     
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(SelectData.class.getName()).log(Level.SEVERE,
                                                             null, ex);
        }


        try {

            List<DataSell> dataList =
                conn.selectSell("SELECT * FROM EURUSD_BOT_SELL where ts = ( select max( ts ) from EURUSD_BOT_SELL ) and rownum = 1 "); 

            for (DataSell data : dataList) {

                String s;
                Timestamp tss;
                String bot_sell;

                s = data.getSymbol();
                tss = data.getTs();
                bot_sell = data.getSellPx();

                if (tss.equals(tss0) && bot_sell.equals(bot_sell0))
                    continue;

                tss0 = tss;
                bot_sell0 = bot_sell;
                
                bs = Double.parseDouble(bot_sell);

                               if (s.equals("EUR/USD")) {

                    symbol[0] = s;
                    sell_px[0] = bs;
                    ts_sell[0] = tss;

                    System.out.println(">>>>>> SELL <<<<<<<   Symbol  " + symbol[0] +
                                       "    ts_sell[0]    " + ts_sell[0] +
                                       "   sell_px[0]  " + sell_px[0]);
     
            }
        } catch (Exception ex) {
            Logger.getLogger(SelectData.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

Open in new window

How I can get these data:
public void actionPerformed(ActionEvent event) {
            double s = ?
            double b = ?
            double st = ?
            addStreamObservation(st);   
            addBuyObservation(b);
            addSellObservation(s);
        }   
    }

Open in new window

Please advice how to assign my data to this chart.
Java

Avatar of undefined
Last Comment
gbcbr
Avatar of for_yan
for_yan
Flag of United States of America image

So what is s, b, st ?
And do you need ActionPerformed - is this some data whioch comes from some event coming from user or you need to
collect your data which arrives from your query?
Please, elaborate.

Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

In my previous charts I used construction like this:
public void doEvent_avg(double[] avg) {
        sc++;

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(avg[0]));

        if (sc > 100) {
            s1.delete(0, 0);
        }
    }

Open in new window

but this new construction much lighter, so I try to use it with action performed listener.
double s,b and st are analogs of long f and long t from the original.
I was tried to create additional class Data_EURUSD
public class Data_EURUSD {

    private static final Data_EURUSD INSTANCE = new Data_EURUSD();

    public static Data_EURUSD getInstance() {
        return INSTANCE;
    }
    
    public Data_EURUSD() {
        super();
    }
    
    public void streamEURUSD(double[] openBid ){

                            System.out.println("    >>>>>>>> Data_EURUSD <<<<<<<<     "  +  "  openBid[0]  " + openBid[0]);
    }
    
    public void buyEURUSD(double[] buy_px){

        System.out.println("    >>>>>>>> Data_EURUSD <<<<<<<<     " + "  buy_px[0]  " +buy_px[0]);    
    }

    public void sellEURUSD(double[] sell_px) {

        System.out.println("    >>>>>>>> Data_EURUSD <<<<<<<<     " +
                           "  sell_px[0]  " + sell_px[0]);
    }
}

Open in new window

, send values there and try to get them from there,
public void actionPerformed(ActionEvent event) {
            double[] sell_px;
            double s = Data_EURUSD.getInstance().sellEURUSD(sell_px);
            double[] buy_px;
            double b = Data_EURUSD.getInstance().buyEURUSD(buy_px);
            double[] openBid;
            double st = Data_EURUSD.getInstance().streamEURUSD(openBid); 
            addStreamObservation(st);   
            addBuyObservation(b);
            addSellObservation(s);
        }   
    }

Open in new window

but I have this error: Cannot assign value of type void to variable of type double
But I try to assign double to double!
Avatar of for_yan
for_yan
Flag of United States of America image



 public <this method returns void> void streamEURUSD(double[] openBid )


double st = Data_EURUSD.getInstance().streamEURUSD(openBid);  <--- so on your right side streamEURUSD(openBid) produces void,
you try to assign void to double - there is the error

The same with other two methods
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

So, what I have to do?
What is the right way?
Avatar of for_yan
for_yan
Flag of United States of America image

What are those values s, b, st - ?
You ahve to know where to get them.

This piece of code does not make much sense:
double[] sell_px;
            double s = Data_EURUSD.getInstance().sellEURUSD(sell_px);

   You just declare this array sell_px - so it is empty - then you call the
method which just prints zero element
and trying to assign the result iof this method - which is nothing as method is void
to double

public void sellEURUSD(double[] sell_px) {

        System.out.println("    >>>>>>>> Data_EURUSD <<<<<<<<     " +
                           "  sell_px[0]  " + sell_px[0]);
    }

This  makes not much sense.

So you need to understand what are those s, b, st and where you can get them from.

Maybe they are lrelated to the query that we were dealiing with in the previous question?




Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

You know, that these variables openBid[0], buy_px[0], sell_px[0] are created into the class SelectData.
I need advice how I can get these values with actionPerformed listener.
As soon I have new value at SelectData this actionPerformed listener has to recognize it.
Please advice.
Avatar of for_yan
for_yan
Flag of United States of America image


You see I don't see the whole picture of your application but I'm afraid your actionPerformed is not what you need.
actionPerformed is a method which is called when user interacts with the interface - say presses the button - do you have any interface and anything like that?
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

I don't agree with you. When  you will see original class( go to the link above), it's no button there.
This is the reason why I like this construction.
They take dynamic vales from return method, which updates all the time when it has new data. No buttons, nothing, like my stream data.
I'm extremely need  your help, because my experience is under this knowledge.
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

Thank you for the idea, I'll try it tomorrow
Avatar of for_yan
for_yan
Flag of United States of America image

Good luck!
Have a nice evening.
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

As always you are right, I make separate class and put there 3 return methods, one for each parameter.
Now it looks like this:
if (s.equals("EUR/USD")) {

                    symbol[0] = s;
                    openBid[0] = bpx;
                    Data_EURUSD.getInstance().addStreamObservation(bpx);
                    timest[0] = tst;
...........
                if (s.equals("EUR/USD"))
                {

                    symbol[0] = s;
                    buy_px[0] = bb;
                    Data_EURUSD.getInstance().addBuyObservation(bb);
                    ts_buy[0] = tsb;
..........

                if (s.equals("EUR/USD")) {


                    symbol[0] = s;
                    sell_px[0] = bs;
                    Data_EURUSD.getInstance().addSellObservation(bs);
                    ts_sell[0] = tss;

Open in new window

public class Data_EURUSD {

    private static final Data_EURUSD INSTANCE = new Data_EURUSD();

    public static Data_EURUSD getInstance() {
        return INSTANCE;
    }

    public Data_EURUSD() {
    }


    /**
     * @return
     */
    public double addStreamObservation(double bpx) {

        System.out.println("    addBuyObservation bpx = " + bpx);

        return bpx;
    }

    /**
     * @return
     */
    public double addBuyObservation(double bb) {

        System.out.println("    addBuyObservation bb = " + bb);

        return bb;
    }

    /**
     * @return
     */
    public double addSellObservation(double bs) {

        System.out.println("    addBuyObservation bs = " + bs);

        return bs;
    }
}

Open in new window

 
double bpx;
        double bb;
        double bs;
        
        public void actionPerformed(ActionEvent event) {

            double s = Data_EURUSD.getInstance().addSellObservation(bs);
            double b = Data_EURUSD.getInstance().addBuyObservation(bb);
            double st = Data_EURUSD.getInstance().addStreamObservation(bpx);
            
            addStreamObservation(st);   
            addBuyObservation(b);
            addSellObservation(s);
        }   
    }

Open in new window

Only the problem now is how to filter zero values?
addBuyObservation bpx = 1.36285
    addBuyObservation bb = 1.36328
    addBuyObservation bs = 1.36281
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bpx = 1.36285
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bpx = 1.36277
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0

Open in new window

Avatar of for_yan
for_yan
Flag of United States of America image

So why are you getting zeroes?

And you still didn't explain to me what system/server/machinery supplies the events to you in order to fire actionPerformed method?
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

For me it's very strange, when I start application without chart window I have normal output from Data_EURUSD class.
As soon I start chart window in starts generate avalanche of zero outputs and on chart I see only these zero values.
CLEANUP : Available Connections : 4
          switch on the Timer
=>
    addBuyObservation bpx = 1.36576
   Symbol  EUR/USD  openBid[0]  1.36576    timest[0]    2011-10-11 16:33:07.0
    addBuyObservation bb = 1.366
>>>>>> BUY <<<<<<<   Symbol  EUR/USD    ts_buy[0]    2011-10-11 19:30:00.494   buy_px[0]  1.366
    addBuyObservation bs = 1.36551
>>>>>> SELL <<<<<<<   Symbol  EUR/USD    ts_sell[0]    2011-10-11 19:24:34.766   sell_px[0]  1.36551
    addBuyObservation bpx = 1.36574
   Symbol  EUR/USD  openBid[0]  1.36574    timest[0]    2011-10-11 16:33:08.0
    addBuyObservation bpx = 1.36574
   Symbol  EUR/USD  openBid[0]  1.36574    timest[0]    2011-10-11 16:33:08.0
    addBuyObservation bpx = 1.36572
   Symbol  EUR/USD  openBid[0]  1.36572    timest[0]    2011-10-11 16:33:09.0
    addBuyObservation bpx = 1.36561
   Symbol  EUR/USD  openBid[0]  1.36561    timest[0]    2011-10-11 16:33:12.0
    addBuyObservation bpx = 1.36561
   Symbol  EUR/USD  openBid[0]  1.36561    timest[0]    2011-10-11 16:33:13.0
Action - flag0c = true
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bpx = 1.36561
   Symbol  EUR/USD  openBid[0]  1.36561    timest[0]    2011-10-11 16:33:13.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bpx = 1.36571
   Symbol  EUR/USD  openBid[0]  1.36571    timest[0]    2011-10-11 16:33:14.0
    addBuyObservation bs = 0.0
    addBuyObservation bb = 0.0
    addBuyObservation bpx = 0.0
    addBuyObservation bs = 0.0

Open in new window

Avatar of for_yan
for_yan
Flag of United States of America image

This is printout from the methods - where are you calling these methods?
Again I see this actionPerformed - and bunch of calls to those methods from there - so you need to understand who and when
calls this method
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

Logically, why I like this model, actionPerformed has to collect only changes of data in Data_EURUSD class return methods, as they show this changes in output before starting chart window, but it provoce generating of zero values and normal(real) values disappear!
Avatar of for_yan
for_yan
Flag of United States of America image

But you can't deal with it as with supernatural force.
You need to know - who and when calls this method.

I'll be away for the next several hours. You have time to think abouut it :)
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

I'm not in a hurry with this question. Let's speak tomorrow. I'll try to experiment with existing code. Just tell me you time zone.
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

I found very strange thing.
I rename methods in Data_EURUSD class and put println() into actionPerformed method and found that it gets zero from getStreamData method, but at the same time this method shows his return data. I even change the way to send data to the getStreamData method, but result is the same.
if (s.equals("EUR/USD")) {

                    symbol[0] = s;
                    openBid[0] = bpx;
                    dataEURUSD.getStreamData(bpx);
//                    Data_EURUSD.getInstance().getStreamData(bpx);
                    timest[0] = tst;

                                        System.out.println("   Symbol  " + symbol[0] +
                                                           "  openBid[0]  " + openBid[0] +
                                                           "    timest[0]    " + timest[0]);

Open in new window

public double getStreamData(double bpx) {

        System.out.println("    getStreamData bpx = " + bpx);

        return bpx;
    }

Open in new window

public void actionPerformed(ActionEvent event) {

//            double s = Data_EURUSD.getInstance().getSellSignal(bs);
//            double b = Data_EURUSD.getInstance().getBuySignal(bb);
            st = Data_EURUSD.getInstance().getStreamData(bpx);
            System.out.println(" >>>>>   actionPerformed st = " + st);
//            addSellObservation(s);
//            addBuyObservation(b);
            addStreamObservation(st);

Open in new window

Symbol  EUR/USD  openBid[0]  1.36767    timest[0]    2011-10-11 17:58:24.0
    getStreamData bpx = 1.36765
   Symbol  EUR/USD  openBid[0]  1.36765    timest[0]    2011-10-11 17:58:26.0
    getStreamData bpx = 1.36762
   Symbol  EUR/USD  openBid[0]  1.36762    timest[0]    2011-10-11 17:58:27.0
Action - flag0c = true
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 1.36767
   Symbol  EUR/USD  openBid[0]  1.36767    timest[0]    2011-10-11 17:58:28.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 1.36766
   Symbol  EUR/USD  openBid[0]  1.36766    timest[0]    2011-10-11 17:58:29.0
    getStreamData bpx = 0.0
 >>>>>   actionPerformed st = 0.0
    getStreamData bpx = 0.0

Open in new window

Why actionPerformed doesn't see this box value?
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

Means that this method doesn't count change of "bpx" value as an event. Maybe I need to specify for this method what means "event" on which it has to act and get changed data, as soon it change?
But how?
Avatar of for_yan
for_yan
Flag of United States of America image

Maybe it fires more often that when some data come.
You need to understand waht casues this actionPerformed to fire

And you can grab your data form whene you get them from slecet statement
Avatar of gbcbr
gbcbr
Flag of Cyprus image

ASKER

This part of question solved.
Thank a lot for the practical help.
Please check for next stage TimeSeries chart questions.
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo