List of usage examples for org.jfree.chart.plot XYPlot mapDatasetToRangeAxis
public void mapDatasetToRangeAxis(int index, int axisIndex)
From source file:ta4jexamples.indicators.CandlestickChart.java
public static void main(String[] args) { /**// w w w .j a va 2 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:ta4jexamples.analysis.CashFlowToChart.java
/** * Adds the cash flow axis to the plot./*from w w w .j a va 2 s. c om*/ * @param plot the plot * @param dataset the cash flow dataset */ private static void addCashFlowAxis(XYPlot plot, TimeSeriesCollection dataset) { final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio"); cashAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, cashAxis); plot.setDataset(1, dataset); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer(); cashFlowRenderer.setSeriesPaint(0, Color.blue); plot.setRenderer(1, cashFlowRenderer); }
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); /**//from ww w . j av a 2s. c om * 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.leonarduk.finance.analysis.CashFlowToChart.java
/** * Adds the cash flow axis to the plot.//www . j a va 2 s. c om * * @param plot * the plot * @param dataset * the cash flow dataset */ private static void addCashFlowAxis(final XYPlot plot, final TimeSeriesCollection dataset) { final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio"); cashAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, cashAxis); plot.setDataset(1, dataset); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer(); cashFlowRenderer.setSeriesPaint(0, Color.blue); plot.setRenderer(1, cashFlowRenderer); }
From source file:ch.zhaw.parallelComputing.view.Plotter.java
/** * Generates a plot for comparing to datasets * @param title the name of the plot// ww w . ja va 2 s. co m * @param dataset1 the first data set for plotting * @param dataset2 the second data set for plotting * @return a chart object for displaying or saving as picture */ public static JFreeChart plot(String title, XYDataset dataset1, XYDataset dataset2) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "Date", // x-axis label "Input Value", // y-axis label dataset1, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); XYPlot plot = chart.getXYPlot(); Axis axis1 = plot.getRangeAxis(0); axis1.setLabelPaint(Color.red); NumberAxis axis2 = new NumberAxis("Twitter"); axis2.setLabelPaint(Color.blue); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.blue); renderer.setBaseShapesVisible(false); plot.setRenderer(1, renderer); return chart; }
From source file:org.jfree.chart.demo.AnnotationDemo2.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset1(); JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); NumberAxis numberaxis1 = new NumberAxis("Secondary"); numberaxis1.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createDataset2()); xyplot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D, 167.30000000000001D, -0.78539816339744828D); xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); xypointerannotation.setPaint(Color.red); xypointerannotation.setArrowPaint(Color.red); xylineandshaperenderer.addAnnotation(xypointerannotation); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true); xylineandshaperenderer1.setSeriesPaint(0, Color.black); xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D, 613.20000000000005D, 1.5707963267948966D); xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER); xylineandshaperenderer1.addAnnotation(xypointerannotation1); xyplot.setRenderer(1, xylineandshaperenderer1); LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer); LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.add(legendtitle, RectangleEdge.LEFT); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(compositetitle); return jfreechart; }
From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java
private static JFreeChart createTimeSeriesChart() { XYDataset dataset1 = createDataset1(); //DomainAxis//from w w w . j av a 2s . co m DateAxis timeAxis = new DateAxis(""); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); //RangeAxis NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); // override default NumberAxis valueAxis2 = new NumberAxis(""); valueAxis2.setAutoRangeIncludesZero(false); // override default // valueAxis.setDefaultAutoRange(new Range(100, 1150)); //Renderer XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); XYDataset dataset2 = createDataset2(); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); //Plot XYPlot plot = new XYPlot(dataset1, timeAxis, valueAxis, null); plot.setRenderer(renderer); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setRangeAxis(1, valueAxis2); plot.mapDatasetToRangeAxis(1, 1); plot.setBackgroundPaint(plotBackgroundPaint); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // plot.setRangePannable(true); //chart JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); valueAxis.setAutoRange(false); timeAxis.setAutoRange(false); return chart; }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java
protected static XYPlot createXYPlot(XYDataset dataset, Color[] colors) { // break up into two datasets, one for bars one for lines //LinkedList lines =new LinkedList(); //LinkedList bars = new LinkedList(); XYDataset seriesLines = new XYSeriesCollection(); XYDataset seriesBars = new XYSeriesCollection(); ((XYSeriesCollection) seriesBars).setIntervalWidth(0.0); if (dataset instanceof XYSeriesCollection) { while (0 < dataset.getSeriesCount()) { XYSeries s = ((XYSeriesCollection) dataset).getSeries(0); ((XYSeriesCollection) dataset).removeSeries(0); Comparable key = s.getKey(); boolean lines = false; if (key instanceof String) lines = ((String) key).startsWith("-"); if (lines) ((XYSeriesCollection) seriesLines).addSeries(s); else/*www . j a va 2s .com*/ ((XYSeriesCollection) seriesBars).addSeries(s); } } else { seriesBars = dataset; } NumberAxis axisDomain = new NumberAxis(); axisDomain.setAutoRange(true); axisDomain.setAutoRangeIncludesZero(false); // axisDomain.setRange(400.0, 1600.0); // NOTE: zooming in too far kills the chart, prevent this axisDomain.addChangeListener(new AxisChangeListener() { public void axisChanged(AxisChangeEvent event) { NumberAxis axis = (NumberAxis) event.getSource(); Range range = axis.getRange(); if (range.getLength() < 2.0) { //_log.info("AxisChangeListener " + range.getLength() + " " + range.toString()); double middle = range.getLowerBound() + range.getLength() / 2.0; axis.setRange(new Range(middle - 1.1, middle + 1.1)); } } }); NumberAxis axisRange = new NumberAxis(); axisRange.setAutoRange(true); axisRange.setAutoRangeIncludesZero(true); XYToolTipGenerator toolTipGenerator = new XYToolTipGenerator() { public String generateToolTip(XYDataset xyDataset, int s, int i) { double X = Math.round(xyDataset.getXValue(s, i) * 1000.0) / 1000.0; double Y = Math.round(xyDataset.getYValue(s, i) * 1000.0) / 1000.0; return "(" + X + ", " + Y + ")"; } }; XYBarRenderer barRenderer = new XYBarRenderer(); //dhmay adding 2009/09/14. As of jfree 1.0.13, shadows on by default barRenderer.setShadowVisible(false); //dhmay adding for jfreechart 1.0.6 upgrade. If this isn't here, we get a //nullPointerException in XYBarRenderer.drawItemLabel barRenderer.setBaseItemLabelGenerator(new NullLabelGenerator()); barRenderer.setSeriesItemLabelsVisible(0, true); barRenderer.setBaseToolTipGenerator(toolTipGenerator); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(); lineRenderer.setBaseToolTipGenerator(toolTipGenerator); XYPlot xy = new XYPlot(null, axisDomain, axisRange, null); int ds = 0; if (seriesLines.getSeriesCount() > 0) { xy.setDataset(ds, seriesLines); xy.setRenderer(ds, lineRenderer); xy.mapDatasetToRangeAxis(ds, 0); ds++; for (int i = 0; i < seriesLines.getSeriesCount(); i++) { Comparable key = ((XYSeriesCollection) seriesLines).getSeriesKey(i); boolean lines = false; if (key instanceof String) lines = ((String) key).startsWith("-"); lineRenderer.setSeriesLinesVisible(i, lines); lineRenderer.setSeriesShapesVisible(i, !lines); } } if (seriesBars.getSeriesCount() > 0) { xy.setDataset(ds, seriesBars); xy.setRenderer(ds, barRenderer); xy.mapDatasetToRangeAxis(ds, 0); ds++; } setColors(xy, colors); return xy; }
From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java
public static void createXYSeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) { ValueAxis axis = null;// w w w .j ava 2 s.c o m if (chartAxisData.getType() != null) { if (chartAxisData.getType().equals("number")) axis = createNumberAxis(chart, chartAxisData); else if (chartAxisData.getType().equals("date")) axis = createDateAxis(chart, chartAxisData); if (chartAxisData.getTickLabelFontSize() > 0) { Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT .deriveFont(chartAxisData.getTickLabelFontSize()); axis.setTickLabelFont(tickFont); } axis.setTickLabelsVisible(chartAxisData.isTickLabels()); axis.setTickMarksVisible(chartAxisData.isTickMarks()); axis.setVerticalTickLabels(chartAxisData.isVerticalTickLabels()); } XYPlot plot = chart.getXYPlot(); if (chartAxisData.isDomain()) { plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis); } else { plot.setRangeAxis(axisIndex, axis); XYDataset dataset = (XYDataset) chartAxisData.getDatasource(); plot.setRenderer(axisIndex, new StandardXYItemRenderer()); plot.setDataset(axisIndex, dataset); plot.mapDatasetToRangeAxis(axisIndex, axisIndex); } setXYSeriesAxisColors(chartAxisData, plot.getRenderer(axisIndex)); }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
private static JFreeChart priceVolumeHistoryChart(String title, TimePeriodValuesCollection prices, TimePeriodValuesCollection volumes, boolean scalePrices) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, null, "Price", prices, false, false, false); XYPlot plot = chart.getXYPlot(); if (scalePrices) { setBoundsForPrice(chart);//from w w w. j a va 2 s. com } else { setBoundsForPercent(chart); } NumberAxis rangeAxis2 = new NumberAxis("Volume"); rangeAxis2.setUpperMargin(2); plot.setRangeAxis(1, rangeAxis2); plot.setDataset(1, volumes); plot.mapDatasetToRangeAxis(1, 1); XYBarRenderer renderer2 = new XYBarRenderer(0.2); plot.setRenderer(1, renderer2); return chart; }