List of usage examples for org.jfree.chart.plot CombinedDomainXYPlot getSubplots
public List getSubplots()
From source file:grafix.telas.PanelGraficos.java
public ValueAxis getValueAxisCandles() { CombinedDomainXYPlot cplot = (CombinedDomainXYPlot) this.getChart().getPlot(); XYPlot plot = (XYPlot) cplot.getSubplots().get(0); ValueAxis va = plot.getRangeAxis();/*from w w w. j a va2 s . c o m*/ return va; }
From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java
public void updatePersonDataset(HistogramChartDataset data) { //set histogram data CombinedDomainXYPlot cplot = (CombinedDomainXYPlot) chart.getPlot(); List plots = cplot.getSubplots(); XYPlot p = (XYPlot) plots.get(0);/*w w w . java 2 s . c o m*/ p.setDataset(0, data); }
From source file:com.itemanalysis.jmetrik.graph.itemmap.ItemMapPanel.java
public void updateItemDataSet(HistogramChartDataset data) { //set histogram data CombinedDomainXYPlot cplot = (CombinedDomainXYPlot) chart.getPlot(); List plots = cplot.getSubplots(); XYPlot p = (XYPlot) plots.get(1);//ww w. jav a 2 s .c om if (data.getSeriesCount() > 1) p.setForegroundAlpha(0.70f); p.setDataset(1, data); }
From source file:grafix.telas.MolduraAreaDados.java
private XYPlot getPlot() { JFreeChart jfchart = getPanelMolduras().getJanela().getPanelGraficos().getChart(); CombinedDomainXYPlot cplot = (CombinedDomainXYPlot) jfchart.getXYPlot(); XYPlot plot = (XYPlot) cplot.getSubplots().get(getNPlot()); return plot;/*from w w w . j a va 2 s . co m*/ }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * Method addBuySellTradeArrow.//from w w w. java 2 s . c om * * @param action * String * @param price * Money * @param time * Date * @param quantity * Integer * @throws ValueTypeException */ public void addBuySellTradeArrow(String action, Money price, Date time, Integer quantity) throws ValueTypeException { String label = Action.newInstance(action) + " " + quantity + "@" + price; XYPointerAnnotation arrow = new XYPointerAnnotation(label, time.getTime(), price.doubleValue(), 90d); arrow.setLabelOffset(5.0); arrow.setBackgroundPaint(Color.GREEN); if (action.equals(Action.SELL)) { arrow.setAngle(-90d); arrow.setBackgroundPaint(Color.RED); } CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) this.chart.getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); XYPlot xyplot = subplots.get(0); xyplot.addAnnotation(arrow); this.chart.fireChartChanged(); }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * Method seriesChanged.//from ww w .j a va2 s. com * * @param event * SeriesChangeEvent * @see org.jfree.data.general.SeriesChangeListener#seriesChanged(SeriesChangeEvent) */ public void seriesChanged(SeriesChangeEvent event) { Object series = event.getSource(); if (series instanceof CandleSeries) { CandleSeries candleSeries = (CandleSeries) series; if (!candleSeries.isEmpty()) { CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) this.chart.getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); XYPlot xyplot = subplots.get(0); CandleItem candleItem = (CandleItem) candleSeries.getDataItem(candleSeries.getItemCount() - 1); String msg = "Time: " + dateFormat.format(candleItem.getLastUpdateDate()) + " Open: " + new Money(candleItem.getOpen()) + " High: " + new Money(candleItem.getHigh()) + " Low: " + new Money(candleItem.getLow()) + " Close: " + new Money(candleItem.getClose()) + " Vwap: " + new Money(candleItem.getVwap()); titleLegend2.setText(msg); valueMarker.setValue(candleItem.getClose()); double x = TradingCalendar .getSpecificTime(candleSeries.getStartTime(), candleItem.getPeriod().getStart()).getTime(); String annotationText = "(" + dateFormat.format(candleItem.getLastUpdateDate()) + ", " + new Money(candleItem.getClose()) + ")"; if (null == closePriceLine) { closePriceLine = new XYTextAnnotation(annotationText, x, candleItem.getY()); closePriceLine.setTextAnchor(TextAnchor.BOTTOM_RIGHT); xyplot.addAnnotation(closePriceLine); xyplot.addRangeMarker(valueMarker); } else { closePriceLine.setText(annotationText); closePriceLine.setX(x); closePriceLine.setY(candleItem.getY()); } this.chart.fireChartChanged(); } } }
From source file:org.trade.ui.chart.CandlestickChart.java
/** * A demonstration application showing a candlestick chart. * //from w ww. jav a 2s . c o m * @param title * the frame title. * @param strategyData * StrategyData */ public CandlestickChart(final String title, StrategyData strategyData, Tradingday tradingday) { this.strategyData = strategyData; this.setLayout(new BorderLayout()); // Used to mark the current price stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 10, 3 }, 0); valueMarker = new ValueMarker(0.00, Color.black, stroke); this.chart = createChart(this.strategyData, title, tradingday); BlockContainer container = new BlockContainer(new BorderArrangement()); container.add(titleLegend1, RectangleEdge.LEFT); container.add(titleLegend2, RectangleEdge.RIGHT); container.add(new EmptyBlock(2000, 0)); CompositeTitle legends = new CompositeTitle(container); legends.setPosition(RectangleEdge.BOTTOM); this.chart.addSubtitle(legends); final ChartPanel chartPanel = new ChartPanel(this.chart); chartPanel.setFillZoomRectangle(true); chartPanel.setMouseZoomable(true, true); chartPanel.setRefreshBuffer(true); chartPanel.setDoubleBuffered(true); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent e) { } public void chartMouseClicked(final ChartMouseEvent e) { CombinedDomainXYPlot combinedXYplot = (CombinedDomainXYPlot) e.getChart().getPlot(); @SuppressWarnings("unchecked") List<XYPlot> subplots = combinedXYplot.getSubplots(); if (e.getTrigger().getClickCount() == 2) { double xItem = 0; double yItem = 0; if (e.getEntity() instanceof XYItemEntity) { XYItemEntity xYItemEntity = ((XYItemEntity) e.getEntity()); xItem = xYItemEntity.getDataset().getXValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); yItem = xYItemEntity.getDataset().getYValue(xYItemEntity.getSeriesIndex(), xYItemEntity.getItem()); } else { PlotEntity plotEntity = ((PlotEntity) e.getEntity()); XYPlot plot = (XYPlot) plotEntity.getPlot(); xItem = plot.getDomainCrosshairValue(); yItem = plot.getRangeCrosshairValue(); } for (XYPlot xyplot : subplots) { double x = xyplot.getDomainCrosshairValue(); double y = xyplot.getRangeCrosshairValue(); /* * If the cross hair is from a right-hand y axis we need * to convert this to a left-hand y axis. */ String rightAxisName = ", Price: "; double rangeLowerLeft = 0; double rangeUpperLeft = 0; double rangeLowerRight = 0; double rangeUpperRight = 0; double yRightLocation = 0; for (int index = 0; index < xyplot.getRangeAxisCount(); index++) { AxisLocation axisLocation = xyplot.getRangeAxisLocation(index); Range range = xyplot.getRangeAxis(index).getRange(); if (axisLocation.equals(AxisLocation.BOTTOM_OR_LEFT) || axisLocation.equals(AxisLocation.TOP_OR_LEFT)) { rangeLowerLeft = range.getLowerBound(); rangeUpperLeft = range.getUpperBound(); rightAxisName = ", " + xyplot.getRangeAxis(index).getLabel() + ": "; } if (y >= range.getLowerBound() && y <= range.getUpperBound() && (axisLocation.equals(AxisLocation.BOTTOM_OR_RIGHT) || axisLocation.equals(AxisLocation.TOP_OR_RIGHT))) { rangeUpperRight = range.getUpperBound(); rangeLowerRight = range.getLowerBound(); } } if ((rangeUpperRight - rangeLowerRight) > 0) { yRightLocation = rangeLowerLeft + ((rangeUpperLeft - rangeLowerLeft) * ((y - rangeLowerRight) / (rangeUpperRight - rangeLowerRight))); } else { yRightLocation = y; } String text = " Time: " + dateFormatShort.format(new Date((long) (x))) + rightAxisName + new Money(y); if (x == xItem && y == yItem) { titleLegend1.setText(text); if (null == clickCrossHairs) { clickCrossHairs = new XYTextAnnotation(text, x, yRightLocation); clickCrossHairs.setTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addAnnotation(clickCrossHairs); } else { clickCrossHairs.setText(text); clickCrossHairs.setX(x); clickCrossHairs.setY(yRightLocation); } } } } else if (e.getTrigger().getClickCount() == 1 && null != clickCrossHairs) { for (XYPlot xyplot : subplots) { if (xyplot.removeAnnotation(clickCrossHairs)) { clickCrossHairs = null; titleLegend1.setText(" Time: 0, Price :0.0"); break; } } } } }); this.add(chartPanel, null); this.strategyData.getCandleDataset().getSeries(0).addChangeListener(this); }
From source file:ch.agent.crnickl.demo.stox.Chart.java
private void makeSubPlot(CombinedDomainXYPlot container, ChartSeries series) throws KeyedException { int index = series.getSubPlotIndex(); int nextDatasetOffset = 0; XYPlot plot = null;//from w ww.j a v a 2 s.c o m try { if (index > 0) { plot = (XYPlot) container.getSubplots().get(index - 1); nextDatasetOffset = plot.getDatasetCount(); } } catch (Exception e) { throw K.CHART_SUBPLOT_ERR.exception(e, index); } if (plot == null) plot = series.isLine() ? getLinePlot() : getBarPlot(); XYItemRenderer renderer = series.isLine() ? getLineRenderer() : getBarRenderer(); plot.setRenderer(nextDatasetOffset, renderer); plot.setDataset(nextDatasetOffset, getDataset(series.getTimeSeries(), series.getName())); if (index < 1) container.add(plot, series.getWeight()); }
From source file:com.att.aro.ui.view.diagnostictab.GraphPanel.java
public void layoutGraphLabels() { CombinedDomainXYPlot combinedPlot = getPlot(); int height = getChartPanel().getBounds().height - 15;// - 20; // logger.info("height: "+ height); // find weights and use them to determine how may divisions are needed. int plotWeightedDivs = 0; List<?> plots = combinedPlot.getSubplots(); for (Object obj : plots) { if (obj instanceof XYPlot) { plotWeightedDivs += ((XYPlot) obj).getWeight(); }//www.j ava 2s. c o m } // check for zero plotWeightedDivs = plotWeightedDivs == 0 ? 1 : plotWeightedDivs; // determine the size of the divisions for each XYPlot int division = Math.round(((float) height) / ((float) plotWeightedDivs)); // working from top to bottom, set the y-coord. for the first XYPlot int currentY = getLabelsPanel().getBounds().y + getChartPanel().getBounds().y; // getLabelsPanel().getBounds().y // + // 4 // + // getChartPanel().getBounds().y; // loop on the list of Plots // logger.info("size: "+ graphHelper.getPlotOrder().size()); for (ChartPlotOptions option : graphHelper.getPlotOrder()) { GraphPanelPlotLabels subplot = getSubplotMap().get(option); if (subplot != null && subplot.getLabel().isVisible()) { int weightDivisionFactor = division * subplot.getWeight(); // set the current position using weight subplot.getLabel().setBounds(3, currentY + 1, 100, weightDivisionFactor + 3); // adjust the currentY value for the next label in the loop currentY += weightDivisionFactor; } } getAxisLabel().setBounds(3, height + 4, 100, 15); // + 3 // +getChartPanel().getBounds().y // logger.info("axis label height: " + (height + 3 + // getChartPanel().getBounds().y) ); }
From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java
/** * Returns the number of plots in this chart dialog. * * @return the number of plots in this chart dialog *//*from w ww .j av a2 s .c o m*/ public int getPlotSize() { final JFreeChart chart = this.chartPanel.getChart(); final CombinedDomainXYPlot cplot = (CombinedDomainXYPlot) chart.getPlot(); return cplot.getSubplots().size(); }