List of usage examples for org.jfree.data.xy XYSeriesCollection getSeries
public XYSeries getSeries(Comparable key)
From source file:com.anrisoftware.prefdialog.miscswing.multichart.freechart.FreechartXYChart.java
private void updateInsertData(int row0, int row1, int offset) { ChartModel model = this.model; XYSeriesCollection series = getCategory(); for (int col = 0; col < series.getSeriesCount(); col++) { XYSeries xyseries = series.getSeries(col); for (int row = row0; row <= row1; row++) { xyseries.add(row, model.getValueAt(row, col), false); }//from ww w.j a va 2 s .c o m xyseries.fireSeriesChanged(); } }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * A test for bug report 1170825.//w w w . ja va2 s . com */ @Test public void test1170825() { XYSeries s1 = new XYSeries("Series1"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); try { /* XYSeries s = */ dataset.getSeries(1); } catch (IllegalArgumentException e) { // correct outcome } catch (IndexOutOfBoundsException e) { assertTrue(false); // wrong outcome } }
From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java
/** * Test that a series belonging to a collection can be renamed (in fact, * because of a bug this was not possible in JFreeChart 1.0.14). *///from ww w . j av a 2 s . c o m public void testSeriesRename() { // first check that a valid renaming works XYSeries series1 = new XYSeries("A"); XYSeries series2 = new XYSeries("B"); XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series1); collection.addSeries(series2); series1.setKey("C"); assertEquals("C", collection.getSeries(0).getKey()); // next, check that setting a duplicate key fails try { series2.setKey("C"); } catch (IllegalArgumentException e) { // expected } assertEquals("B", series2.getKey()); // the series name should not // change because "C" is already the key for the other series in the // collection }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * Some basic checks for the getSeries() method. *//*from w w w . j av a 2 s .c o m*/ @Test public void testGetSeries() { XYSeriesCollection c = new XYSeriesCollection(); XYSeries s1 = new XYSeries("s1"); c.addSeries(s1); assertEquals("s1", c.getSeries(0).getKey()); try { c.getSeries(-1); fail("Should have thrown IndexOutOfBoundsException on negative key"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds", e.getMessage()); } try { c.getSeries(1); fail("Should have thrown IndexOutOfBoundsException on key out of range"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds", e.getMessage()); } }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * Some checks for the getSeries(Comparable) method. *//* w w w. j a v a 2 s . c o m*/ @Test public void testGetSeriesByKey() { XYSeriesCollection c = new XYSeriesCollection(); XYSeries s1 = new XYSeries("s1"); c.addSeries(s1); assertEquals("s1", c.getSeries("s1").getKey()); try { c.getSeries("s2"); fail("Should have thrown UnknownKeyException on unknown key"); } catch (UnknownKeyException e) { assertEquals("Key not found: s2", e.getMessage()); } try { c.getSeries(null); fail("Should have thrown IndexOutOfBoundsException on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } }
From source file:sim.app.sugarscape.util.ResultsGrapher.java
JFreeChart createChart1(XYSeries[] series) { JFreeChart chart3 = ChartFactory.createXYLineChart("Results", x_axis_fieldname, y_axis_fieldname, null, //new XYSeriesCollection(series[2]), PlotOrientation.VERTICAL, true, true, false); //System.out.println("Series count = " +series[0].getItemCount()); XYPlot plot = chart3.getXYPlot();//w w w . j av a 2s. c om ValueAxis yAxis = plot.getRangeAxis(); //xAxis.setFixedDimension(100); //yAxis.setFixedDimension(1.0); //yAxis.setRange(0,1); ValueAxis xAxis = plot.getDomainAxis(); //xAxis.setFixedDimension(50); StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); renderer.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 20)); renderer.setItemLabelsVisible(true); renderer.setSeriesItemLabelsVisible(1, true); renderer.setBaseShapesVisible(true); //XYLabelGenerator generator = new StandardXYLabelGenerator(); //"{2}", new DecimalFormat("0.00") ); //renderer.setLabelGenerator(generator); //NumberAxis axis2 = new NumberAxis("Average Agent Vision"); //renderer.setItemLabelsVisible(true); //axis2.setAutoRangeIncludesZero(false); //axis2.setRange(0,12); //plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision); //plot.setDataset(1, vision); //String first_letter = x_param_fieldname.substring(0,1)+"="; XYSeriesCollection xys = new XYSeriesCollection(); for (int a = 0; a < series.length; a++) { xys.addSeries(series[a]); //xys. //xys.getSeriesName(4); System.out.println(xys.getSeries(a).getDescription()); } plot.setDataset(0, xys); return chart3; }
From source file:com.anrisoftware.prefdialog.miscswing.multichart.freechart.FreechartXYChart.java
private void updateData0(int row0, int row1, int offset) { ChartModel model = this.model; XYSeriesCollection series = getCategory(); int col0 = 0; int col1 = series.getSeriesCount() - 1; for (int col = col0; col <= col1; col++) { XYSeries xyseries = series.getSeries(col); for (int row = row0; row <= row1; row++) { double value = model.getValueAt(row + offset, col); xyseries.updateByIndex(row, value); }// w w w .ja v a 2 s . co m } }
From source file:TradeMonitorGui.java
private void startGui() { XYSeriesCollection dataset = new XYSeriesCollection(); createChartFrame(dataset);/*from w ww . ja v a 2s. c o m*/ EntryAddedUpdatedListener<String, KeyedWindowResult<String, Double>> listener = (key, value) -> { if (!TICKERS.contains(key)) { return; } Long ts = value.end(); double val = value.result() / 100.0; int idx = dataset.getSeriesIndex(key); XYSeries series; if (idx == -1) { series = new XYSeries(key, true, false); dataset.addSeries(series); } else { series = dataset.getSeries(idx); } series.addOrUpdate((long) ts, val); }; this.listenerId = avgPrices.addEntryListener(listener, true); }
From source file:org.jfree.data.xy.XYSeriesCollectionTest.java
/** * Test that a series belonging to a collection can be renamed (in fact, * because of a bug this was not possible in JFreeChart 1.0.14). *///from ww w.j ava2 s .co m @Test public void testSeriesRename() { // first check that a valid renaming works XYSeries series1 = new XYSeries("A"); XYSeries series2 = new XYSeries("B"); XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series1); collection.addSeries(series2); series1.setKey("C"); assertEquals("C", collection.getSeries(0).getKey()); // next, check that setting a duplicate key fails try { series2.setKey("C"); fail("Expected an IllegalArgumentException."); } catch (IllegalArgumentException e) { // expected } assertEquals("B", series2.getKey()); // the series name should not // change because "C" is already the key for the other series in the // collection }
From source file:oct.analysis.application.OCTSelection.java
public JPanel createLRPPanel() { //create the series collection from the LRP data XYSeriesCollection lrp = new XYSeriesCollection(); lrp.addSeries(getLrpSeriesFromOCT(OCTAnalysisManager.getInstance().getOctImage())); // System.out.println("Processing graph " + lrp.getSeriesKey(0).toString()); lrp.addSeries(findMaximums(lrp.getSeries(0), selectionName + " LRP Maximums")); List<XYSeries> fwhm = getFWHMForLRPPeaks(lrp.getSeries(1), lrp.getSeries(0)); fwhm.forEach((fwhmSeries) -> {//w w w .j a v a 2s . c o m lrp.addSeries(fwhmSeries); }); //create chart panel for LRP JFreeChart chart = ChartFactory.createXYLineChart(lrp.getSeriesKey(0).toString(), "Pixel Height", "Reflectivity", lrp, PlotOrientation.HORIZONTAL, false, true, false); XYPlot plot = chart.getXYPlot(); // plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // plot.getDomainAxis().setInverted(true); //set up rendering principles XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShapesFilled(1, true); renderer.setSeriesPaint(1, Color.BLUE); for (int i = 2; i < fwhm.size() + 2; i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); renderer.setSeriesPaint(i, Color.BLACK); } plot.setRenderer(renderer); //make panel ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(200, 200)); panel.setFillZoomRectangle(true); panel.setMouseWheelEnabled(true); return panel; }