List of usage examples for org.jfree.chart ChartFactory createHighLowChart
public static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, boolean legend)
From source file:org.jfree.chart.demo.HighLowChartDemo1.java
private static JFreeChart createChart(OHLCDataset ohlcdataset) { JFreeChart jfreechart = ChartFactory.createHighLowChart("High-Low-Open-Close Demo", "Time", "Value", ohlcdataset, true);// w w w . ja v a 2 s . com XYPlot xyplot = (XYPlot) jfreechart.getPlot(); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); return jfreechart; }
From source file:org.jfree.chart.demo.PriceVolumeDemo2.java
private static JFreeChart createChart() { OHLCDataset ohlcdataset = createPriceDataset(); String s = "Sun Microsystems (SUNW)"; JFreeChart jfreechart = ChartFactory.createHighLowChart(s, "Date", "Price", ohlcdataset, true); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setLowerMargin(0.01D);/*from w w w. ja v a2 s.co m*/ dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setLowerMargin(0.59999999999999998D); numberaxis.setAutoRangeIncludesZero(false); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); NumberAxis numberaxis1 = new NumberAxis("Volume"); numberaxis1.setUpperMargin(1.0D); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createVolumeDataset()); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); XYBarRenderer xybarrenderer = new XYBarRenderer(); xybarrenderer.setDrawBarOutline(false); xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); xyplot.setRenderer(1, xybarrenderer); ChartUtilities.applyCurrentTheme(jfreechart); xybarrenderer.setShadowVisible(false); xybarrenderer.setBarPainter(new StandardXYBarPainter()); return jfreechart; }
From source file:com.thecoderscorner.groovychart.chart.HighLowChart.java
public JFreeChart createChart() { JFreeChart chart = null;//from w w w . j ava2s . c om if (this.getTimeline() == null) { chart = ChartFactory.createHighLowChart(getTitle(), getTimeAxisLabel(), getValueAxisLabel(), (OHLCDataset) getDataset(), isLegend()); } else { chart = ChartFactory.createHighLowChart(getTitle(), getTimeAxisLabel(), getValueAxisLabel(), (OHLCDataset) getDataset(), getTimeline(), isLegend()); } return setExtraProperties(chart); }
From source file:org.jfree.chart.demo.HighLowChartDemo.java
/** * A demonstration application showing a high-low-open-close chart. * * @param title the frame title.// ww w. j a va2 s. c o m */ public HighLowChartDemo(final String title) { super(title); final DefaultHighLowDataset dataset = DemoDatasetFactory.createHighLowDataset(); final JFreeChart chart = ChartFactory.createHighLowChart("High-Low-Open-Close Demo", "Time", "Value", dataset, true); final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
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;//w w w. j a v a 2 s . c o m 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.HighLowChartDemo2.java
/** * Creates a sample chart.//from w ww .j a va 2s . c o m * * @param dataset a dataset. * * @return a sample chart. */ private JFreeChart createChart(final DefaultHighLowDataset dataset) { final JFreeChart chart = ChartFactory.createHighLowChart("OHLC Demo 2", "Time", "Value", dataset, true); final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); final XYDataset dataset2 = MovingAverage.createMovingAverage(dataset, "-MAVG", 3 * 24 * 60 * 60 * 1000L, 0L); final XYPlot plot = (XYPlot) chart.getPlot(); plot.setDataset(1, dataset2); plot.setRenderer(1, new StandardXYItemRenderer()); return chart; }
From source file:org.jfree.chart.demo.HighLowChartDemo3.java
private static JFreeChart createChart(OHLCDataset ohlcdataset) { JFreeChart jfreechart = ChartFactory.createHighLowChart("OHLC Demo 3", "Time", "Price", ohlcdataset, true); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); HighLowRenderer highlowrenderer = (HighLowRenderer) xyplot.getRenderer(); highlowrenderer.setBaseStroke(new BasicStroke(2.0F)); highlowrenderer.setSeriesPaint(0, Color.blue); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); NumberAxis numberaxis1 = new NumberAxis("Price 2"); numberaxis1.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createDataset2()); xyplot.setRenderer(1, new CandlestickRenderer(10D)); xyplot.mapDatasetToRangeAxis(1, 1);/* www.java 2 s .c o m*/ ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:net.commerce.zocalo.freechart.ChartTest.java
public void testOHLCChart() throws IOException { File jpgFile = newEmptyFile(".", "testChart.jpg"); File pngFile = newEmptyFile(".", "testChart.png"); assertFalse(jpgFile.exists());/*from w w w . j av a 2s . c om*/ assertFalse(pngFile.exists()); OutputStream jpgStream = new FileOutputStream(jpgFile); OutputStream pngStream = new FileOutputStream(pngFile); OHLCDataset data2 = createOHLCDataSet(new Minute()); JFreeChart chart = ChartFactory.createHighLowChart("testChart", "date", "values", data2, false); ChartUtilities.writeChartAsJPEG(jpgStream, chart, 200, 500); ChartUtilities.writeChartAsPNG(pngStream, chart, 200, 500); assertTrue(jpgFile.exists()); assertTrue(pngFile.exists()); jpgFile.delete(); pngFile.delete(); }
From source file:com.bdb.weather.display.summary.HighLowPanel.java
@SuppressWarnings("LeakingThisInConstructor") public HighLowPanel(String title, SummaryInterval interval, ViewLauncher launcher, SummarySupporter supporter, ValueAxis rangeAxis, String domainAxisLabel, SeriesInfo<T>[] seriesList, NumberFormat format) { this.setPrefSize(500, 300); this.interval = interval; this.launcher = launcher; this.supporter = supporter; chart = ChartFactory.createHighLowChart(title, domainAxisLabel, "", seriesCollection, true); chart.getLegend().setPosition(RectangleEdge.RIGHT); plot = (XYPlot) chart.getPlot();/*from w w w .ja v a2 s . c o m*/ renderer = (HighLowRenderer) plot.getRenderer(); renderer.setDrawCloseTicks(false); plot.setRangeAxis(rangeAxis); dateAxis = (DateAxis) plot.getDomainAxis(); dateAxis.setDateFormatOverride(interval.getLegacyFormat()); dateAxis.setVerticalTickLabels(true); dateAxis.setTickMarkPosition(DateTickMarkPosition.START); //dateAxis.setTickUnit(interval.getDateTickUnit()); //dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 2)); ChartViewer chartViewer = new ChartViewer(chart); chartViewer.addChartMouseListener(this); chartViewer.setPrefSize(500, 300); series = new OHLCSeries[seriesList.length]; for (int i = 0; i < seriesList.length; i++) { series[i] = new OHLCSeries(seriesList[i].getSeriesName()); seriesCollection.addSeries(series[i]); } seriesInfo = Arrays.copyOf(seriesList, seriesList.length); TableColumn<SummaryRecord, String> column = new TableColumn<>("Date"); column.setCellValueFactory( (rec) -> new ReadOnlyStringWrapper(DisplayConstants.formatDate(rec.getValue().getDate()))); dataTable.getColumns().add(column); String headingPrefix[] = { HIGH_COL_HEADING, LOW_COL_HEADING, AVG_COL_HEADING }; for (SeriesInfo<T> seriesColumn : seriesList) { for (String heading : headingPrefix) { column = new TableColumn<>(heading + " - " + seriesColumn.getSeriesName()); column.setCellValueFactory(seriesColumn); column.setUserData(heading); dataTable.getColumns().add(column); } } this.setTabContents(chartViewer, dataTable); HighLowItemLabelGenerator ttg = new HiLoItemLabelGenerator(interval.getLegacyFormat(), format); plot.getRenderer().setBaseToolTipGenerator(ttg); }
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. ja v a 2s .c o 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."); } }