From: SourceForge.net <no...@so...> - 2008-05-12 15:53:26
|
Bugs item #1962472, was opened at 2008-05-12 15:53 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=1962472&group_id=15494 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: David Gilbert (mungady) Assigned to: David Gilbert (mungady) Summary: CandlestickRenderer tooltips Initial Comment: >From the forum: http://www.jfree.org/phpBB2/viewtopic.php?t=24597 Text copied below: The CandlestickRenderer adds entities with the area of the "filled" candle. If the open == close then this area is zero pixels high so cannot generate a tooltip. I suggest (If using entities) that the Shape for the tootip be the Max/Min of Open/Close/High/Low/ instead of just the max/min of open/close. This demo highlights the problem. Try hovering over March 28 or April 24... Code: import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.SegmentedTimeline; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.CandlestickRenderer; import org.jfree.data.xy.AbstractXYDataset; import org.jfree.data.xy.DefaultOHLCDataset; import org.jfree.data.xy.OHLCDataItem; import org.jfree.data.xy.XYDataset; import javax.swing.*; import java.awt.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.List; public class CandlestickDemo extends JFrame { public CandlestickDemo(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); 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<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>(); try { String strUrl= "http://ichart.finance.yahoo.com/table.csv?s="+stockSymbol+"&a=2&b=1&c=2003&d=3&e=28&f=2003&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) { new CandlestickDemo("MSFT").setVisible(true); } } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=1962472&group_id=15494 |
From: SourceForge.net <no...@so...> - 2008-05-13 12:13:32
|
Bugs item #1962472, was opened at 2008-05-12 15:53 Message generated for change (Comment added) made by mungady You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=1962472&group_id=15494 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: General Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: David Gilbert (mungady) Assigned to: David Gilbert (mungady) Summary: CandlestickRenderer tooltips Initial Comment: >From the forum: http://www.jfree.org/phpBB2/viewtopic.php?t=24597 Text copied below: The CandlestickRenderer adds entities with the area of the "filled" candle. If the open == close then this area is zero pixels high so cannot generate a tooltip. I suggest (If using entities) that the Shape for the tootip be the Max/Min of Open/Close/High/Low/ instead of just the max/min of open/close. This demo highlights the problem. Try hovering over March 28 or April 24... Code: import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.SegmentedTimeline; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.CandlestickRenderer; import org.jfree.data.xy.AbstractXYDataset; import org.jfree.data.xy.DefaultOHLCDataset; import org.jfree.data.xy.OHLCDataItem; import org.jfree.data.xy.XYDataset; import javax.swing.*; import java.awt.*; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import java.util.List; public class CandlestickDemo extends JFrame { public CandlestickDemo(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); 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<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>(); try { String strUrl= "http://ichart.finance.yahoo.com/table.csv?s="+stockSymbol+"&a=2&b=1&c=2003&d=3&e=28&f=2003&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) { new CandlestickDemo("MSFT").setVisible(true); } } ---------------------------------------------------------------------- >Comment By: David Gilbert (mungady) Date: 2008-05-13 12:13 Message: Logged In: YES user_id=112975 Originator: YES Fixed for the upcoming 1.0.10 release. Regards, Dave Gilbert JFreeChart Project Leader ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=115494&aid=1962472&group_id=15494 |