Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

TimeSeriesChat null value

Posted on 2011-10-13
48
Medium Priority
?
284 Views
Last Modified: 2012-05-12
I build TimeSeries chart with three series inside of dataset. But I need from two series insert to chart mark only when arrive new data to this series. Or ignore inserting similar values, means when arrive value identical to previous, renderer has not to draw anything. I read The JFreeChart Class Library
Version 1.0.13
Developer Guide
Written by David Gilbert
but I didn't find this option. Please advice, maybe I just can't find it
public class TimeSeriesEURUSD extends JFrame {

    public static final TimeSeriesEURUSD INSTANCE = new TimeSeriesEURUSD();

    public static TimeSeriesEURUSD getInstance() {
        return INSTANCE;
    }

    public TimeSeriesEURUSD() {

        setContentPane(chartPanel);
        setSize(1800, 800);
        setVisible(true);
    }

    TimeSeries s1 = new TimeSeries("s1");
    TimeSeries s2 = new TimeSeries("s2");
    TimeSeries s3 = new TimeSeries("s3");

    int sc1 = 0;
    int sc2 = 0;
    int sc3 = 0;

    public void doEvent(double bpx, double bb, double bs) {

        System.out.println("    createDataset  >>>>>>>   bpx = " + bpx +
                           "   bb = " + bb + "   bs = " + bs);

        sc1++;
        sc2++;
        sc3++;


        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bpx));
        s2.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bb));
        s3.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bs));

        if (sc1 > 1800) {
            s1.delete(0, 0);
        }

        if (sc2 > 100) {
            s2.delete(0, 0);
        }

        if (sc3 > 100) {
            s3.delete(0, 0);
        }
    }

    private JFreeChart createChart(XYDataset dataset) {

        JFreeChart chart =
            ChartFactory.createTimeSeriesChart("EUR/USD", // title
                "Time", // x-axis label
                "EUR/USD Bot Signals", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false); // generate URLs?

        chart.setBackgroundPaint(Color.white);

        chart.addSubtitle(new TextTitle("Bot Statistics for EUR/USD"));

        XYPlot plot = (XYPlot)chart.getPlot();

        plot.setBackgroundPaint(Color.lightGray);

        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

        plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);

        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, false);
        renderer.setSeriesLinesVisible(1, false);
        renderer.setSeriesShapesVisible(1, true);
        renderer.setSeriesLinesVisible(2, false);
        renderer.setSeriesShapesVisible(2, true);
        plot.setRenderer(renderer);

        renderer.setSeriesPaint(0, Color.blue);
        renderer.setSeriesPaint(1, Color.green);
        renderer.setSeriesPaint(2, Color.red);

        DateAxis axis = (DateAxis)plot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss"));

        return chart;
    }

    public XYDataset createDataset() {

        TimeSeriesCollection dataset = new TimeSeriesCollection();

        dataset.addSeries(s1);
        dataset.addSeries(s2);
        dataset.addSeries(s3);

        return dataset;
    }

    public JPanel createDemoPanel() {

        JFreeChart chart = createChart(createDataset());
        ChartPanel panel = new ChartPanel(chart);
        panel.setFillZoomRectangle(true);
        panel.setMouseWheelEnabled(true);

        return panel;
    }

    ChartPanel chartPanel = (ChartPanel)createDemoPanel();


}

Open in new window

Now output looks like this
doEvent  >>>>>>>   bpx = 1.3692   bb = 1.37011   bs = 1.36953
    doEvent  >>>>>>>   bpx = 1.36913   bb = 1.37011   bs = 1.36953
    doEvent  >>>>>>>   bpx = 1.36913   bb = 1.37011   bs = 1.36889
