List of usage examples for org.jfree.chart.plot XYPlot getDataset
public XYDataset getDataset(int index)
From source file:com.chart.SwingChart.java
/** * /*from ww w. ja v a2s . com*/ * @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 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); }// ww w . j av a 2 s. co 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: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 v a 2s .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.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://from w w w . j a v a 2 s . 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 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 ww w. j ava 2s .co m 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:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotFunctionSample(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape, double minX, double maxX, List<String> warnings) throws ConvertException { double[][] functionPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); double[][] samplePoints; if (!inverse) { samplePoints = plotable.getFunctionSamplePoints(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, warnings); } else {/*from w w w .j av a 2 s .c o m*/ samplePoints = plotable.getInverseFunctionSamplePoints(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, warnings); } 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); } if (addInfoInLegend) { legend = longLegend.get(id); } if (color == null) { color = defaultColor; } if (shape == null) { shape = defaultShape; } if (functionPoints != 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 < functionPoints[0].length; j++) { double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j]; series.add(functionPoints[0][j], functionPoints[1][j], functionPoints[1][j] - error, functionPoints[1][j] + error); } functionDataset.addSeries(series); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesFillPaint(0, color); functionRenderer.setSeriesShape(0, shape); if (samplePoints != 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, functionPoints); functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); functionRenderer.setSeriesPaint(0, color); functionRenderer.setSeriesShape(0, shape); if (samplePoints != null) { functionRenderer.setBaseSeriesVisibleInLegend(false); } plot.setDataset(i, functionDataset); plot.setRenderer(i, functionRenderer); } if (samplePoints != null) { DefaultXYDataset sampleDataset = new DefaultXYDataset(); XYLineAndShapeRenderer sampleRenderer = new XYLineAndShapeRenderer(false, true); sampleDataset.addSeries(legend, samplePoints); sampleRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); sampleRenderer.setSeriesPaint(0, color); sampleRenderer.setSeriesShape(0, shape); plot.setDataset(i + 1, sampleDataset); plot.setRenderer(i + 1, sampleRenderer); } } }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotBothStrict(XYPlot plot, Plotable plotable, String id, double minX, double maxX) throws ConvertException { String legend = shortLegend.get(id); List<Color> colorList = colorLists.get(id); List<Shape> shapeList = shapeLists.get(id); ColorAndShapeCreator creator = new ColorAndShapeCreator(plotable.getNumberOfCombinations()); int index = 0; if (addInfoInLegend) { legend = longLegend.get(id);// w ww .j ava 2 s . com } if (colorList == null || colorList.isEmpty()) { colorList = creator.getColorList(); } if (shapeList == null || shapeList.isEmpty()) { shapeList = creator.getShapeList(); } for (Map<String, Integer> choiceMap : plotable.getAllChoices()) { double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY, choiceMap); if (dataPoints == null) { continue; } double[][] modelPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, choiceMap); if (modelPoints == null) { continue; } double[][] modelErrors = null; if (showConfidenceInterval) { modelErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, choiceMap); } int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } String addLegend = ""; for (String arg : choiceMap.keySet()) { if (!arg.equals(paramX)) { addLegend += " (" + arg + "=" + plotable.getFunctionArguments().get(arg).get(choiceMap.get(arg)) + ")"; } } if (modelErrors != null) { YIntervalSeriesCollection modelSet = new YIntervalSeriesCollection(); DeviationRenderer modelRenderer = new DeviationRenderer(true, false); YIntervalSeries series = new YIntervalSeries(legend); for (int j = 0; j < modelPoints[0].length; j++) { double error = Double.isNaN(modelErrors[1][j]) ? 0.0 : modelErrors[1][j]; series.add(modelPoints[0][j], modelPoints[1][j], modelPoints[1][j] - error, modelPoints[1][j] + error); } modelSet.addSeries(series); modelRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); modelRenderer.setSeriesPaint(0, colorList.get(index)); modelRenderer.setSeriesFillPaint(0, colorList.get(index)); modelRenderer.setSeriesShape(0, shapeList.get(index)); if (dataPoints != null) { modelRenderer.setBaseSeriesVisibleInLegend(false); } plot.setDataset(i, modelSet); plot.setRenderer(i, modelRenderer); } else { DefaultXYDataset modelSet = new DefaultXYDataset(); XYLineAndShapeRenderer modelRenderer = new XYLineAndShapeRenderer(true, false); modelSet.addSeries(legend + addLegend, modelPoints); modelRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); modelRenderer.setBaseSeriesVisibleInLegend(false); modelRenderer.setSeriesPaint(0, colorList.get(index)); modelRenderer.setSeriesShape(0, shapeList.get(index)); plot.setDataset(i, modelSet); plot.setRenderer(i, modelRenderer); } DefaultXYDataset dataSet = new DefaultXYDataset(); XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true); dataSet.addSeries(legend + addLegend, dataPoints); dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); dataRenderer.setSeriesPaint(0, colorList.get(index)); dataRenderer.setSeriesShape(0, shapeList.get(index)); plot.setDataset(i + 1, dataSet); plot.setRenderer(i + 1, dataRenderer); index++; } }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotDataSetStrict(XYPlot plot, Plotable plotable, String id) throws ConvertException { String legend = shortLegend.get(id); List<Color> colorList = colorLists.get(id); List<Shape> shapeList = shapeLists.get(id); ColorAndShapeCreator creator = new ColorAndShapeCreator(plotable.getNumberOfCombinations()); int index = 0; if (addInfoInLegend) { legend = longLegend.get(id);//from w ww . j av a2 s . c o m } if (colorList == null || colorList.isEmpty()) { colorList = creator.getColorList(); } if (shapeList == null || shapeList.isEmpty()) { shapeList = creator.getShapeList(); } for (Map<String, Integer> choiceMap : plotable.getAllChoices()) { double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY, choiceMap); if (dataPoints != null) { DefaultXYDataset dataSet = new DefaultXYDataset(); XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true); String addLegend = ""; for (String arg : choiceMap.keySet()) { if (!arg.equals(paramX)) { addLegend += " (" + arg + "=" + plotable.getFunctionArguments().get(arg).get(choiceMap.get(arg)) + ")"; } } dataSet.addSeries(legend + addLegend, dataPoints); dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); dataRenderer.setSeriesPaint(0, colorList.get(index)); dataRenderer.setSeriesShape(0, shapeList.get(index)); int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } plot.setDataset(i, dataSet); plot.setRenderer(i, dataRenderer); } index++; } }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
void createSeries(final IScope scope, final boolean isTimeSeries) throws GamaRuntimeException { final XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setTickLabelFont(getTickFont()); domainAxis.setLabelFont(getLabelFont()); if (isTimeSeries) { domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (timeSeriesXData == null) { timeSeriesXData = (ChartDataStatement) DescriptionFactory.create(IKeyword.DATA, description, IKeyword.LEGEND, xAxisName, IKeyword.VALUE, SimulationAgent.CYCLE).compile(); if (getFacet(IKeyword.TIMEXSERIES) != null) { timeSeriesXData.getDescription().getFacets().get(IKeyword.VALUE) .setExpression(getFacet(IKeyword.TIMEXSERIES)); }// w w w . j a va 2 s .co m } // FIXME: datas can NOT contain timeSeriesXData (a ChartDataStatement and not a ChartData) if (!datas.contains(timeSeriesXData)) { datas.add(0, timeSeriesXData.createData(scope)); } } IExpression expr = getFacet(XRANGE); IExpression expr2 = getFacet(XTICKUNIT); if (expr != null) { Object range = expr.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { domainAxis.setFixedAutoRange(r); domainAxis.setAutoRangeMinimumSize(r); } domainAxis.setAutoRangeIncludesZero(false); } else if (range instanceof GamaPoint) { domainAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY()); } } if (expr2 != null) { Object range = expr2.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { domainAxis.setTickUnit(new NumberTickUnit(r)); } } } if (datas.size() > 0) { domainAxis.setLabel(datas.get(0).getName()); } final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setTickLabelFont(getTickFont()); yAxis.setLabelFont(getLabelFont()); expr = getFacet(YRANGE); expr2 = getFacet(YTICKUNIT); if (expr != null) { Object range = expr.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setFixedAutoRange(r); yAxis.setAutoRangeMinimumSize(r); } yAxis.setAutoRangeIncludesZero(false); } else if (range instanceof GamaPoint) { yAxis.setRange(((GamaPoint) range).getX(), ((GamaPoint) range).getY()); } } if (expr2 != null) { Object range = expr2.value(scope); // Double range = Cast.asFloat(scope, expr.value(scope)); if (range instanceof Number) { double r = ((Number) range).doubleValue(); if (r > 0) { yAxis.setTickUnit(new NumberTickUnit(r)); } } } if (datas.size() == 2) { yAxis.setLabel(datas.get(1).getName()); chart.removeLegend(); } final LegendTitle ll = chart.getLegend(); if (ll != null) { ll.setItemFont(getLegendFont()); } for (int i = 0; i < datas.size(); i++) { ChartData e = datas.get(i); final String legend = e.getName(); if (i != 0 | !isTimeSeries) { // the first data is the domain XYDataset data = plot.getDataset(i); XYSeries serie = new XYSeries(0, false, false); if (type == SERIES_CHART || type == XY_CHART) { dataset = new DefaultTableXYDataset(); // final XYSeries nserie = new XYSeries(serie.getKey(), false, false); final XYSeries nserie = new XYSeries(e.getName(), false, false); ((DefaultTableXYDataset) dataset).addSeries(nserie); } if (type == SCATTER_CHART) { dataset = new XYSeriesCollection(); final XYSeries nserie = new XYSeries(e.getName(), false, true); // final XYSeries nserie = new XYSeries(serie.getKey(), false, true); ((XYSeriesCollection) dataset).addSeries(nserie); } // dataset = new DefaultTableXYDataset(); // final XYSeries serie = new XYSeries(legend, false, false); // final XYSeries serie = new XYSeries(legend, false, true); // ((DefaultTableXYDataset) dataset).addSeries(serie); expressions_index.put(legend, i); plot.setRenderer(i, (XYItemRenderer) e.getRenderer(), false); // final Color c = e.getColor(); // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesPaint(0, c); // TODO Control this with a facet // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setBaseShapesFilled(false); // TODO Control this with a facet // ((XYLineAndShapeRenderer) plot.getRenderer(i)).setSeriesShapesVisible(0, false); // if (type==SERIES_CHART) // plot.setDataset(i-1, (DefaultTableXYDataset) dataset); // else plot.setDataset(i, (XYDataset) dataset); } history.append(legend); history.append(','); } if (history.length() > 0) { history.deleteCharAt(history.length() - 1); } history.append(Strings.LN); }
From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java
private XYPlot getXYPlot(List<cfCHARTSERIESData> series, String xAxisTitle, String yAxisTitle, String labelFormat, boolean bShowMarkers, int markerSize, boolean bShow3D, String tipStyle, String drillDownUrl, int xOffset, int yOffset, int yAxisUnits, String seriesPlacement, int height, int gridLines) throws cfmRunTimeException { // Create an XY plot XYPlot plot = new XYPlot(); ValueAxis domainAxis;/*www .j a va2 s .c o m*/ if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_NUMERIC_SERIES) { if (bShow3D) domainAxis = new NumberAxis3D(xAxisTitle); else domainAxis = new NumberAxis(xAxisTitle); } else { domainAxis = new DateAxis(xAxisTitle); } plot.setDomainAxis(domainAxis); ValueAxis valueAxis; DateFormat dateFormat = null; NumberFormat numberFormat = null; if (labelFormat.equals("date")) { valueAxis = new DateAxis(yAxisTitle); dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); ((DateAxis) valueAxis).setDateFormatOverride(dateFormat); } else { if (bShow3D) valueAxis = new NumberAxis3D(yAxisTitle); else valueAxis = new NumberAxis(yAxisTitle); if (labelFormat.equals("currency")) { ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getCurrencyInstance()); numberFormat = NumberFormat.getCurrencyInstance(); } else if (labelFormat.equals("percent")) { numberFormat = NumberFormat.getPercentInstance(); numberFormat.setMaximumFractionDigits(3); // without this change .11443 // would be displayed as 11% // instead of 11.443% ((NumberAxis) valueAxis).setNumberFormatOverride(numberFormat); } else { numberFormat = NumberFormat.getInstance(); } if (yAxisUnits != 0) ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits)); } plot.setRangeAxis(valueAxis); // Add a dataset and renderer for each series int barChartDatasetIndex = -1; int hBarChartDatasetIndex = -1; int num = 0; MinMaxData minMax = new MinMaxData(); for (int i = 0; i < series.size(); i++) { cfCHARTSERIESData seriesData = series.get(i); XYSeriesCollection dataset; if ((barChartDatasetIndex != -1) && (seriesData.getType().equals("bar"))) { dataset = (XYSeriesCollection) plot.getDataset(barChartDatasetIndex); addSeriesDataToDataset(seriesData, dataset, minMax); // Set the paint style for this series setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(barChartDatasetIndex), dataset.getSeriesCount() - 1, height); // Add the color list for this series to the custom color renderer CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(barChartDatasetIndex); cr.addColors(getColorList(seriesData)); continue; } else if ((hBarChartDatasetIndex != -1) && (seriesData.getType().equals("horizontalbar"))) { dataset = (XYSeriesCollection) plot.getDataset(hBarChartDatasetIndex); addSeriesDataToDataset(seriesData, dataset, minMax); // Set the paint style for this series setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(hBarChartDatasetIndex), dataset.getSeriesCount() - 1, height); // Add the color list for this series to the custom color renderer CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(hBarChartDatasetIndex); cr.addColors(getColorList(seriesData)); continue; } else { dataset = new XYSeriesCollection(); addSeriesDataToDataset(seriesData, dataset, minMax); } plot.setDataset(num, dataset); XYItemRenderer renderer = null; if (seriesData.getType().equals("bar")) { plot.setOrientation(PlotOrientation.VERTICAL); renderer = getXYBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData)); ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); renderer.setNegativeItemLabelPosition(position2); ((XYBarRenderer) renderer).setMargin(0.2); // The margin between each // category barChartDatasetIndex = num; } else if (seriesData.getType().equals("horizontalbar")) { plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); renderer = getXYBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData)); ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); renderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); renderer.setNegativeItemLabelPosition(position2); ((XYBarRenderer) renderer).setMargin(0.2); // The margin between each // category hBarChartDatasetIndex = num; } else if (seriesData.getType().equals("line")) { renderer = new XYLineAndShapeRenderer(true, false); // Enable/Disable displaying of markers ((XYLineAndShapeRenderer) renderer).setShapesVisible(bShowMarkers); // Set the shape of the markers based on the markerSize value ((XYLineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize)); } else if (seriesData.getType().equals("area")) { renderer = new CustomXYAreaRenderer(); } else if (seriesData.getType().equals("step")) { renderer = new CustomXYStepRenderer(); } else if (seriesData.getType().equals("scatter")) { renderer = new XYLineAndShapeRenderer(false, true); // Set the shape of the markers based on the markerSize value ((XYLineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize)); } if (!tipStyle.equals("none")) { if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: {1}", DateFormat.getInstance(), DateFormat.getInstance())); } else { if (dateFormat != null) renderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator("{0}: {2}", dateFormat, dateFormat)); else renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", numberFormat, NumberFormat.getInstance())); } } if (drillDownUrl != null) { if (dateFormat != null) renderer.setURLGenerator( new com.newatlanta.bluedragon.XYURLGenerator(drillDownUrl, dateFormat)); else renderer.setURLGenerator( new com.newatlanta.bluedragon.XYURLGenerator(drillDownUrl, numberFormat)); } if (seriesData.getSeriesColor() != null) renderer.setSeriesPaint(0, convertStringToColor(seriesData.getSeriesColor())); String dataLabelStyle = seriesData.getDataLabelStyle(); if (labelFormat.equals("date")) { if (dataLabelStyle.equals("none")) { renderer.setItemLabelsVisible(false); } else { setXYItemLabelsData(renderer, seriesData); if (dataLabelStyle.equals("value")) renderer.setItemLabelGenerator( new StandardXYItemLabelGenerator("{2}", dateFormat, dateFormat)); else if (dataLabelStyle.equals("rowlabel")) renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{0}", NumberFormat.getInstance(), NumberFormat.getInstance())); else if (dataLabelStyle.equals("columnlabel")) renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}", NumberFormat.getInstance(), NumberFormat.getInstance())); else if (dataLabelStyle.equals("pattern")) renderer.setItemLabelGenerator(new XYItemLabelGenerator("{2}", dateFormat, dateFormat)); else renderer.setItemLabelGenerator( new XYItemLabelGenerator(dataLabelStyle, dateFormat, dateFormat)); } } else { if (dataLabelStyle.equals("none")) { renderer.setItemLabelsVisible(false); } else { setXYItemLabelsData(renderer, seriesData); if (dataLabelStyle.equals("value")) { renderer.setItemLabelGenerator( new StandardXYItemLabelGenerator("{2}", numberFormat, numberFormat)); } else if (dataLabelStyle.equals("rowlabel")) { renderer.setItemLabelGenerator( new StandardXYItemLabelGenerator("{0}", numberFormat, numberFormat)); } else if (dataLabelStyle.equals("columnlabel")) { if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) { renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}", SimpleDateFormat.getInstance(), NumberFormat.getInstance())); } else { renderer.setItemLabelGenerator(new StandardXYItemLabelGenerator("{1}", NumberFormat.getInstance(), NumberFormat.getInstance())); } } else if (dataLabelStyle.equals("pattern")) { if (series.get(0).getSeriesDataType() == cfCHARTSERIESData.XY_DATE_SERIES) { renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})", SimpleDateFormat.getInstance(), numberFormat)); } else { renderer.setItemLabelGenerator(new XYItemLabelGenerator("{1} {2} ({3} of {4})", NumberFormat.getInstance(), numberFormat)); } } else { renderer.setItemLabelGenerator( new XYItemLabelGenerator(dataLabelStyle, NumberFormat.getInstance(), numberFormat)); } } } // Add the renderer to the plot. // NOTE: this must be done before the setPaintStyle() call so the // DrawingSupplier object // will be set up properly for the generation of default colors. plot.setRenderer(num, renderer); // Set the paint style for this series (series 0) if (seriesData.getType().equals("bar") || seriesData.getType().equals("horizontalbar") || seriesData.getType().equals("area")) setPaintStyle(seriesData.getPaintStyle(), renderer, 0, height); num++; } // If gridLines was specified then we need to calculate the yAxisUnits if ((gridLines != -1) && (valueAxis instanceof NumberAxis)) { // Calculate the yAxisUnits we need to use to create the number of // gridLines yAxisUnits = calculateYAxisUnits(gridLines, minMax); // Set the yAxisUnits ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits)); } return plot; }