List of usage examples for org.jfree.chart.plot XYPlot getDatasetCount
public int getDatasetCount()
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java
private void pushDataAndRendererIntoPlot(XYPlot plot, int rangeAxisIdx, XYItemRenderer renderer, XYDataset dataset) throws ChartPlottimeException { if (dataset != null && renderer != null) { int datasetIdx = plot.getDatasetCount(); if (datasetIdx > 0 && plot.getDataset(datasetIdx - 1) == null) { datasetIdx -= 1;/*from w ww . j a va 2 s .c om*/ } // push dataset and renderer into plot try { plot.setDataset(datasetIdx, dataset); // if Eclipse states that // dataset might not be // initialized, you did // not consider all // possibilities in the // condition block above } catch (RuntimeException e) { // probably this is because the domain axis contains values less // then zero and the scaling is logarithmic. // The shitty JFreeChart implementation does not throw a proper // exception stating what happened, // but just a RuntimeException with a string, so this is our // best guess: if (isProbablyZeroValuesOnLogScaleException(e)) { throw new ChartPlottimeException("gui.plotter.error.log_axis_contains_zero", "domain axis"); } else { throw e; } } plot.mapDatasetToRangeAxis(datasetIdx, rangeAxisIdx); plot.setRenderer(datasetIdx, renderer); } else { ChartPlottimeException chartPlottimeException = new ChartPlottimeException( new PlotConfigurationError("generic_plotter_error")); throw chartPlottimeException; } }
From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java
private void setupChart(String pInitialId, XYDataset pInitialDataset) { chart = ChartFactory.createTimeSeriesChart("Spielerstatistiken", // title "Zeiten", // x-axis label pInitialId, // y-axis label pInitialDataset, // data jShowLegend.isSelected(), // create legend? true, // generate tooltips? false // generate URLs? );/* w w w . j a v a 2 s . com*/ chart.setBackgroundPaint(Constants.DS_BACK); XYPlot plot = (XYPlot) chart.getPlot(); setupPlotDrawing(plot); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 0; i < plot.getSeriesCount(); i++) { renderer.setSeriesLinesVisible(i, jShowLines.isSelected()); renderer.setSeriesShapesVisible(i, jShowDataPoints.isSelected()); plot.setRenderer(i, renderer); } renderer.setDefaultItemLabelsVisible(jShowItemValues.isSelected()); renderer.setDefaultItemLabelGenerator(new org.jfree.chart.labels.StandardXYItemLabelGenerator()); renderer.setDefaultToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"), NumberFormat.getInstance())); int lastDataset = plot.getDatasetCount() - 1; if (lastDataset > 0) { plot.getRangeAxis().setAxisLinePaint(plot.getLegendItems().get(lastDataset).getLinePaint()); plot.getRangeAxis().setLabelPaint(plot.getLegendItems().get(lastDataset).getLinePaint()); plot.getRangeAxis().setTickLabelPaint(plot.getLegendItems().get(lastDataset).getLinePaint()); plot.getRangeAxis().setTickMarkPaint(plot.getLegendItems().get(lastDataset).getLinePaint()); } NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(0); NumberAxis na = ((NumberAxis) plot.getRangeAxis()); if (na != null) { na.setNumberFormatOverride(nf); } }
From source file:org.talend.dataprofiler.chart.util.ToolTipChartComposite.java
/** * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a * data point in a data set that lies inside a hotspot around that value. * /*from w w w. j a va2s . c o m*/ * @param point The Java 2D point * @return A string for the data at the point or null if no data is found. */ protected String getTooltipAtPoint(Point point) { String result = null; Point2D translatedPoint = this.translateScreenToJava2D(point); Plot plot = this.getChart().getPlot(); PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo(); if (plot instanceof CombinedDomainXYPlot) { int index = info.getSubplotIndex(translatedPoint); if (index < 0) { index = 0; } plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index); info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index); } if (plot != null && plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; ValueAxis domainAxis = xyPlot.getDomainAxis(); ValueAxis rangeAxis = xyPlot.getRangeAxis(); // had to switch to SWT's rectangle here. Rectangle screenArea = this.scale(info.getDataArea()); double hotspotSizeX = hotspontsize * this.getScaleX(); double hotspotSizeY = hotspontsize * this.getScaleY(); double x0 = point.getX(); double y0 = point.getY(); double x1 = x0 - hotspotSizeX; double y1 = y0 + hotspotSizeY; double x2 = x0 + hotspotSizeX; double y2 = y0 - hotspotSizeY; RectangleEdge xEdge = RectangleEdge.BOTTOM; RectangleEdge yEdge = RectangleEdge.LEFT; // Switch everything for horizontal charts if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) { hotspotSizeX = hotspontsize * this.getScaleY(); hotspotSizeY = hotspontsize * this.getScaleX(); x0 = point.getY(); y0 = point.getX(); x1 = x0 + hotspotSizeX; y1 = y0 - hotspotSizeY; x2 = x0 - hotspotSizeX; y2 = y0 + hotspotSizeY; xEdge = RectangleEdge.LEFT; yEdge = RectangleEdge.BOTTOM; } // OK, here we have to get ourselves back into AWT land... Rectangle2D r2d = new Rectangle2D.Double(); r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height); double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge); double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge); double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge); double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge); double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge); int datasetCount = xyPlot.getDatasetCount(); for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) { XYDataset dataset = xyPlot.getDataset(datasetIndex); int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); if (dataset instanceof OHLCDataset) { // This could be optimized to use a binary search for x first for (int item = 0; item < itemCount; item++) { double xValue = dataset.getXValue(series, item); double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item); double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item); // Check hi lo and swap if needed if (yValueHi < yValueLo) { double temp = yValueHi; yValueHi = yValueLo; yValueLo = temp; } // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2) if (tx1 < xValue && xValue < tx2) { // Check if the cursor 'y' value lies between the high and low (low < ty0 < high) if (yValueLo < ty0 && ty0 < yValueHi) { return hiLoTips.generateToolTip(dataset, series, item); } } } } else { // This could be optimized to use a binary search for x first for (int item = 0; item < itemCount; item++) { double xValue = dataset.getXValue(series, item); double yValue = dataset.getYValue(series, item); // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2) if (tx1 < xValue && xValue < tx2) { // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2) if (ty1 < yValue && yValue < ty2) { return xyTips.generateToolTip(dataset, series, item); } } } } } } } return result; }
From source file:com.chart.SwingChart.java
/** * //from www. j a va2 s .co m * @param name Chart name * @param parent Skeleton parent * @param axes Configuration of axes * @param abcissaName Abcissa name */ public SwingChart(String name, final Skeleton parent, List<AxisChart> axes, String abcissaName) { this.skeleton = parent; this.axes = axes; this.name = name; this.abcissaFormat = NumberFormat.getInstance(Locale.getDefault()); this.ordinateFormat = NumberFormat.getInstance(Locale.getDefault()); plot = new XYPlot(); plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor))); plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor))); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); abcissaAxis = new NumberAxis(abcissaName); ((NumberAxis) abcissaAxis).setAutoRangeIncludesZero(false); abcissaAxis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); abcissaAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor))); abcissaAxis.setAutoRange(true); abcissaAxis.setLowerMargin(0.0); abcissaAxis.setUpperMargin(0.0); abcissaAxis.setTickLabelsVisible(true); abcissaAxis.setLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); abcissaAxis.setTickLabelFont(abcissaAxis.getLabelFont().deriveFont(fontSize)); plot.setDomainAxis(abcissaAxis); for (int i = 0; i < axes.size(); i++) { AxisChart categoria = axes.get(i); addAxis(categoria.getName()); for (int j = 0; j < categoria.configSerieList.size(); j++) { SimpleSeriesConfiguration cs = categoria.configSerieList.get(j); addSeries(categoria.getName(), cs); } } chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 16), plot, false); chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))))); chartPanel.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escape"); chartPanel.getActionMap().put("escape", new AbstractAction() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { for (int i = 0; i < plot.getDatasetCount(); i++) { XYDataset test = plot.getDataset(i); XYItemRenderer r = plot.getRenderer(i); r.removeAnnotations(); } } }); chartPanel.addChartMouseListener(cml = new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { } @Override public void chartMouseMoved(ChartMouseEvent event) { try { XYItemEntity xyitem = (XYItemEntity) event.getEntity(); // get clicked entity XYDataset dataset = (XYDataset) xyitem.getDataset(); // get data set double x = dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()); double y = dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()); final XYPlot plot = chart.getXYPlot(); for (int i = 0; i < plot.getDatasetCount(); i++) { XYDataset test = plot.getDataset(i); XYItemRenderer r = plot.getRenderer(i); r.removeAnnotations(); if (test == dataset) { NumberAxis ejeOrdenada = AxesList.get(i); double y_max = ejeOrdenada.getUpperBound(); double y_min = ejeOrdenada.getLowerBound(); double x_max = abcissaAxis.getUpperBound(); double x_min = abcissaAxis.getLowerBound(); double angulo; if (y > (y_max + y_min) / 2 && x > (x_max + x_min) / 2) { angulo = 3.0 * Math.PI / 4.0; } else if (y > (y_max + y_min) / 2 && x < (x_max + x_min) / 2) { angulo = 1.0 * Math.PI / 4.0; } else if (y < (y_max + y_min) / 2 && x < (x_max + x_min) / 2) { angulo = 7.0 * Math.PI / 4.0; } else { angulo = 5.0 * Math.PI / 4.0; } CircleDrawer cd = new CircleDrawer((Color) r.getSeriesPaint(xyitem.getSeriesIndex()), new BasicStroke(2.0f), null); //XYAnnotation bestBid = new XYDrawableAnnotation(dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()), dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), 11, 11, cd); String txt = "X:" + abcissaFormat.format(x) + ", Y:" + ordinateFormat.format(y); XYPointerAnnotation anotacion = new XYPointerAnnotation(txt, dataset.getXValue(xyitem.getSeriesIndex(), xyitem.getItem()), dataset.getYValue(xyitem.getSeriesIndex(), xyitem.getItem()), angulo); anotacion.setTipRadius(10.0); anotacion.setBaseRadius(35.0); anotacion.setFont(new Font("SansSerif", Font.PLAIN, 10)); if (Long.parseLong((strChartBackgroundColor.replace("#", "")), 16) > 0xffffff / 2) { anotacion.setPaint(Color.black); anotacion.setArrowPaint(Color.black); } else { anotacion.setPaint(Color.white); anotacion.setArrowPaint(Color.white); } //bestBid.setPaint((Color) r.getSeriesPaint(xyitem.getSeriesIndex())); r.addAnnotation(anotacion); } } //LabelValorVariable.setSize(LabelValorVariable.getPreferredSize()); } catch (NullPointerException | ClassCastException ex) { } } }); chartPanel.setPopupMenu(null); chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor))); SwingNode sn = new SwingNode(); sn.setContent(chartPanel); chartFrame = new VBox(); chartFrame.getChildren().addAll(sn, legendFrame); VBox.setVgrow(sn, Priority.ALWAYS); VBox.setVgrow(legendFrame, Priority.NEVER); chartFrame.getStylesheets().addAll(SwingChart.class.getResource("overlay-chart.css").toExternalForm()); legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;"); MenuItem mi; mi = new MenuItem("Print"); mi.setOnAction((ActionEvent t) -> { print(chartFrame); }); contextMenuList.add(mi); sn.setOnMouseClicked((MouseEvent t) -> { if (menu != null) { menu.hide(); } if (t.getClickCount() == 2) { backgroundEdition(); } }); mi = new MenuItem("Copy to clipboard"); mi.setOnAction((ActionEvent t) -> { copyClipboard(chartFrame); }); contextMenuList.add(mi); mi = new MenuItem("Export values"); mi.setOnAction((ActionEvent t) -> { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to file"); fileChooser.getExtensionFilters() .addAll(new FileChooser.ExtensionFilter("Comma Separated Values", "*.csv")); Window w = null; try { w = parent.getScene().getWindow(); } catch (NullPointerException e) { } File file = fileChooser.showSaveDialog(w); if (file != null) { export(file); } }); contextMenuList.add(mi); chartFrame.setOnContextMenuRequested((ContextMenuEvent t) -> { if (menu != null) { menu.hide(); } menu = new ContextMenu(); menu.getItems().addAll(contextMenuList); menu.show(chartFrame, t.getScreenX(), t.getScreenY()); }); }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotDataSet(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape) throws ConvertException { double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY); String legend = shortLegend.get(id); Color color = colors.get(id); Shape shape = shapes.get(id); if (addInfoInLegend) { legend = longLegend.get(id);//from w ww.jav a 2s . c om } if (color == null) { color = defaultColor; } if (shape == null) { shape = defaultShape; } if (points != null) { DefaultXYDataset dataset = new DefaultXYDataset(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(drawLines, true); dataset.addSeries(legend, points); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setSeriesPaint(0, color); renderer.setSeriesShape(0, shape); int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } plot.setDataset(i, dataset); plot.setRenderer(i, renderer); } }
From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java
@Override public void itemChanged(iPlatformComponent chartComponent, ChartDefinition cd, ChartDataItem item) { ChartInfo info = (ChartInfo) cd.getChartHandlerInfo(); switch (item.getItemType()) { case SERIES://w w w. ja v a 2s . c o m dataChanged(chartComponent, cd); return; case DOMAIN_MARKER: if ((info.chart != null) && (info.chart.getPlot() instanceof XYPlot)) { updateMarkers(cd, (XYPlot) info.chart.getPlot(), false); } break; case RANGE_MARKER: if ((info.chart != null) && (info.chart.getPlot() instanceof XYPlot)) { updateMarkers(cd, (XYPlot) info.chart.getPlot(), true); } break; case POINT: break; default: break; } SeriesData data = info.updateSeries(cd, item); Plot plot = info.chart.getPlot(); if ((data == null) || (plot instanceof PiePlot)) { createChart(chartComponent, cd); return; } int series = data.seriesIndex; try { if (plot instanceof XYPlot) { XYPlot xyplot = (XYPlot) plot; int sn = series; XYDataset set; if (xyplot.getDatasetCount() == 1) { set = xyplot.getDataset(0); } else { set = xyplot.getDataset(series); sn = 0; } if (set.getSeriesCount() > sn) { if (set instanceof XYSeriesCollection) { XYSeries s = ((XYSeriesCollection) set).getSeries(sn); if (s != null) { s.clear(); ChartHelper.populateXYSeries(s, data); } } } } } catch (Exception e) { Platform.ignoreException("can't update chart series", e); createChart(chartComponent, cd); } }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotFunction(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape, double minX, double maxX) throws ConvertException { double[][] points = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); double[][] functionErrors = null; String legend = shortLegend.get(id); Color color = colors.get(id); Shape shape = shapes.get(id); if (showConfidenceInterval) { functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); }/*from ww w .j av a2 s . c o m*/ if (addInfoInLegend) { legend = longLegend.get(id); } if (color == null) { color = defaultColor; } if (shape == null) { shape = defaultShape; } if (points != null) { int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } if (functionErrors != null) { YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection(); DeviationRenderer functionRenderer = new DeviationRenderer(true, false); YIntervalSeries series = new YIntervalSeries(legend); for (int j = 0; j < points[0].length; j++) { double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j]; series.add(points[0][j], points[1][j], points[1][j] - error, points[1][j] + error); } functionDataset.addSeries(series); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesFillPaint(0, color); functionRenderer.setSeriesShape(0, shape); plot.setDataset(i, functionDataset); plot.setRenderer(i, functionRenderer); } else { DefaultXYDataset functionDataset = new DefaultXYDataset(); XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false); functionDataset.addSeries(legend, points); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesShape(0, shape); plot.setDataset(i, functionDataset); plot.setRenderer(i, functionRenderer); } } }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotBoth(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape, double minX, double maxX) throws ConvertException { double[][] modelPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY); double[][] functionErrors = null; String legend = shortLegend.get(id); Color color = colors.get(id); Shape shape = shapes.get(id); if (showConfidenceInterval) { functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); }//from www . j av a 2s . com if (addInfoInLegend) { legend = longLegend.get(id); } if (color == null) { color = defaultColor; } if (shape == null) { shape = defaultShape; } if (modelPoints != null) { int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } if (functionErrors != null) { YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection(); DeviationRenderer functionRenderer = new DeviationRenderer(true, false); YIntervalSeries series = new YIntervalSeries(legend); for (int j = 0; j < modelPoints[0].length; j++) { double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j]; series.add(modelPoints[0][j], modelPoints[1][j], modelPoints[1][j] - error, modelPoints[1][j] + error); } functionDataset.addSeries(series); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesFillPaint(0, color); functionRenderer.setSeriesShape(0, shape); if (dataPoints != null) { functionRenderer.setBaseSeriesVisibleInLegend(false); } plot.setDataset(i, functionDataset); plot.setRenderer(i, functionRenderer); } else { DefaultXYDataset functionDataset = new DefaultXYDataset(); XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false); functionDataset.addSeries(legend, modelPoints); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesShape(0, shape); if (dataPoints != null) { functionRenderer.setBaseSeriesVisibleInLegend(false); } plot.setDataset(i, functionDataset); plot.setRenderer(i, functionRenderer); } } if (dataPoints != null) { DefaultXYDataset dataSet = new DefaultXYDataset(); XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true); dataSet.addSeries(legend, dataPoints); dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); dataRenderer.setSeriesPaint(0, color); dataRenderer.setSeriesShape(0, shape); int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } plot.setDataset(i, dataSet); plot.setRenderer(i, dataRenderer); } }
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
private void updateIndicatorTraceInfos(int mainPointIndex) { this.indicatorTraceInfos.clear(); if (this.mainTraceInfo == null) { return;/* w ww .j a v a 2s . c o m*/ } final ChartPanel chartPanel = this.chartJDialog.getChartPanel(); Day day = null; final XYDataset xyDataset = this.chartJDialog.getPlot().getDataset(); if (xyDataset instanceof TimeSeriesCollection) { // Get the date. day = (Day) ((TimeSeriesCollection) xyDataset).getSeries(0).getDataItem(mainPointIndex).getPeriod(); // 0 means main plot. final XYPlot plot = this.chartJDialog.getPlot(); final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(); // Start with 1. We are not interested in main series. for (int j = 1, size = timeSeriesCollection.getSeriesCount(); j < size; j++) { final TimeSeries timeSeries = timeSeriesCollection.getSeries(j); /* Time consuming. */ final int dataIndex = getDataIndex(timeSeries, day); if (dataIndex < 0) { continue; } final Point2D point = this.getPoint(0, j, dataIndex); final String name = this.getLegendName(0, j); final Number value = this.getValue(0, j, dataIndex); if (point == null || name == null || value == null) { continue; } // We will never draw ball for SMA, EMA... this.indicatorTraceInfos.add(TraceInfo.newInstance(null, 0, j, dataIndex)); } } else { final Date date = ((org.jfree.data.xy.DefaultHighLowDataset) xyDataset).getXDate(0, mainPointIndex); // OK to do so? Is "day" only used to compare day, excluding time information? // Will day 13th September 2009, 1:00pm same as another day 13th September 2009, 3:00pm? day = new Day(date); // 0 means main plot. final XYPlot plot = this.chartJDialog.getPlot(); final int count = plot.getDatasetCount(); for (int i = 1; i < count; i++) { final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(i); /* Not ready. */ if (timeSeriesCollection == null) { continue; } final TimeSeries timeSeries = timeSeriesCollection.getSeries(0); /* Time consuming. */ final int dataIndex = getDataIndex(timeSeries, day); if (dataIndex < 0) { continue; } final Point2D point = this.getPoint(0, i, dataIndex); final String name = this.getLegendName(0, i); final Number value = this.getValue(0, i, dataIndex); if (point == null || name == null || value == null) { continue; } // We will never draw ball for SMA, EMA... this.indicatorTraceInfos.add(TraceInfo.newInstance(null, 0, i, dataIndex)); } } // Begin with 1. 0 is main plot. for (int i = 1, size = this.chartJDialog.getPlotSize(); i < size; i++) { final XYPlot plot = this.chartJDialog.getPlot(i); final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(); // So far, for subplot, each of them only have 1 series. assert (1 == timeSeriesCollection.getSeriesCount()); for (int j = 0, size2 = timeSeriesCollection.getSeriesCount(); j < size2; j++) { final TimeSeries timeSeries = timeSeriesCollection.getSeries(j); /* Time consuming. */ final int dataIndex = getDataIndex(timeSeries, day); if (dataIndex < 0) { continue; } final Point2D point = this.getPoint(i, j, dataIndex); final String name = this.getLegendName(i, j); final Number value = this.getValue(i, j, dataIndex); if (point == null || name == null || value == null) { continue; } final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(i) .getDataArea(); if (plotArea.contains(point)) { this.indicatorTraceInfos.add(TraceInfo.newInstance(point, i, j, dataIndex)); } else { this.indicatorTraceInfos.add(TraceInfo.newInstance(null, i, j, dataIndex)); } } } }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java
public static XYDataset createLineDataset(DataItems dataitems1, DataItems dataitems2, Map<String, ArrayList<LinePos>> mapAB, XYPlot xyplot) { // ????/*w w w .jav a 2 s . c o m*/ int modelcount = mapAB.keySet().size(); long off1 = dataitems1.getElementAt(0).getTime().getTime(); long off2 = dataitems2.getElementAt(0).getTime().getTime(); long unit = 0; if (dataitems1.getLength() > 0) { unit = dataitems1.getElementAt(1).getTime().getTime() - off1; } else { unit = 3600000; } XYSeriesCollection xyseriescollection = new XYSeriesCollection(); // ?? int colorindex = 0; int renderercount = 2; for (Object se : mapAB.keySet()) { ArrayList<LinePos> s = mapAB.get(se); int oneModelCount = s.size(); ArrayList<DataItems> dslist = new ArrayList<DataItems>(); Iterator it = s.iterator(); System.out.println("**************"); System.out.println("?=" + se + ":=" + oneModelCount); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(); // ??? xylineandshaperenderer.setBaseShapesVisible(false); // ?? xylineandshaperenderer.setSeriesLinesVisible(0, true); // xylineandshaperenderer.setSeriesShape(0, double1); //? // xylineandshaperenderer.setSeriesPaint(0, getcolor(colorindex % 9)); xylineandshaperenderer.setSeriesFillPaint(0, getcolor(colorindex % 9)); xylineandshaperenderer.setSeriesOutlinePaint(0, getcolor(colorindex % 9)); colorindex++; xylineandshaperenderer.setUseFillPaint(true); xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer.setBaseShapesVisible(false); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1.0F, 1, 1, 1.0F, new float[] { 15F, 12F }, 0.0F)); // xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer.setBaseItemLabelsVisible(false); while (it.hasNext()) { LinePos temp = (LinePos) it.next(); DataItem d1 = new DataItem(); d1 = dataitems1.getElementAt(temp.A_start); DataItem d2 = new DataItem(); d2 = dataitems2.getElementAt(temp.B_start); DataItems ds1 = new DataItems(); ds1.add1Data(d1); ds1.add1Data(d2); // dslist.add(ds1); XYDataset xydataset1 = createmodeDataset(ds1, off1, se.toString() + ":" + 1, unit); DataItem d3 = new DataItem(); d3 = dataitems1.getElementAt(temp.A_end); DataItem d4 = new DataItem(); d4 = dataitems2.getElementAt(temp.B_end); DataItems ds2 = new DataItems(); ds2.add1Data(d3); ds2.add1Data(d4); // dslist.add(ds2); XYDataset xydataset2 = createmodeDataset(ds2, off1, se.toString() + ":" + 2, unit); int datasetCount = xyplot.getDatasetCount(); XYTextAnnotation localXYTextAnnotation = null; int modelx = (temp.A_start + temp.B_end) / 2; double modely = (Double.parseDouble(dataitems2.getElementAt(temp.A_start).getData()) + Double.parseDouble(dataitems1.getElementAt(temp.B_end).getData())) / 2; /*System.out.println("se=" + se + "::" + "x=" + modelx + "y=" + modely);*/ localXYTextAnnotation = new XYTextAnnotation("" + se + ":" + oneModelCount, modelx, modely); xyplot.addAnnotation(localXYTextAnnotation); /*System.out.println("datasetCount=" + datasetCount);*/ xyplot.setDataset(datasetCount, xydataset1); xyplot.setRenderer(datasetCount, xylineandshaperenderer); xyplot.setDataset(datasetCount + 1, xydataset2); xyplot.setRenderer(datasetCount + 1, xylineandshaperenderer); } } return xyseriescollection; }