>>>>>> SELL <<<<<<<   Symbol  EUR/USD    ts_sell[0]    2011-10-13 17:16:46.169   sell_px[0]  1.36889
    doEvent  >>>>>>>   bpx = 1.36919   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36919   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36916   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36916   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36915   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36915   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36915   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36916   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36913   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36912   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36913   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36917   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36913   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36912   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36915   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36922   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36924   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36924   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36925   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36925   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36932   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36944   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36944   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.3694   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36938   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36938   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36943   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36943   bb = 1.37011   bs = 1.36889
    doEvent  >>>>>>>   bpx = 1.36945   bb = 1.37011   bs = 1.36889

Open in new window

 and chart like this  BotStatistics.tiff
0
Comment
Question by:gbcbr
  • 25
  • 23
48 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36962441
This does not need to bein JfreeChart manual or among itsfeatiures - it should be done before - when you prepare data - just ignorer identical data and not ad dthem
0
 

Author Comment

by:gbcbr
ID: 36962449
If I do this, I get NPE
0
 

Author Comment

by:gbcbr
ID: 36962496
If you remember, when I start this question http://www.experts-exchange.com/Programming/Languages/Java/Q_27385500.html
I suppose that dataset has to be filled.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 47

Expert Comment

by:for_yan
ID: 36962535
The dataset should have at least something - if you remove duplicates it still wil have something - this is the issue which has nothing to do wwith JFreeChart - it has to do with hiw you create dataset.

We already went through ignorung the same data - and this is the way to create dataset ignoring duplcate records
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36962705
If you see NPE you ahould catch the exception and print ex.printStackTrace() and locate exact line and snalyze why it happens. If it happens beacuse of bad data - you need to go to the place where data is collected and find the reason of bad or missing data. in such case JfreeChart has nothing to do with iut - it can only draw if we provide valid data
0
 

Author Comment

by:gbcbr
ID: 36962775
I don't understand what data has to be insert into dataset. Any value will be wrong. If we put zero "0", chart will jump down to zero value, if we put null, we have NPE.
I work already two days on this question and still not understand how to avoid renderer from drawing any data on the chart.
It should be some option like if bb0 == bb, setSeriesVisible(false)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36962806
You definitely don't put null into data - that makes no sense. If you need to shoiw valuye zero then you put zero into data. You should not nix it in your mind with JFreeeChart. You should uinderatand your busines requirement and crete data correctly - make a table of ytour data and forgewt about any JfreeChart - make sure youir tablke printout is cortect
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963322
I suggest that you first forget about any chart drawing - that sidetracks the thought.Just at the point where you beklive you have accumulated the data for
drawing - print it out in the form of two columns and inspect it.
If it has something which you don't wnat it to have zeroes, nulls, etc. then think how to weed it out
while accumulating it.

0
 

Author Comment

