List of usage examples for org.jfree.chart ChartFactory createCandlestickChart
public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, boolean legend)
From source file:ta4jexamples.indicators.CandlestickChart.java
public static void main(String[] args) { /**// w w w . jav a2 s.c o m * Getting time series */ TimeSeries series = CsvTradesLoader.loadBitstampSeries(); /** * Creating the OHLC dataset */ OHLCDataset ohlcDataset = createOHLCDataset(series); /** * Creating the additional dataset */ TimeSeriesCollection xyDataset = createAdditionalDataset(series); /** * Creating the chart */ JFreeChart chart = ChartFactory.createCandlestickChart("Bitstamp BTC price", "Time", "USD", ohlcDataset, true); // Candlestick rendering CandlestickRenderer renderer = new CandlestickRenderer(); renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST); XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); // Additional dataset int index = 1; plot.setDataset(index, xyDataset); plot.mapDatasetToRangeAxis(index, 0); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesPaint(index, Color.blue); plot.setRenderer(index, renderer2); // Misc plot.setRangeGridlinePaint(Color.lightGray); plot.setBackgroundPaint(Color.white); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setAutoRangeIncludesZero(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); /** * Displaying the chart */ displayChart(chart); }
From source file:org.jfree.chart.demo.CandlestickChartDemo1.java
private static JFreeChart createChart(OHLCDataset ohlcdataset) { JFreeChart jfreechart = ChartFactory.createCandlestickChart("Candlestick Demo 1", "Time", "Value", ohlcdataset, true);/* w w w . j a v a 2 s . c om*/ XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setUpperMargin(0.0D); numberaxis.setLowerMargin(0.0D); return jfreechart; }
From source file:SQLite3ToChart.Chart.java
private void chart(ToChartData toChartData, int Xaxis) { String titleChart = "Daily chart of TOPIX"; String timeAxisLabel = "2000 Year"; String valueAxisLabel = "point"; OHLCDataset oHLCDataset = toChartData.toChartData(); JFreeChart chart = ChartFactory.createCandlestickChart(titleChart, timeAxisLabel, valueAxisLabel, oHLCDataset, false);/* w ww . ja v a 2s. com*/ ChartPanel cpanel = new ChartPanel(chart); getContentPane().add(cpanel, BorderLayout.CENTER); File file = new File("./filename_" + Xaxis + ".png"); try { ChartUtilities.saveChartAsPNG(file, chart, Xaxis, 500); } catch (IOException ex) { String msg = "saveChartAsPNG() make Exception "; Logger.getLogger(Chart.class.getName()).log(Level.SEVERE, msg, ex); } }
From source file:com.thecoderscorner.groovychart.chart.CandlestickChart.java
public JFreeChart createChart() { JFreeChart chart = ChartFactory.createCandlestickChart(getTitle(), getTimeAxisLabel(), getValueAxisLabel(), (OHLCDataset) getDataset(), isLegend()); return setExtraProperties(chart); }
From source file:biz.ixnay.pivot.charts.skin.jfree.HighLowChartViewSkin.java
@Override protected JFreeChart createChart() { HighLowChartView chartView = (HighLowChartView) getComponent(); String title = chartView.getTitle(); String horizontalAxisLabel = chartView.getHorizontalAxisLabel(); String verticalAxisLabel = chartView.getVerticalAxisLabel(); boolean showLegend = chartView.getShowLegend(); String seriesNameKey = chartView.getSeriesNameKey(); List<?> chartData = chartView.getChartData(); JFreeChart chart;//from w ww. jav a2 s . com OHLCSeriesDataset dataset = new OHLCSeriesDataset(seriesNameKey, chartData); if (candlestick) { chart = ChartFactory.createCandlestickChart(title, horizontalAxisLabel, verticalAxisLabel, dataset, showLegend); } else { chart = ChartFactory.createHighLowChart(title, horizontalAxisLabel, verticalAxisLabel, dataset, showLegend); } return chart; }
From source file:org.jfree.chart.demo.CandlestickDemo.java
/** * Creates a chart./*from w w w. ja va 2 s .c om*/ * * @param dataset the dataset. * * @return The dataset. */ private JFreeChart createChart(final DefaultHighLowDataset dataset) { final JFreeChart chart = ChartFactory.createCandlestickChart("Candlestick Demo", "Time", "Value", dataset, true); return chart; }
From source file:com.leonarduk.finance.chart.CandlestickChart.java
public static void displayCandlestickChart(final Stock stock) throws IOException { final TimeSeries series = TimeseriesUtils.getTimeSeries(stock, 1); /**//w w w . jav a2 s.com * Creating the OHLC dataset */ final OHLCDataset ohlcDataset = CandlestickChart.createOHLCDataset(series); /** * Creating the additional dataset */ final TimeSeriesCollection xyDataset = CandlestickChart.createAdditionalDataset(series); /** * Creating the chart */ final JFreeChart chart = ChartFactory.createCandlestickChart(stock.getName() + " price", "Time", stock.getCurrency(), ohlcDataset, true); // Candlestick rendering final CandlestickRenderer renderer = new CandlestickRenderer(); renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); // Additional dataset final int index = 1; plot.setDataset(index, xyDataset); plot.mapDatasetToRangeAxis(index, 0); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesPaint(index, Color.blue); plot.setRenderer(index, renderer2); // Misc plot.setRangeGridlinePaint(Color.lightGray); plot.setBackgroundPaint(Color.white); final NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setAutoRangeIncludesZero(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); /** * Displaying the chart */ ChartDisplay.displayChartInFrame(chart, 740, 300, "Candlestick Chart"); }
From source file:com.zigabyte.stock.stratplot.StockMarketHistoryViewer.java
/** Update the chart to display the history of the selected StockHistory **/ private void refreshChart() { StockHistory stockHistory = (StockHistory) this.stockList.getSelectedValue(); if (stockHistory != null) { // a quick chart to show open/high/low/close/volume data by date OHLCDataset chartData = new StockHistoryOHLCDataset(stockHistory); chartPanel.setChart(/*from w w w.ja v a 2s .c o m*/ ChartFactory.createCandlestickChart(stockHistory.toString(), null, null, chartData, false)); } else { chartPanel.setChart(null); } }
From source file:compecon.dashboard.panel.BanksPanel.java
protected ChartPanel createPriceTimeSeriesChartPanel(Currency currency, Currency commodityCurrency) { JFreeChart priceChart = ChartFactory.createCandlestickChart(commodityCurrency.getIso4217Code() + " Prices", "Time", "Price in " + currency.getIso4217Code(), this.getDefaultHighLowDataset(currency, commodityCurrency), false); ChartPanel chartPanel = new ChartPanel(priceChart); chartPanel.setDomainZoomable(true);// w w w . j a v a2 s . c om chartPanel.setPreferredSize(new java.awt.Dimension(800, 400)); return chartPanel; }
From source file:de.laures.cewolf.taglib.CewolfChartFactory.java
public static JFreeChart getChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, Dataset data) throws ChartValidationException { // first check the dynamically registered chart types CewolfChartFactory factory = (CewolfChartFactory) factories.get(chartType); if (factory != null) { // custom factory found, use it return factory.getChartInstance(title, xAxisLabel, yAxisLabel, data); }/*from w w w. j av a 2s . co m*/ switch (getChartTypeConstant(chartType)) { case XY: check(data, XYDataset.class, chartType); return ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, true, true); case PIE: check(data, PieDataset.class, chartType); return ChartFactory.createPieChart(title, (PieDataset) data, true, true, true); case AREA_XY: check(data, XYDataset.class, chartType); return ChartFactory.createXYAreaChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false); case SCATTER: check(data, XYDataset.class, chartType); return ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, (XYDataset) data, PlotOrientation.VERTICAL, true, false, false); case AREA: check(data, CategoryDataset.class, chartType); return ChartFactory.createAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case HORIZONTAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case HORIZONTAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case LINE: check(data, CategoryDataset.class, chartType); return ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case STACKED_HORIZONTAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.HORIZONTAL, true, false, false); case STACKED_VERTICAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case STACKED_VERTICAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case VERTICAL_BAR: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case VERTICAL_BAR_3D: check(data, CategoryDataset.class, chartType); return ChartFactory.createBarChart3D(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case TIME_SERIES: check(data, XYDataset.class, chartType); return ChartFactory.createTimeSeriesChart(title, xAxisLabel, yAxisLabel, (XYDataset) data, true, false, false); case CANDLE_STICK: check(data, OHLCDataset.class, chartType); return ChartFactory.createCandlestickChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true); case HIGH_LOW: check(data, OHLCDataset.class, chartType); return ChartFactory.createHighLowChart(title, xAxisLabel, yAxisLabel, (OHLCDataset) data, true); case GANTT: check(data, IntervalCategoryDataset.class, chartType); return ChartFactory.createGanttChart(title, xAxisLabel, yAxisLabel, (IntervalCategoryDataset) data, true, false, false); case WIND: check(data, WindDataset.class, chartType); return ChartFactory.createWindPlot(title, xAxisLabel, yAxisLabel, (WindDataset) data, true, false, false); //case SIGNAL : // check(data, SignalsDataset.class, chartType); // return ChartFactory.createSignalChart(title, xAxisLabel, yAxisLabel, (SignalsDataset) data, true); case VERRTICAL_XY_BAR: check(data, IntervalXYDataset.class, chartType); return ChartFactory.createXYBarChart(title, xAxisLabel, true, yAxisLabel, (IntervalXYDataset) data, PlotOrientation.VERTICAL, true, false, false); case PIE_3D: check(data, PieDataset.class, chartType); return ChartFactory.createPieChart3D(title, (PieDataset) data, true, false, false); case METER: check(data, ValueDataset.class, chartType); MeterPlot plot = new MeterPlot((ValueDataset) data); JFreeChart chart = new JFreeChart(title, plot); return chart; case STACKED_AREA: check(data, CategoryDataset.class, chartType); return ChartFactory.createStackedAreaChart(title, xAxisLabel, yAxisLabel, (CategoryDataset) data, PlotOrientation.VERTICAL, true, false, false); case BUBBLE: check(data, XYZDataset.class, chartType); return ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, (XYZDataset) data, PlotOrientation.VERTICAL, true, false, false); case AUSTER_CICLOS: check(data, IntervalCategoryDataset.class, chartType); return ChartFactory.createAusterCiclosChart((IntervalCategoryDataset) data); default: throw new UnsupportedChartTypeException(chartType + " is not supported."); } }