List of usage examples for org.jfree.data.xy XYSeries getKey
public Comparable getKey()
From source file:org.esa.snap.rcp.statistics.ScatterPlotPanel.java
private XYIntervalSeries computeRegressionData(double xStart, double xEnd) { if (scatterpointsDataset.getItemCount(0) > 1) { final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0); final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]); final XYSeries regressionData = DatasetUtilities.sampleFunction2DToSeries(curve, xStart, xEnd, 100, "regression line"); final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey()); for (int i = 0; i < regressionData.getItemCount(); i++) { XYDataItem item = regressionData.getDataItem(i); final double x = item.getXValue(); final double y = item.getYValue(); xyIntervalRegression.add(x, x, x, y, y, y); }/*w w w . j a v a 2 s .co m*/ return xyIntervalRegression; } else { JOptionPane.showMessageDialog(this, "Unable to compute regression line.\n" + "At least 2 values are needed to compute regression coefficients."); return null; } }
From source file:com.chart.SwingChart.java
/** * Clear a series//from w w w .j a v a 2s . c o m * @param seriesName Name of series to clear */ public void clear(String seriesName) { for (XYSeries serie : seriesList) { if (serie.getKey().toString().equals(seriesName)) { serie.clear(); break; } } }
From source file:com.chart.SwingChart.java
/** * Add sample to a series/*from w w w. j a v a 2 s .c o m*/ * @param x Abcissa * @param y Ordinate * @param seriesName Series name */ @Override public void addSample(double x, double y, String seriesName) { for (XYSeries serie : seriesList) { if (serie.getKey().toString().equals(seriesName)) { serie.add(x, y); break; } } }
From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java
private XYIntervalSeries computeRegressionData(double xStart, double xEnd) { if (scatterpointsDataset.getItemCount(0) > 1) { final double[] coefficients = Regression.getOLSRegression(scatterpointsDataset, 0); final Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]); final XYSeries regressionData = DatasetUtilities.sampleFunction2DToSeries(curve, xStart, xEnd, 100, "regression line"); final XYIntervalSeries xyIntervalRegression = new XYIntervalSeries(regressionData.getKey()); final List<XYDataItem> regressionDataItems = regressionData.getItems(); for (XYDataItem item : regressionDataItems) { final double x = item.getXValue(); final double y = item.getYValue(); xyIntervalRegression.add(x, x, x, y, y, y); }/*from w w w .ja v a 2s .c o m*/ return xyIntervalRegression; } else { JOptionPane.showMessageDialog(this, "Unable to compute regression line.\n" + "At least 2 values are needed to compute regression coefficients."); return null; } }
From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java
private XYIntervalSeries computeAcceptableDeviationData(double lowerBound, double upperBound) { final Function2D identityFunction = new Function2D() { @Override/*from w w w . jav a 2 s . c o m*/ public double getValue(double x) { return x; } }; final XYSeries identity = DatasetUtilities.sampleFunction2DToSeries(identityFunction, lowerBound, upperBound, 100, "1:1 line"); final XYIntervalSeries xyIntervalSeries = new XYIntervalSeries(identity.getKey()); final List<XYDataItem> items = identity.getItems(); for (XYDataItem item : items) { final double x = item.getXValue(); final double y = item.getYValue(); if (scatterPlotModel.showAcceptableDeviation) { final double acceptableDeviation = scatterPlotModel.acceptableDeviationInterval; final double xOff = acceptableDeviation * x / 100; final double yOff = acceptableDeviation * y / 100; xyIntervalSeries.add(x, x - xOff, x + xOff, y, y - yOff, y + yOff); } else { xyIntervalSeries.add(x, x, x, y, y, y); } } return xyIntervalSeries; }
From source file:com.chart.SwingChart.java
/** * Export chart values to a csv file//from w w w . j a va 2 s.c o m * @param file CSV file */ private void export(File file) { String registro; int n = 0; int ne = 0; String cabecera = "Time;"; for (int i = 0; i < plot.getDatasetCount(); i++) { XYSeriesCollection ds = (XYSeriesCollection) plot.getDataset(i); for (int j = 0; j < ds.getSeriesCount(); j++) { n++; XYSeries s = (XYSeries) ds.getSeries(j); cabecera += s.getKey().toString() + ";"; if (n == 1) { ne = s.getItemCount(); } } } String[][] exportacion = new String[ne][n + 1]; n = 0; for (int i = 0; i < plot.getDatasetCount(); i++) { XYSeriesCollection ds = (XYSeriesCollection) plot.getDataset(i); for (int j = 0; j < ds.getSeriesCount(); j++) { XYSeries s = (XYSeries) ds.getSeries(j); n++; for (int e = 0; e < ne; e++) { try { exportacion[e][n] = ordinateFormat.format(s.getDataItem(e).getYValue()); } catch (Exception ex) { exportacion[e][n] = ""; } if (n == 1) { exportacion[e][0] = abcissaFormat.format(s.getDataItem(e).getXValue()); } } } } FileWriter fichero; PrintWriter pw; try { fichero = new FileWriter(file.getAbsolutePath(), false); pw = new PrintWriter(fichero); pw.println(cabecera); for (String[] exp : exportacion) { String strRegistro = ""; for (String e : exp) { strRegistro += e + ";"; } pw.println(strRegistro); } pw.close(); } catch (IOException ex) { Global.info.log(ex); } }
From source file:com.planetmayo.debrief.satc_rcp.views.SpatialView.java
private void showBoundedStates(Collection<BoundedState> newStates) { if (newStates.isEmpty()) { return;//from w w w.java2 s. c o m } // just double-check that we're showing any states if (!_settings.isShowLegEndBounds() && !_settings.isShowAllBounds()) return; String lastSeries = "UNSET"; BoundedState lastState = null; int turnCounter = 1; int colourCounter = 0; @SuppressWarnings("rawtypes") HashMap<Comparable, Integer> keyToLegTypeMapping = new HashMap<Comparable, Integer>(); // and plot the new data Iterator<BoundedState> iter = newStates.iterator(); while (iter.hasNext()) { BoundedState thisS = iter.next(); // get the poly LocationRange loc = thisS.getLocation(); // ok, color code the series String thisSeries = thisS.getMemberOf(); if (loc != null) { boolean showThisState = false; // ok, what about the name? String legName = ""; if (thisSeries != lastSeries) { // are we storing leg ends? if (_settings.isShowLegEndBounds() || (lastSeries == null)) { showThisState = true; if (thisSeries != null) legName = thisSeries; else legName = "Turn " + turnCounter++; } colourCounter++; // and remember the new series lastSeries = thisSeries; } // are we adding this leg? // if (!showThisState) // { // no, but are we showing mid=leg states? if (_settings.isShowAllBounds()) { // yes - we do want mid-way stats, better add it. showThisState = true; if (legName.length() > 0) legName = "(" + legName + ") "; legName += _legendDateFormat.format(thisS.getTime()); } // } // right then do we create a shape (series) for this one? if (showThisState) { // right, but do we show it for the new, or old state if (thisS.getMemberOf() == null) { // right, we're already in a turn. use the last one if (lastState != null) loc = lastState.getLocation(); } else { // right this is the first point in a new leg. use this one loc = thisS.getLocation(); } // check we've found a shape if (loc != null) { // ok, we've got a new series XYSeries series = new XYSeries(legName, false); Geometry geometry = loc.getGeometry(); Coordinate[] boundary = geometry.getCoordinates(); for (int i = 0; i < boundary.length; i++) { Coordinate coordinate = boundary[i]; series.add(new XYDataItem(coordinate.y, coordinate.x)); } keyToLegTypeMapping.put(series.getKey(), colourCounter); _myData.addSeries(series); int seriesIndex = _myData.getSeriesCount() - 1; // final float dash1[] = // { 10f, 10f }; // final BasicStroke dashed = new BasicStroke(1.0f , // BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, // 0.0f); final BasicStroke dashed = new BasicStroke(1f); _renderer.setSeriesStroke(seriesIndex, dashed); // _renderer.setSeriesStroke(seriesIndex, new BasicStroke()); _renderer.setSeriesLinesVisible(seriesIndex, true); _renderer.setSeriesShapesVisible(seriesIndex, false); } } } // and move on lastState = thisS; } Color[] colorsList = getDifferentColors(colourCounter); // paint each series with color depending on leg type. for (Comparable<?> key : keyToLegTypeMapping.keySet()) { _renderer.setSeriesPaint(_myData.getSeriesIndex(key), colorsList[keyToLegTypeMapping.get(key) - 1]); } }
From source file:cs.cirg.cida.CIDAView.java
@Action public void plotGraph() { lineSeriesComboBox.removeAllItems(); int numSelectedColumns = userSelectedColumns.size(); int numSelectedRows = userSelectedRows.size(); if (numSelectedColumns == 0) { return;/*w ww .j a v a 2 s .c om*/ } StandardDataTable<Numeric> data = (StandardDataTable<Numeric>) ((IOBridgeTableModel) analysisTable .getModel()).getDataTable(); List<Numeric> iterations = data.getColumn(0); XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); for (int i = 0; i < numSelectedColumns; i++) { int selectedColumnIndex = userSelectedColumns.get(i); List<Numeric> selectedColumn = data.getColumn(selectedColumnIndex); XYSeries series = new XYSeries(data.getColumnName(selectedColumnIndex)); for (int k = 0; k < numSelectedRows; k++) { int selectedRowIndex = userSelectedRows.get(k); series.add(iterations.get(selectedRowIndex).getReal(), selectedColumn.get(selectedRowIndex).getReal()); } xySeriesCollection.addSeries(series); lineSeriesComboBox.addItem(new SeriesPair(i, (String) series.getKey())); } String chartName = experimentController.getAnalysisName(); if (chartName.compareTo("") == 0) { chartName = CIDAConstants.DEFAULT_CHART_NAME; } JFreeChart chart = ChartFactory.createXYLineChart(chartName, // Title CIDAConstants.CHART_ITERATIONS_LABEL, // X-Axis label CIDAConstants.CHART_VALUE_LABEL, // Y-Axis label xySeriesCollection, // Dataset PlotOrientation.VERTICAL, true, // Show legend, false, //tooltips false //urls ); chart.setAntiAlias(true); chart.setAntiAlias(true); XYPlot plot = (XYPlot) chart.getPlot(); Paint[] paints = new Paint[7]; paints[0] = Color.RED; paints[1] = Color.BLUE; paints[2] = new Color(0.08f, 0.5f, 0.04f); paints[3] = new Color(1.0f, 0.37f, 0.0f); paints[4] = new Color(0.38f, 0.07f, 0.42f); paints[5] = Color.CYAN; paints[6] = Color.PINK; plot.setDrawingSupplier( new DefaultDrawingSupplier(paints, paints, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.GRAY); plot.setRangeGridlinePaint(Color.GRAY); IntervalXYRenderer renderer = new IntervalXYRenderer(true, false); plot.setRenderer(renderer); lineTickIntervalInput.setText(Integer.toString(renderer.getLineTickInterval())); ((ChartPanel) chartPanel).setChart(chart); }
From source file:com.jtstand.swing.StatsPanel.java
public JFreeChart getChartValues(Iterator<TestStepInstance> values) { if (values == null || !values.hasNext()) { return null; }/*from www .j ava2s. c o m*/ XYSeriesCollection dataset = new XYSeriesCollection(); int count = 0; TreeMap<String, XYSeries> map = new TreeMap<String, XYSeries>(); while (values.hasNext()) { TestStepInstance step = values.next(); Number num = getNumber(step); if (num != null) { String groupName = getGroupName(step); XYSeries pop = map.get(groupName); if (pop == null) { pop = new XYSeries(groupName); map.put(groupName, pop); } pop.add(++count, num.doubleValue()); } } for (Iterator<XYSeries> it = map.values().iterator(); it.hasNext();) { dataset.addSeries(it.next()); } // NumberAxis xAxis = new NumberAxis("#"); NumberAxis xAxis = new NumberAxis(); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(getValueString()); yAxis.setAutoRangeIncludesZero(false); XYLineAndShapeRenderer renderer6 = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer6); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeCrosshairVisible(true); plot.setDomainCrosshairVisible(true); renderer6.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer6.setBaseSeriesVisibleInLegend(false); // StandardXYItemLabelGenerator itemlabels=new StandardXYItemLabelGenerator(); // renderer.setBaseItemLabelGenerator(itemlabels); // renderer.setBaseItemLabelsVisible(true); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping()); //chart.setTitle(title); placeLimitMarkers(plot, true); /* coloring */ if (isCategorization()) { // TreeMap<String, Color> cmap = new TreeMap<String, Color>(); int i = 0; for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) { String groupName = it.next(); Color c = ChartCategories.getColor(i); for (int j = 0; j < dataset.getSeriesCount(); j++) { XYSeries s = dataset.getSeries(j); if (s.getKey().equals(groupName)) { renderer6.setSeriesPaint(j, c); } } } } else { renderer6.setSeriesPaint(0, ChartCategories.getColor(0)); } chart.setTextAntiAlias(false); return chart; }
From source file:com.vgi.mafscaling.VECalc.java
private boolean plotCorrectionData() { plot3d.removeAllPlots();/*w w w . jav a 2s . co m*/ XYSeries series; XYPlot plot = chartPanel.getChart().getXYPlot(); XYSeriesCollection lineDataset = (XYSeriesCollection) plot.getDataset(0); DecimalFormat df = new DecimalFormat(".00"); String val; int i = 0; int j = 0; if (!Utils.isTableEmpty(corrTable)) { try { for (i = 1; i < corrTable.getColumnCount(); ++i) { val = corrTable.getValueAt(0, i).toString(); series = new XYSeries(df.format(Double.valueOf(val))); for (j = 1; j < corrTable.getRowCount(); ++j) { if (corrTable.getValueAt(j, i) != null) { val = corrTable.getValueAt(j, i).toString(); if (!val.isEmpty()) series.add(Double.valueOf(corrTable.getValueAt(j, 0).toString()), Double.valueOf(val)); } } if (series.getItemCount() > 0) { corrData.add(series); series.setDescription(series.getKey().toString()); lineDataset.addSeries(series); } } plot.getDomainAxis(0).setAutoRange(true); plot.getRangeAxis(0).setAutoRange(true); plot.getDomainAxis(0).setLabel(xAxisName); plot.getRangeAxis(0).setLabel(yAxisName); plot.getRenderer(0).setSeriesVisible(0, false); double[] x = new double[xAxisArray.size()]; for (i = 0; i < xAxisArray.size(); ++i) x[i] = xAxisArray.get(i); double[] y = new double[yAxisArray.size()]; for (i = 0; i < yAxisArray.size(); ++i) y[i] = yAxisArray.get(i); double[][] z = Utils.doubleZArray(corrTable, x, y); Color[][] colors = Utils.generateTableColorMatrix(corrTable, 1, 1); plot3d.addGridPlot("Average Error % Plot", colors, x, y, z); } catch (NumberFormatException e) { logger.error(e); JOptionPane.showMessageDialog(null, "Error parsing number from " + corrTableName + " table, cell(" + i + " : " + j + "): " + e, "Error", JOptionPane.ERROR_MESSAGE); return false; } } return true; }