title: jfreechart crashes when using Yahoo Finance Quotes
body: <hr>
  
  <h2>QUESTION RESOLVED: solution is changing to JFreeChart v1.0.15</h2>
  
  <hr>
  
  <p>I have a very peculiar problem.</p>
  
  <p>What I have set up is a file that sends a url request to the Yahoo Finance website and then uses the results to draw a JFreeChart in a JFrame.</p>
  
  <p>What I just can't get my head around is the following:</p>
  
  <p><strong>For certain url requests, the JFrame crashes</strong></p>
  
  <p>It starts, but only shows a white screen. Whereas for other requests, my program works fine.</p>
  
  <h2>Example</h2>
  
  <p>For example:</p>
  
  <p>This request: </p>
  
  <pre><code>"http://ichart.yahoo.com/table.csv?s=GOOG&amp;a=0&amp;b=1&amp;c=2011&amp;d=6&amp;e=24&amp;f=2013&amp;g=d&amp;ignore=.csv";
  </code></pre>
  
  <p>works fine.</p>
  
  <p>But this request:</p>
  
  <pre><code>"http://ichart.yahoo.com/table.csv?s=GOOG&amp;a=2&amp;b=1&amp;c=2012&amp;d=6&amp;e=24&amp;f=2013&amp;g=d&amp;ignore=.csv";
  </code></pre>
  
  <p>causes an error.</p>
  
  <p>How is this possible?</p>
  
  <h2>Note</h2>
  
  <p>I know the following:</p>
  
  <ul>
  <li>JFrame crashes but JVM doesn't make note of it (doesn't notice that it crashes)</li>
  <li>Downloading of the stock quotes (the information that JFreeChart uses) goes perfect in both cases</li>
  <li>The code for downloading the data and displaying it in the JFreeChart comes from <a href="http://www.jfree.org/forum/viewtopic.php?f=10&amp;t=24521" rel="nofollow noreferrer">this site</a> (the code posted by <em>RoyW » Sat May 10, 2008 7:52 am</em>).</li>
  <li>The amount of data coming in doesn't seem a problem because in request 1, there are more data points than in request 2</li>
  <li>The way I download the data doesn't matter (I tried both reading directly from the url and I tried saving the <code>.csv</code> file to a folder and then reading from the folder)</li>
  <li>The problem doesn't occur randomly: I've tried launching the JFrame (recompiling the code and then running it) multiple times but the 'wrong' quote crashes the JFrame everytime.</li>
  </ul>
  
  <h2>Extra information</h2>
  
  <p>Something that might have to do with it:</p>
  
  <ul>
  <li>When I launch the graph with a correct quote and I drag the graph around, something weird happens. At a certain interval, it seems every weekend, the candlesticks get smaller and smaller untill they are only a stripe. Then when I drag across the weekend, they become thicker again until they are normal size again. This seems to happen for every weekend. Refer to the following pictures:</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/NYD0c.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/0I7DI.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/Cc7bR.png" alt="enter image description here"></p>
  
  <p>So it got me thinking that it might have something to do with <a href="http://en.wikipedia.org/wiki/Trading_day" rel="nofollow noreferrer">trading days</a>. But this doesn't make any sense either because <strong>1/1/2011</strong> (request 1) falls on a Saturday and <strong>3/1/2012</strong> (request 2) falls on a Thursday while request 1 was successful and request 2 failed.</p>
  
  <p>I am absolutely clueless as to what I should do.</p>
  
  <p>All help greatly appreciated.</p>
  
  <h2>Update</h2>
  
  <p>On request, here is the <a href="http://sscce.org/" rel="nofollow noreferrer">SSCCE</a> with <a href="https://stackoverflow.com/users/230513/trashgod">trashgod</a>'s suggestions (using JFreechart lib v1.0.14).</p>
  
  <pre><code>    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 some setting up, see the API Doc
              renderer.setSeriesPaint(0, Color.BLACK);
              renderer.setDrawVolume(false);
              rangeAxis.setAutoRangeIncludesZero(false);
              domainAxis.setTimeline( SegmentedTimeline.newMondayThroughFridayTimeline() );
  
              //Now create the chart and 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 is the dataset we are going to create
              DefaultOHLCDataset result = null;
              //This is the data needed for the dataset
              OHLCDataItem[] data;
  
              //This is where we go get the data, replace with your own data source
              data = getData(stockSymbol);
  
              //Create a dataset, an Open, High, Low, Close dataset
              result = new DefaultOHLCDataset(stockSymbol, data);
  
              return result;
          }
          //This method uses yahoo finance to get the OHLC data
          protected OHLCDataItem[] getData(String stockSymbol) {
              List&lt;OHLCDataItem&gt; dataItems = new ArrayList&lt;OHLCDataItem&gt;();
              try {
                  String strUrl= "http://ichart.finance.yahoo.com/table.csv?s=GOOG&amp;a=2&amp;b=1&amp;c=2012&amp;d=6&amp;e=24&amp;f=2013&amp;g=d&amp;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 from Yahoo is from newest to oldest. Reverse so it is oldest to newest
              Collections.reverse(dataItems);
  
              //Convert the list into an 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);
                  }
              });
          }
      }
  </code></pre>
  
  <p>This generates a JFrame that displays nothing but a white screen. Try changing the <code>strUrl</code> to </p>
  
  <pre><code> "http://ichart.finance.yahoo.com/table.csv?s=GOOG&amp;a=0&amp;b=1&amp;c=2011&amp;d=6&amp;e=24&amp;f=2013&amp;g=d&amp;ignore=.csv";
  </code></pre>
  
  <p>and you will notice that it works fine.</p>
  
  <h2>Update</h2>
  
  <p><strong>Solved it!</strong> The problem was the JFreeChart version. Changing from v1.0.14 to v1.0.15 solved everything. Kudos to <a href="https://stackoverflow.com/users/230513/trashgod">trashgod</a> for (unknowingly) solving my issue by answering extensively <em>and mentioning the library version</em> used. </p>
  
  <p>Does anybody know how I can help others that are having the same issue? Is there a portal somewhere where I can make note of this bug?</p>