by:gbcbr
ID: 36963395
You don't understand the question. Means, you understood it wrong.
I don't have problem with data, data is correct. My problem is performing of this data.
If you will open screenshot .tiff you will see red and green LINES, these data have not to be performed on this chart like now. It has to be performed ONLY as  a DOT, at the moment when this data changed to the new value.
I try to use this construction
public void doEvent(double bpx, double bb, double bs) {

        System.out.println("    doEvent  >>>>>>>   bpx = " + bpx +
                           "   bb = " + bb + "   bs = " + bs);

        sc1++;
        sc2++;
        sc3++;
        
          for (int j = 2; j > 0; j--) {

              cbb[j] = cbb[j - 1];
              cbs[j] = cbs[j - 1];
          } 
          
              cbb[j] = bb;
              cbs[j] = bs;

.................


public class TimeSeriesEURUSD extends JFrame {

    public static final TimeSeriesEURUSD INSTANCE = new TimeSeriesEURUSD();

    /**
     * @return
     */
    public static TimeSeriesEURUSD getInstance() {
        return INSTANCE;
    }


    public TimeSeriesEURUSD() {

        setContentPane(chartPanel);
        setSize(1800, 800);
        setVisible(true);
    }

    TimeSeries s1 = new TimeSeries("s1");
    TimeSeries s2 = new TimeSeries("s2");
    TimeSeries s3 = new TimeSeries("s3");


    int sc1 = 0;
    int sc2 = 0;
    int sc3 = 0;
    
    double[] cbb = new double[3];
    double[] cbs = new double[3];
    int j;

    public void doEvent(double bpx, double bb, double bs) {

        System.out.println("    doEvent  >>>>>>>   bpx = " + bpx +
                           "   bb = " + bb + "   bs = " + bs);

        sc1++;
        sc2++;
        sc3++;
        
          for (int j = 2; j > 0; j--) {

              cbb[j] = cbb[j - 1];
              cbs[j] = cbs[j - 1];
          } 
          
              cbb[j] = bb;
              cbs[j] = bs;
          
              
      System.out.println("    doEvent  >>>>>>>   cbb[0] = " + cbb[0] +
                         "   cbb[1] = " + cbb[1] + "    cbs[0] = " + cbs[0]  + "   cbs[1] = " + cbs[1]);

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bpx));
        s2.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bb));
        s3.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bs));
        
        if (sc1 > 1800) {
            s1.delete(0, 0);
        }

        if (sc2 > 100) {
            s2.delete(0, 0);
        }

        if (sc3 > 100) {
            s3.delete(0, 0);
        }
    }


    private JFreeChart createChart(XYDataset dataset) {

        JFreeChart chart =
            ChartFactory.createTimeSeriesChart("EUR/USD", // title
              ...
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesLinesVisible(0, true);
        renderer.setSeriesShapesVisible(0, false);
        
        
        if (cbb[0] == cbb[1])
        {
        renderer.setSeriesLinesVisible(1, false);
        renderer.setSeriesShapesVisible(1, false);
        }
        
        else {
            renderer.setSeriesLinesVisible(1, false);
            renderer.setSeriesShapesVisible(1, true);
        }

        if (cbs[0] == cbs[1])
        {
        renderer.setSeriesLinesVisible(2, false);
        renderer.setSeriesShapesVisible(2, false);
        }
        
      else {
        renderer.setSeriesLinesVisible(2, false);
        renderer.setSeriesShapesVisible(2, true);
      }
        plot.setRenderer(renderer);

Open in new window

but it doesn't work. Just remove these two timeseries from chart.
0
 

Author Comment

by:gbcbr
ID: 36963419
So, this chart has to look like blue line chart, which present current rate and red and green dots on this blue line which mark(show) bot signals to buy or to sell.
This is my final target.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963441
I don't see any screenshot.
0
 

Author Comment

by:gbcbr
ID: 36963447
BotStatistics.tiff attached to initial question
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963517
Buy and Sell are just points in time - correct?

Where od you want to put the dots in terms of the second coordinate?
Do you want them to sit on the blue line itsels?

If so - you take the set of  buy time coordinates  - then assign the second corrdinate for each time as the values of the second coordinate
for this time in your blue data and then you get dataset - you add this series in normal way
but then say
 renderer.setSeriesLinesVisible(num_of_series, false);
so it will not connect these dots but just draw them as separate dots like in this examples:
http://www.java2s.com/Code/Java/Chart/JFreeChartLineChartDemo6.htm


0
 

Author Comment

by:gbcbr
ID: 36963576
This is dynamic chart, so all performances have to be arranged automatically.
I'll try to use XYDotRenderer, maybe this can help.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963604
don't understand what you mean by "performances"
but once you supply data, and let her darw the cahrt it wll draw it;
you got new data, recreated the charts - it will show new data.
If your data are changing asay once a few seconds I think it will keep up.
If the data are changing many times a second it may be a problem,
as JFreeChart (like actually almost any Java component) redraws the whole panel every time
0
 

Author Comment

by:gbcbr
ID: 36963637
>>>you got new data, recreated the charts - it will show new data.
I don't want to see new data, if it's similar to previous.
Performances, I mean drawing this useless, garbage data on the chart.
I need only signal value presented on this chart, but not this permanent "noise" data, this "noise" data has to be filtered.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963690
again, we return to the same thing.
you know what you consider to be noise data, JFreeChart - does not, each point is just a point to JFreChart.
So if there is some data which you believe is noise - analyze it before you add to dataset
and don't add it to dataset if this point is a noise
0
 

Author Comment

by:gbcbr
ID: 36963727
Noise, I mean repeated data, this data was actual at the moment when it was issued, next second it starts to be "noise"
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963783
at each mioment before drawing edit (or re-create) dataset - whatever you consider garbage at the moment of editing - remove it,
whatever you consider good at the moment of editing will be drawn
0
 

Author Comment

by:gbcbr
ID: 36963792
>>> whatever you consider garbage at the moment of editing - remove it,
when I remove it ==>>>>NPE
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963820
Again, check - find the line where you have NPE - and understand why it happens - it does not happen just because you removed some point
from your data - maybe you added some null or something - but be reasonable - whta maeans - "when I remlove it - NPE" - that's why I'm saying -
find the line, print the data in the plain text before putting them into dataset - either you put null in the data or it maybe some other issue just coincidence with you removing it is a matter of normal debugging - just because you removed any point from the data you cannot get error
0
 

Author Comment

by:gbcbr
ID: 36963875
I repeat. Whatever data I'll put in dataset NEXT SECOND after real data coning, is the wrong. The question not in the data, question is printing(drawing) data only ONCE. The table which you suggest has to look like this:
bb = 1.37011;
bb = null;
bb = null;
bb = null;
bb = null;
bb = null;
bb = null;
bb = 1.37035;
bb = null;
bb = null;
bb = null;
But this table generates NPE

and this table:

bb = 1.37011;
bb = 1.37011;
bb = 1.37011;
bb = 1.37011;
bb = 1.37011;
bb = 1.37035;
bb = 1.37035;
bb = 1.37035;
bb = 1.37035;
bb = 1.37035;

generate noise
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36963940
Before every drawing you should create again the series
and add only those points which are meaningful:

something like that:

double bb0 = -1.0;

  TimeSeries s2 = new TimeSeries("s2");

loop through all points:
    if(bb == bb0) continue;
    s2.add(new FixedMillisecond(new Date().getTime()),
                       new Float(bb));
    bb0 = bb;
end of loop



0
 

Author Comment

by:gbcbr
ID: 36963949
thank you, I'll try tomorrow
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36964290
well, good night and good luck (tomorrow)!
0
 

Author Comment

by:gbcbr
ID: 36966726
         if(bb == bb0) continue; >>>>>>>>>>>Error(94, 25): continue outside of loop
         
          s2.add(new FixedMillisecond(new Date().getTime()),
                             new Float(bb));
          bb0 = bb;
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36966744
Look, but not put continue outside the loop

loop through all points:  <---- this is loop throuugh all points - I don't know what particular loop it is , but you need to go through all points
    if(bb == bb0) continue;
    s2.add(new FixedMillisecond(new Date().getTime()),
                       new Float(bb));
    bb0 = bb;
end of loop  <---- this is edn of loop through the points

0
 

Author Comment

by:gbcbr
ID: 36973484
Please explain what you mean
>>loop through all points:  <---- this is loop throuugh all points - I don't know what particular loop it is , but you need to go through all points

For this particular case I have only bb incoming data, when I compare with previous case

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;

Open in new window

0
 

Author Comment

by:gbcbr
ID: 36973493
I don't see any difference.
public void doEvent(double bpx, double bb, double bs) {

        System.out.println("    doEvent  >>>>>>>   bpx = " + bpx +
                           "   bb = " + bb + "   bs = " + bs);

        sc1++;
        sc2++;
        sc3++;
        
//          for (int j = 2; j > 0; j--) {
//
//              cbb[j] = cbb[j - 1];
//              cbs[j] = cbs[j - 1];
//          } 
//          
//              cbb[j] = bb;
//              cbs[j] = bs;
//          
//              
//      System.out.println("    doEvent  >>>>>>>   cbb[0] = " + cbb[0] +
//                         "   cbb[1] = " + cbb[1] + "    cbs[0] = " + cbs[0]  + "   cbs[1] = " + cbs[1]);

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bpx));
        
        double bb0 = -1.0;

        TimeSeries s2 = new TimeSeries("s2");

        if(bb == bb0) {
              
              continue;
          
          s2.add(new FixedMillisecond(new Date().getTime()),
                             new Float(bb));
          bb0 = bb;
        }

//        double bs0 = -1.0;

//        TimeSeries s3 = new TimeSeries("s3");

//        if (bs == bs0)
//            continue;
        s3.add(new FixedMillisecond(new Date().getTime()), new Float(bs));
//        bs0 = bs;

Open in new window

Please explain what you mean
>> but you need to go through all points
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36974025
Before each drawing of the plot you need to craete dataset, add series and then draw the plot. When you are creating data set you are adding oounts tio dataset. Adding points to dataset is the loop where youi are going through points and adding them. In the proces of doing it - yiu should comparer current point with the previouis one using the ideology which I showed yiu above and if current point is identical with the previous one or if current ppoint reperesents any other ttype of junk - just skip it.
0
 

Author Comment

by:gbcbr
ID: 36978344
What means loop?
As I understand from your statement, loop for this parameter 'bb' starts after
if (bb == bb0)

and finished at bb0 = bb;
Please advice
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36978351
Loop is what is inside

while{

}

or

for (...) {


}

 

Please, post the place where you populate the dataset
for drawing the plot

0
 

Author Comment

by:gbcbr
ID: 36978364
public class XYChartEURUSD extends JFrame {

    private String title;

    public static final XYChartEURUSD INSTANCE = new XYChartEURUSD();


    public static XYChartEURUSD getInstance() {
        return INSTANCE;
    }

    public XYChartEURUSD() {
        //        super(title);
        setContentPane(chartPanel);
        setSize(1200, 800);
        setVisible(true);
    }
 
    TimeSeries s1;
    TimeSeries s2;
    TimeSeries s3;

    int sc1 = 0;
    int sc2 = 0;
    int sc3 = 0;
    
//  double bb0 = -1.0;
//  double bs0 = -1.0;

    public void doEvent(double bpx, double bb, double bs) {

        sc1++;
        sc2++;
        sc3++;
        
        if (bb != 0 && bs != 0){
            
    s1 = new TimeSeries("s1");
    
    s2 = new TimeSeries("s2");
    
    double bb0 = -1.0;  
                

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bpx));
        
//        if (bb == bb0){
                    


        s2.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bb));
       
