List of usage examples for org.jfree.data.xy DefaultXYDataset getSeriesKey
@Override public Comparable getSeriesKey(int series)
From source file:org.jfree.data.xy.DefaultXYDatasetTest.java
/** * Some checks for the getSeriesKey(int) method. *///from www.j a v a 2s . c o m @Test public void testGetSeriesKey() { DefaultXYDataset d = createSampleDataset1(); assertEquals("S1", d.getSeriesKey(0)); assertEquals("S2", d.getSeriesKey(1)); // check for series key out of bounds boolean pass = false; try { /*Comparable k =*/ d.getSeriesKey(-1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { /*Comparable k =*/ d.getSeriesKey(2); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.xy.junit.DefaultXYDatasetTest.java
/** * Some checks for the getSeriesKey(int) method. *//* w w w. ja v a 2s .c om*/ public void testGetSeriesKey() { DefaultXYDataset d = createSampleDataset1(); assertEquals("S1", d.getSeriesKey(0)); assertEquals("S2", d.getSeriesKey(1)); // check for series key out of bounds boolean pass = false; try { /*Comparable k =*/ d.getSeriesKey(-1); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); pass = false; try { /*Comparable k =*/ d.getSeriesKey(2); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.xy.DefaultXYDatasetTest.java
/** * Some tests for the addSeries() method. *///from ww w . j a v a 2 s . co m @Test public void testAddSeries() { DefaultXYDataset d = new DefaultXYDataset(); d.addSeries("S1", new double[][] { { 1.0 }, { 2.0 } }); assertEquals(1, d.getSeriesCount()); assertEquals("S1", d.getSeriesKey(0)); // check that adding a series will overwrite the old series d.addSeries("S1", new double[][] { { 11.0 }, { 12.0 } }); assertEquals(1, d.getSeriesCount()); assertEquals(12.0, d.getYValue(0, 0), EPSILON); // check null key boolean pass = false; try { d.addSeries(null, new double[][] { { 1.0 }, { 2.0 } }); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.xy.junit.DefaultXYDatasetTest.java
/** * Some tests for the addSeries() method. *//* w w w. jav a 2 s . c o m*/ public void testAddSeries() { DefaultXYDataset d = new DefaultXYDataset(); d.addSeries("S1", new double[][] { { 1.0 }, { 2.0 } }); assertEquals(1, d.getSeriesCount()); assertEquals("S1", d.getSeriesKey(0)); // check that adding a series will overwrite the old series d.addSeries("S1", new double[][] { { 11.0 }, { 12.0 } }); assertEquals(1, d.getSeriesCount()); assertEquals(12.0, d.getYValue(0, 0), EPSILON); // check null key boolean pass = false; try { d.addSeries(null, new double[][] { { 1.0 }, { 2.0 } }); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:net.bioclipse.chart.ChartUtils.java
public static void handleCellChangeEvent(CellChangedEvent e) { // Iterator<CellChangeListener> iterator = listeners.iterator(); // while( iterator.hasNext() ) // {/*w w w. j a va 2 s. c o m*/ // CellChangeListener listener = iterator.next(); // listener.handleCellChangeEvent(e); // } Set<JFreeChart> keySet = chartManager.keySet(); Iterator<JFreeChart> iterator = keySet.iterator(); while (iterator.hasNext()) { JFreeChart chart = iterator.next(); ChartDescriptor desc = chartManager.get(chart); String domainLabel = desc.getXLabel(); String rangeLabel = desc.getYLabel(); CellData data = e.getCellData(); if (domainLabel.equals(data.getColName()) || rangeLabel.equals(data.getColName())) { DefaultXYDataset dataset = (DefaultXYDataset) chart.getXYPlot().getDataset(); int itemCount = dataset.getItemCount(0); double[] yValues = new double[itemCount]; double[] xValues = new double[itemCount]; for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(0, i); double y = dataset.getYValue(0, i); xValues[i] = x; yValues[i] = y; } int indices[] = desc.getSourceIndices(); if (domainLabel.equals(e.getCellData().getColName())) { int rowIndex = data.getRowIndex(); for (int i = 0; i < indices.length; i++) { if (indices[i] == rowIndex) { xValues[i] = data.getValue(); } } } else if (rangeLabel.equals(e.getCellData().getColName())) { int rowIndex = data.getRowIndex(); for (int i = 0; i < indices.length; i++) { if (indices[i] == rowIndex) { yValues[i] = data.getValue(); } } } double[][] chartData = new double[2][]; chartData[0] = xValues; chartData[1] = yValues; dataset.getSeriesKey(0); Comparable seriesKey = dataset.getSeriesKey(0); dataset.removeSeries(seriesKey); dataset.addSeries(seriesKey, chartData); } } }
From source file:org.jfree.data.xy.XYSeriesTest.java
/** * Some checks for an example using the toArray() method. *//*from ww w.j ava2 s. c o m*/ @Test public void testToArrayExample() { XYSeries s = new XYSeries("S"); s.add(1.0, 11.0); s.add(2.0, 22.0); s.add(3.5, 35.0); s.add(5.0, null); DefaultXYDataset dataset = new DefaultXYDataset(); dataset.addSeries("S", s.toArray()); assertEquals(1, dataset.getSeriesCount()); assertEquals(4, dataset.getItemCount(0)); assertEquals("S", dataset.getSeriesKey(0)); assertEquals(1.0, dataset.getXValue(0, 0), EPSILON); assertEquals(2.0, dataset.getXValue(0, 1), EPSILON); assertEquals(3.5, dataset.getXValue(0, 2), EPSILON); assertEquals(5.0, dataset.getXValue(0, 3), EPSILON); assertEquals(11.0, dataset.getYValue(0, 0), EPSILON); assertEquals(22.0, dataset.getYValue(0, 1), EPSILON); assertEquals(35.0, dataset.getYValue(0, 2), EPSILON); assertTrue(Double.isNaN(dataset.getYValue(0, 3))); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.SimpleScatter.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false);/* w ww. j a v a 2 s .c o m*/ Font font = new Font("Tahoma", Font.BOLD, titleDimension); //TextTitle title = new TextTitle(name, font); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); chart.setBackgroundPaint(Color.white); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); int seriesN = dataset.getSeriesCount(); if (colorMap != null) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); Color color = (Color) colorMap.get(serieName); if (color != null) { renderer.setSeriesPaint(i, color); } } } // increase the margins to account for the fact that the auto-range // doesn't take into account the bubble size... NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setRange(xMin, xMax); if (legend == true) { drawLegend(chart); } return chart; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false);/*from w w w .j av a 2 s .co m*/ TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); chart.setBackgroundPaint(Color.white); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); //defines colors int seriesN = dataset.getSeriesCount(); if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); Color color = new Color(Integer.decode(defaultColor).intValue()); if (colorMap != null && colorMap.size() > 0) color = (Color) colorMap.get(serieName); if (color != null) renderer.setSeriesPaint(i, color); } } // add un interval marker for the Y axis... if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("") && !yMarkerEndInt.equals("")) { Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt), Double.parseDouble(yMarkerEndInt)); intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerY.setPaint( new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue())); //intMarkerY.setLabel(yMarkerLabel); intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(intMarkerY, Layer.BACKGROUND); } // add un interval marker for the X axis... if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("") && !xMarkerEndInt.equals("")) { Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt), Double.parseDouble(xMarkerEndInt)); intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerX.setPaint( new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue())); //intMarkerX.setLabel(xMarkerLabel); intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(intMarkerX, Layer.BACKGROUND); } // add a labelled marker for the Y axis... if (yMarkerValue != null && !yMarkerValue.equals("")) { Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue)); markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!yMarkerColor.equals("")) markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue())); markerY.setLabel(yMarkerLabel); markerY.setLabelFont(new Font("Arial", Font.BOLD, 11)); markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(markerY, Layer.BACKGROUND); } // add a labelled marker for the X axis... if (xMarkerValue != null && !xMarkerValue.equals("")) { Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue)); markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!xMarkerColor.equals("")) markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue())); markerX.setLabel(xMarkerLabel); markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(markerX, Layer.BACKGROUND); } if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) { if (Double.valueOf(xRangeLow).doubleValue() > xMin) xRangeLow = String.valueOf(xMin); if (Double.valueOf(xRangeHigh).doubleValue() < xMax) xRangeHigh = String.valueOf(xMax); ValueAxis rangeAxis = plot.getRangeAxis(); //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); } else { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setRange(xMin, xMax); } if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) { if (Double.valueOf(yRangeLow).doubleValue() > yMin) yRangeLow = String.valueOf(yMin); if (Double.valueOf(yRangeHigh).doubleValue() < yMax) yRangeHigh = String.valueOf(yMax); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setAutoRangeIncludesZero(false); } else { NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); domainAxis.setAutoRangeIncludesZero(false); } //add annotations if requested if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) { if (annotationMap == null || annotationMap.size() == 0) logger.error("Annotations on the chart are requested but the annotationMap is null!"); else { int cont = 1; for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) { String text = (String) iterator.next(); String pos = (String) annotationMap.get(text); double x = Double.parseDouble(pos.substring(0, pos.indexOf("__"))); double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2)); //default up position XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); if (cont % 2 != 0) //dx annotation = new XYTextAnnotation(text, y, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); else //sx //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1)); annotation = new XYTextAnnotation(text, y, x - (text.length() - 1)); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); //annotation.setRotationAngle(Math.PI / 4.0); annotation.setRotationAngle(0.0); // horizontal plot.addAnnotation(annotation); cont++; } renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) { renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } if (legend == true) { drawLegend(chart); } return chart; }