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.
gbcbrAsked:
Who is Participating?
 
for_yanCommented:
You see teh point of actionListener the way I know it - is that it helps with intaerctaion
with the GUI and there is additional thing - call it Swing, AWT, or whatever - which provides these events and
and call this actipnPerformed when event happens.
Do you have such mechanism? What serevre entity provides these events and what information is contained in that event,
as it happend with the interface (where event it self can tell you what button was pushed, etc) ?
If you have , explain what it is.

In fact in your case, as I understadn it you just
make quesries to databses and receive data from database - sop ass soon as you receive you should populate your observations,
something like this:
My guess is that  you need to collect your data from the very place with which we were dealing yesterday
as soon as you retrieve your data from database you should populate your arrays.
Somewhere here:
       symbol[0] = s;
                    buy_px[0] = bb;
 addBuyObservation(bb);
                    ts_buy[0] = tsb;


                    symbol[0] = s;
                    sell_px[0] = bs;
      addSellObservation(bs);

                    ts_sell[0] = tss;

If not, then please explauin what is this listenere, what it can listen for and what entitity
provides the event to which it listens







0
 
for_yanCommented:
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.

0
 
gbcbrAuthor Commented:
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!
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
for_yanCommented:


 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
0
 
gbcbrAuthor Commented:
So, what I have to do?
What is the right way?
0
 
for_yanCommented:
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?




0
 
gbcbrAuthor Commented:
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.
0
 
for_yanCommented:

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?
0
 
gbcbrAuthor Commented:
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.
0
 
gbcbrAuthor Commented:
Thank you for the idea, I'll try it tomorrow
0
 
for_yanCommented:
Good luck!
Have a nice evening.
0
 
gbcbrAuthor Commented:
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

0
 
for_yanCommented:
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?
0
 
gbcbrAuthor Commented:
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

0
 
for_yanCommented:
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
0
 
gbcbrAuthor Commented:
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!
0
 
for_yanCommented:
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 :)
0
 
gbcbrAuthor Commented:
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.
0
 
gbcbrAuthor Commented:
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?
0
 
gbcbrAuthor Commented:
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?
0
 
for_yanCommented:
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
0
 
gbcbrAuthor Commented:
This part of question solved.
Thank a lot for the practical help.
Please check for next stage TimeSeries chart questions.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.