java - jfreechart crashes when using Yahoo Finance Quotes -



question resolved: solution changing jfreechart v1.0.15


i have peculiar problem.

what have set file sends url request yahoo finance website , uses results draw jfreechart in jframe.

what can't head around following:

for url requests, jframe crashes

it starts, shows white screen. whereas other requests, program works fine.

example

for example:

this request:

"http://ichart.yahoo.com/table.csv?s=goog&a=0&b=1&c=2011&d=6&e=24&f=2013&g=d&ignore=.csv"; 

works fine.

but request:

"http://ichart.yahoo.com/table.csv?s=goog&a=2&b=1&c=2012&d=6&e=24&f=2013&g=d&ignore=.csv"; 

causes error.

how possible?

note

i know following:

  • jframe crashes jvm doesn't make note of (doesn't notice crashes)
  • downloading of stock quotes (the information jfreechart uses) goes perfect in both cases
  • the code downloading data , displaying in jfreechart comes this site (the code posted royw » sat may 10, 2008 7:52 am).
  • the amount of data coming in doesn't seem problem because in request 1, there more data points in request 2
  • the way download data doesn't matter (i tried both reading directly url , tried saving .csv file folder , reading folder)
  • the problem doesn't occur randomnly: i've tried launching jframe (recompiling code , running it) multiple times 'wrong' quote crashes jframe everytime.

extra information

something might have it:

  • when launch graph correct quote , drag graph around, weird happens. @ interval, seems every weekend, candlesticks smaller , smaller untill stripe. when drag across weekend, become thicker again until normal size again. seems happen every weekend. refer following pictures:

enter image description here enter image description here enter image description here

so got me thinking might have trading days. doesn't make sense either because 1/1/2011 (request 1) falls on saturday , 3/1/2012 (request 2) falls on thursday while request 1 successful , request 2 failed.

i absolutely clueless should do.

all appreciated.

update

on request, here sscce trashgod's suggestions (using jfreechart lib v1.0.14).

    import org.jfree.chart.*;     import org.jfree.chart.axis.*;     import org.jfree.chart.plot.xyplot;     import org.jfree.chart.renderer.xy.candlestickrenderer;     import org.jfree.data.xy.*;      import javax.swing.*;     import java.awt.*;     import java.io.*;     import java.net.url;     import java.text.*;     import java.util.*;     import java.util.list;      public class candlestickdemo2 extends jframe {         public candlestickdemo2(string stocksymbol) {             super("candlestickdemo");             this.setdefaultcloseoperation(jframe.exit_on_close);              dateaxis    domainaxis       = new dateaxis("date");             numberaxis  rangeaxis        = new numberaxis("price");             candlestickrenderer renderer = new candlestickrenderer();             xydataset   dataset          = getdataset(stocksymbol);              xyplot mainplot = new xyplot(dataset, domainaxis, rangeaxis, renderer);              //do setting up, see api doc             renderer.setseriespaint(0, color.black);             renderer.setdrawvolume(false);             rangeaxis.setautorangeincludeszero(false);             domainaxis.settimeline( segmentedtimeline.newmondaythroughfridaytimeline() );              //now create chart , chart panel             jfreechart chart = new jfreechart(stocksymbol, null, mainplot, false);             chartpanel chartpanel = new chartpanel(chart, false);             chartpanel.setpreferredsize(new dimension(600, 300));              this.add(chartpanel);             this.pack();         }         protected abstractxydataset getdataset(string stocksymbol) {             //this dataset going create             defaultohlcdataset result = null;             //this data needed dataset             ohlcdataitem[] data;              //this go data, replace own data source             data = getdata(stocksymbol);              //create dataset, open, high, low, close dataset             result = new defaultohlcdataset(stocksymbol, data);              return result;         }         //this method uses yahoo finance ohlc data         protected ohlcdataitem[] getdata(string stocksymbol) {             list<ohlcdataitem> dataitems = new arraylist<ohlcdataitem>();             try {                 string strurl= "http://ichart.finance.yahoo.com/table.csv?s=goog&a=2&b=1&c=2012&d=6&e=24&f=2013&g=d&ignore=.csv";                 url url = new url(strurl);                 bufferedreader in = new bufferedreader(new inputstreamreader(url.openstream()));                 dateformat df = new simpledateformat("y-m-d");                  string inputline;                 in.readline();                 while ((inputline = in.readline()) != null) {                     stringtokenizer st = new stringtokenizer(inputline, ",");                      date date       = df.parse( st.nexttoken() );                     double open     = double.parsedouble( st.nexttoken() );                     double high     = double.parsedouble( st.nexttoken() );                     double low      = double.parsedouble( st.nexttoken() );                     double close    = double.parsedouble( st.nexttoken() );                     double volume   = double.parsedouble( st.nexttoken() );                     double adjclose = double.parsedouble( st.nexttoken() );                      ohlcdataitem item = new ohlcdataitem(date, open, high, low, close, volume);                     dataitems.add(item);                 }                 in.close();             }             catch (exception e) {                 e.printstacktrace();             }             //data yahoo newest oldest. reverse oldest newest             collections.reverse(dataitems);              //convert list array             ohlcdataitem[] data = dataitems.toarray(new ohlcdataitem[dataitems.size()]);              return data;         }          public static void main(string[] args) {             eventqueue.invokelater(new runnable() {                 @override                 public void run() {                     new candlestickdemo2("goog").setvisible(true);                 }             });         }     } 

this generates jframe displays nothing white screen. try changing strurl

 "http://ichart.finance.yahoo.com/table.csv?s=goog&a=0&b=1&c=2011&d=6&e=24&f=2013&g=d&ignore=.csv"; 

and notice works fine.

update

solved it! problem jfreechart version. changing v1.0.14 v1.0.15 solved everything. kudos trashgod (unknowingly) solving issue answering extensively and mentioning library version used.

does know how can others having same issue? there portal somewhere can make note of bug?

candlestickdemo works me v1.0.15 , either of queries. made 2 changes:

  • construct gui on event dispatch thread; failure causes data race non-deterministic results:

    eventqueue.invokelater(new runnable() {     @override     public void run() {         new candlestickdemo("goog").setvisible(true);     } }); 
  • omit backing buffer, although it's irrelevant:

    chartpanel chartpanel = new chartpanel(chart, false); 
  • addendum: reference, looks call paramchecks.nullnotpermitted() applied in r2692, replacing explicit check, renderer otherwise unchanged.

  • addendum: under v1.0.14, example works correctly defaulttimeline of dateaxis, changed substantially in interim.

  • addendum: @david gilbert notes relevant changes may found in r2465.

image


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -