Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jfreechart: How exclude weekend days from chart?

  1. How exclude one or two day from jfreechart? I have input date without saturday and chart without saturday, but in axis there all date.
  2. I have all added item on screen. How viewing <= 100 item on screen and if scrolling to right item add more.

UPDATE: I make CandleChart, used JfreeChart library. Between 12 and 14 days chart should not be interrupted.

enter image description here

This is string: One or few day is maybe off-time.

12.10.2012 19:00    1.2951  1.296   1.2947  1.2956
12.10.2012 20:00    1.2956  1.296   1.295   1.2954
**12.10.2012 21:00  1.2955  1.2959  1.2948  1.2949**
**14.10.2012 22:00  1.2952  1.296   1.2948  1.2953** 
14.10.2012 23:00    1.2955  1.2955  1.2942  1.2947

This is code:

    static TimeSeries t1 = new TimeSeries("");
    RegularTimePeriod day = new Day();
    RegularTimePeriod hour = new Hour();
private static OHLCDataset createPriceDataset(String FILENAME_SD)
        {   
            OHLCSeries s1 = new OHLCSeries(FILENAME_SD);

                if (!Environment.getExternalStorageState().equals(
                    Environment.MEDIA_MOUNTED)) {

                }
                File sdPath = Environment.getExternalStorageDirectory();
                sdPath = new File(sdPath.getAbsolutePath() + "/" + DIR_SD);
                File sdFile = new File(sdPath, FILENAME_SD);
            try {
                BufferedReader in = new BufferedReader(new FileReader(sdFile));
                DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
                String inputLine;

                in.readLine();
                while ((inputLine = in.readLine()) != null) {
                     String[] data = inputLine.split("\\s+");                    
                     Date date = df.parse(data[0] + " " + data[1]);                  
                    double open     = Double.parseDouble( data[2] );
                    double high     = Double.parseDouble( data[3]  );
                    double low      = Double.parseDouble( data[4]  );
                    double close    = Double.parseDouble( data[5]  );
                   // double volume   = Double.parseDouble( st.nextToken() );
                    //double adjClose = Double.parseDouble( st.nextToken() );
                    s1.add(new Hour(date), open, high, low, close);
                    t1.add(new Hour(date), open);      
                }    
                in.close();              
            }
            catch (Exception e) {
                e.printStackTrace();
            }



            OHLCSeriesCollection dataset = new OHLCSeriesCollection();
            dataset.addSeries(s1);
            return dataset;
        }

Also, diagram zoom depends on how mach string in file. How drawing candles no more than 100 on screen?

This is chart from file with many strings:

enter image description here

This is chart from file with few strings: enter image description here

like image 228
Denis S. Avatar asked Nov 04 '22 11:11

Denis S.


1 Answers

If it's particularly candlestick you want to do this with, I do not believe that JFreechart class supports it. You could use Box And Whisker to imitate the behavior while using category based data. For the charts you've shown the axis represents continuous data, categorical axis are for discrete data.

Example code is shown here: http://www.java2s.com/Code/Java/Chart/JFreeChartBoxAndWhiskerDemo.htm

With that you can choose your own discrete points to be represented on the graph.

If it's for anything other than candlesticks, Graham was right and DefaultCategoryDataset would be more useful: http://www.jfree.org/jfreechart/api/javadoc/org/jfree/data/category/DefaultCategoryDataset.html

like image 165
John at TimeStored Avatar answered Nov 08 '22 05:11

John at TimeStored