//            bb0 = bb;
            
//        }
        
         s3 = new TimeSeries("s3");
           double bs0 = -1.0;
        
//        if (bs == bs0){

        

        s3.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bs));

//            bs0 = bs;
//        }
            
        System.out.println("    doEvent  >>>>>>>   bpx = " + bpx + "   bb = " +
                           bb + "   bs = " + bs);
      System.out.println();

        }

        if (sc1 > 1800) {
            s1.delete(0, 0);
        }
        else if (sc2 > 1800){
            s2.delete(0, 0);
        }
        else if (sc3 > 1800){
         s3.delete(0, 0);
        }
    }

//    transient XYItemRenderer r;

        private JFreeChart createChart(XYDataset dataset) {

        JFreeChart chart =
            ChartFactory.createTimeSeriesChart("EUR/USD", // title
                "Time", // x-axis label
                "EUR/USD", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false); // generate URLs?

        chart.setBackgroundPaint(Color.yellow);
        chart.addSubtitle(new TextTitle("Bot Statistics for EUR/USD"));

        XYPlot plot = chart.getXYPlot();


        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.blue);
        plot.setRangeGridlinePaint(Color.blue);

        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);

        XYItemRenderer renderer = plot.getRendererForDataset(dataset);
        
        renderer.setBaseSeriesVisible(true);
        renderer.setSeriesPaint(0, Color. blue);

        DateAxis axis = (DateAxis)plot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss"));

        // Dataset2

        XYDataset dataset2 = createDataset2();

        plot.setDataset(1, dataset2);
        plot.mapDatasetToRangeAxis(0, 1);
        XYItemRenderer renderer2 = new XYLineAndShapeRenderer();
        renderer2.setSeriesPaint(0, Color.green);
        plot.setRenderer(1, renderer2);

        // Dataset3

        XYDataset dataset3 = createDataset3();

        plot.setDataset(2, dataset3);
        plot.mapDatasetToRangeAxis(0, 2);
        XYItemRenderer renderer3 = new XYLineAndShapeRenderer();
        renderer3.setSeriesPaint(0, Color.red);
        plot.setRenderer(2, renderer3);

        return chart;
    }

    private XYDataset createDataset() {

        TimeSeriesCollection dataset = new TimeSeriesCollection();

        dataset.addSeries(s1);

        return dataset;
    }

    private XYDataset createDataset2() {

        TimeSeriesCollection dataset2 = new TimeSeriesCollection();

        dataset2.addSeries(s2);

        return dataset2;
    }

    private XYDataset createDataset3() {

        TimeSeriesCollection dataset3 = new TimeSeriesCollection();

        dataset3.addSeries(s3);

        return dataset3;
    }

    public JPanel createDemoPanel() {
        JFreeChart chart = createChart(createDataset());
        ChartPanel panel = new ChartPanel(chart);
        panel.setFillZoomRectangle(true);
        panel.setMouseWheelEnabled(true);

        return panel;
    }
    ChartPanel chartPanel = (ChartPanel)createDemoPanel();

}

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36978435
I'm sorry, I can't understand.

Well, you do not know who or what calls doEvent() method
but as I understadn doEvent() is called each time you add a new point to each of the three series.
Is it so?

If so, then why  you create the series themselves
with these kind of operations
 s1 = new TimeSeries("s1");
every time doEvent() is called?

0
 

Author Comment

by:gbcbr
ID: 36978519
These data come from previous solved question
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 "); //union all " +

            for (DataStream data : dataList) {

                String s;
               
                Timestamp tst;

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

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

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

                    XYChartEURUSD.getInstance().doEvent(bpx, bb, bs);

                    timest[0] = tst;
...............

        try {


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

            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;

                    XYChartEURUSD.getInstance().doEvent(bpx, bb, bs);

                    ts_buy[0] = tsb;
.................

        try {

            List<DataSell> dataList =
                conn.selectSell("SELECT * FROM EURUSD_BOT_SELL where ts = ( select max( ts ) from EURUSD_BOT_SELL ) and rownum = 1 "); //union all " +
      
            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;

                    XYChartEURUSD.getInstance().doEvent(bpx, bb, bs);

                    ts_sell[0] = tss;

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36978584
dut how often does doEvent() execute?
does it exceute once for every point in the series?

TimeSeries as I understand is the whole set of points.

If so, I can't understand, how it can run

 s1 = new TimeSeries("s1");
   
 every time you have non-zero values.

We need to understand bigger picture of your application.
 
0
 

Author Comment

by:gbcbr
ID: 36978675
SelectData class collect data from DB  
public static void main(String[] args) throws Exception {

        chartControl = new ChartControl();
        callSelect();
    }


    /**
     * @throws Exception
     */
    public static void callSelect() throws Exception {
        try {
            timer = new Timer();
            timer.schedule(new SelectData(), 10000, 1000);

Open in new window

When data selected they separated by currency pairs, even create an array is unnecessary, because we need only bb value and we filter it by symbol, so it may look like this:
 
if (s.equals("EUR/USD")) {

                    XYChartEURUSD.getInstance().doEvent(bpx, bb, bs);

Open in new window

Before it was one dataset with three data series, but in view that we have to play with each one separately, I split them on three different datasets, but place them on one plot with one axis for all of them.
That's all.
Now I need put only changed data to each dataset, but if dataset will be empty, it may generate NPE.
OK, 's1' always has fresh data, so we don't need to touch it, but 's2' and 's3' most of the time has identical data, because data chained only when bot generate buy or sell signal, but this may happened ones of 60 seconds and more, so SelectData send to XYChart.doEvent every second identical data which are displayed as a straight horizontal line with dots. So, most of the time I have one real time line chart which shows every second changed real rate and two horizontal line which show last time changed value of 'bb' and 'bs'.
And when bb or bs again changed, line jump to the new level and continue with this value.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36978712
but why do you create new series every call to doEvent() ?
I think series should be created once and befiore and when you call doEvent you just accumulate points
so then when you create series you set these bb0 to -1;
and then add only those bb0 whiche are not zero and not equal to the previous one.
But when the series is created every time so I lose understanding
0
 

Author Comment

by:gbcbr
ID: 36978760
originally I create them once, in sample which I publish I move them down into doEvent method, this is normal view
public class XYChartEURUSD extends JFrame {

    public static final XYChartEURUSD INSTANCE = new XYChartEURUSD();

    public static XYChartEURUSD getInstance() {
        return INSTANCE;
    }

        public XYChartEURUSD() {
        setContentPane(chartPanel);
        setSize(1200, 800);
        setVisible(true);
    }

    TimeSeries s1 = new TimeSeries("s1");
    TimeSeries s2 = new TimeSeries("s2");
    TimeSeries s3 = new TimeSeries("s3");

    int sc1 = 0;
    int sc2 = 0;
    int sc3 = 0;

    public void doEvent(double bpx, double bb, double bs) {

        sc1++;
        sc2++;
        sc3++;
        
        if (bb != 0 && bs != 0){

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bpx));

        s2.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bb));

        s3.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bs));

        System.out.println("    doEvent  >>>>>>>   bpx = " + bpx + "   bb = " +
                           bb + "   bs = " + bs);

Open in new window

0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36978781
This looks normal - so when you create them assign bb0 to -1 and then within the method check not only for zero but also for equality to bb0 and skip if it is eqaul, if not add to series and then reassign bb0 to bb. The same with second parameter, bs, or whatever it is called
0
 

Author Comment

by:gbcbr
ID: 36978806
This part I'm don't understand completely. If bb value is definitely positive, it's impossible bb == bb0, if bb0 = -1.0
Maybe it's need come counter which will keep value of bb0, so we can compare these two values.
0
 

Author Comment

by:gbcbr
ID: 36978937
Thank a lot. This code works
public void doEvent(double bpx, double bb, double bs) {

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bpx));
        
      for (int j = 2; j > 0; j--) {
      
                    cbb[j] = cbb[j - 1];
                    cbs[j] = cbs[j - 1];
                } 
                
                    cbb[j] = bb;
                    cbs[j] = bs;
            
          if (bb != 0 && cbb[0] != cbb[1]){

        s2.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bb));
          }
       if (bs != 0  && cbs[0] != cbs[1]){

        s3.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(bs));
        }

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36980385
Great!
0
 

Author Comment

by:gbcbr
ID: 36980389
Thank you for you help!
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36980455
You are always welcome.
0
 

Author Comment

by:gbcbr
ID: 36980466
As always I have new question, as an extension of previous.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36980507
Don't see where is that?
0
 

Author Comment

by:gbcbr
ID: 36980517
I just now prepare it "Client-server transforming"
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question