/** * Test that the equals() method distinguishes all fields. */ public void testEquals() { StandardXYItemRenderer r1 = new StandardXYItemRenderer(); StandardXYItemRenderer r2 = new StandardXYItemRenderer(); assertEquals(r1, r2); r1.setPlotShapes(true); assertFalse(r1.equals(r2)); r2.setPlotShapes(true); assertTrue(r1.equals(r2)); r1.setShapesFilled(false); assertFalse(r1.equals(r2)); r2.setShapesFilled(false); assertTrue(r1.equals(r2)); }
/** * Tests cloning for a more complex plot. */ @Test public void testCloning2() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); p1.setRangeAxis(1, new NumberAxis("Range Axis 2")); List axisIndices = Arrays.asList(new Integer[] {new Integer(0), new Integer(1)}); p1.mapDatasetToDomainAxes(0, axisIndices); p1.mapDatasetToRangeAxes(0, axisIndices); p1.setRenderer(1, new XYBarRenderer()); XYPlot p2 = (XYPlot) p1.clone(); assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); }
/** * Tests cloning for a plot where the fixed legend items have been * specified. */ @Test public void testCloning3() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); LegendItemCollection c1 = new LegendItemCollection(); p1.setFixedLegendItems(c1); XYPlot p2 = (XYPlot) p1.clone(); assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); // verify independence of fixed legend item collection c1.add(new LegendItem("X")); assertFalse(p1.equals(p2)); }
public TPPlot() { super(); // axes setDomainAxis( new TPDomainAxis() ); setRangeAxis( new TPRangeAxis() ); // series series = new XYSeries( "real", true /* autoSort */); // dataset XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries( series ); setDataset( dataset ); // renderer StandardXYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setDrawSeriesLineAsPath( true ); setRenderer( renderer ); }
private XYPlot createPlot( XYSeriesCollection dataset ) { XYPlot plot = new XYPlot(); ValueAxis domainAxis = new NumberAxis( "Time" ); domainAxis.setTickLabelsVisible( false ); domainAxis.setRange( 0, RANGE ); plot.setDomainAxis( domainAxis ); ValueAxis rangeAxis = new NumberAxis( "Population" ); rangeAxis.setStandardTickUnits( NumberAxis.createIntegerTickUnits() ); plot.setRangeAxis( rangeAxis ); rangeAxis.setRange( 0, 50 ); plot.setRenderer( new StandardXYItemRenderer() ); final int seriesIndex = 0; plot.setDataset( seriesIndex, dataset ); XYItemRenderer renderer = new StandardXYItemRenderer(); // TODO: maybe use XYLineAndShapeRenderer? renderer.setStroke( new BasicStroke( 2f ) ); renderer.setSeriesPaint( TOTAL_INDEX, Color.BLACK ); renderer.setSeriesPaint( FUR_WHITE_INDEX, Color.RED ); plot.setRenderer( seriesIndex, renderer ); return plot; }
protected void initComponents() { setLayout(new BorderLayout()); // create chart theDataset = new DefaultXYDataset(); theIsotopesDataset = new DefaultXYDataset(); theChart = org.jfree.chart.ChartFactory.createScatterPlot("PeakList", "m/z ratio", "Intensity", new XYBarDataset(theDataset,0.001), org.jfree.chart.plot.PlotOrientation.VERTICAL, false, false, false); thePlot = (XYPlot)theChart.getPlot(); thePlot.setRenderer(new XYBarRenderer()); thePlot.setDataset(1, theIsotopesDataset); thePlot.setRenderer(1,new StandardXYItemRenderer(StandardXYItemRenderer.LINES)); theChartPanel = new ChartPanel(theChart); theChartPanel.setDomainZoomable(false); theChartPanel.setRangeZoomable(false); theChartPanel.setPopupMenu(null); add(theChartPanel,BorderLayout.CENTER); // create toolbar theToolBar = createToolBar(); add(theToolBar,BorderLayout.SOUTH); }
protected void initComponents() { setLayout(new BorderLayout()); // create chart theDataset = new DefaultXYDataset(); theChart = org.jfree.chart.ChartFactory.createScatterPlot("Annotation", "Count", "Intensity", theDataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, false, false); thePlot = (XYPlot)theChart.getPlot(); thePlot.setRenderer(new StandardXYItemRenderer(StandardXYItemRenderer.LINES)); theChartPanel = new ChartPanel(theChart); theChartPanel.setDomainZoomable(true); theChartPanel.setRangeZoomable(false); //theChartPanel.setPopupMenu(null); add(theChartPanel,BorderLayout.CENTER); // create toolbar theToolBar = createToolBar(); add(theToolBar,BorderLayout.SOUTH); }
public static JFreeChart createOverlaidChart( SuccessfulAttack sa ) { // create subplot 1... final XYSeries data1 = createDatasetResponseTime( RequestType.UNTAMPERED, sa.getUntamperedMetrics() ); final XYSeries data2 = createDatasetResponseTime( RequestType.TAMPERED, sa.getTamperedMetrics() ); final XYSeries data3 = createDatasetResponseTime( RequestType.TESTPROBES, sa.getTestProbes() ); final XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries( data1 ); collection.addSeries( data2 ); collection.addSeries( data3 ); final XYItemRenderer renderer = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis( "duration in ms" ); final XYPlot plot = new XYPlot( collection, new NumberAxis( "" ), rangeAxis1, renderer ); plot.setRangeAxisLocation( AxisLocation.BOTTOM_OR_LEFT ); renderer.setSeriesPaint( 0, Color.GREEN ); renderer.setSeriesPaint( 1, Color.RED ); renderer.setSeriesPaint( 2, Color.BLUE ); // return a new chart containing the overlaid plot... return new JFreeChart( "", JFreeChart.DEFAULT_TITLE_FONT, plot, true ); }
/** * Tests cloning for a more complex plot. */ public void testCloning2() { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); p1.setRangeAxis(1, new NumberAxis("Range Axis 2")); p1.setRenderer(1, new XYBarRenderer()); XYPlot p2 = null; try { p2 = (XYPlot) p1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); }
/** * A check to ensure that an item that falls outside the plot's data area * does NOT generate an item entity. */ public void testNoDisplayedItem() { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(10.0, 10.0); dataset.addSeries(s1); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StandardXYItemRenderer()); NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setRange(0.0, 5.0); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setRange(0.0, 5.0); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); ChartRenderingInfo info = new ChartRenderingInfo(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info); g2.dispose(); EntityCollection ec = info.getEntityCollection(); assertFalse(TestUtilities.containsInstanceOf(ec.getEntities(), XYItemEntity.class)); }
/** * Tests cloning for a more complex plot. */ public void testCloning2() { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); p1.setRangeAxis(1, new NumberAxis("Range Axis 2")); List axisIndices = Arrays.asList(new Integer[] {new Integer(0), new Integer(1)}); p1.mapDatasetToDomainAxes(0, axisIndices); p1.mapDatasetToRangeAxes(0, axisIndices); p1.setRenderer(1, new XYBarRenderer()); XYPlot p2 = null; try { p2 = (XYPlot) p1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); }
/** * Tests cloning for a plot where the fixed legend items have been * specified. */ public void testCloning3() { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); LegendItemCollection c1 = new LegendItemCollection(); p1.setFixedLegendItems(c1); XYPlot p2 = null; try { p2 = (XYPlot) p1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); // verify independence of fixed legend item collection c1.add(new LegendItem("X")); assertFalse(p1.equals(p2)); }
private static DatasetConfig createGradientConfig() { DatasetConfig config = new DatasetConfigDelegate( new DefaultDatasetConfig.Builder(2) .description( i18n.getText("com.github.pfichtner.jrunalyser.ui.mapprofile.MapProfilePlugin.gradient")) //$NON-NLS-1$ .yFunc(createGradientFunction(DistanceUnit.METERS)) .renderer( rendererColor(new StandardXYItemRenderer(), Color.RED)).build()) { @Override public NumberAxis createNumberAxis(Track track) { NumberAxis axis = super.createNumberAxis(track); axis.setAutoRange(true); return axis; } }; return new MovingAverageConfigDecorator(config, "", MOVING_AVG_VALUE, MOVING_AVG_SKIP); //$NON-NLS-1$ }
/** * A demonstration application showing an XY series containing a null value. * * @param title the frame title. */ public WaterTemperatureDemo(final String title) { super(title); final XYDataset dataset = createDataset(); final NumberAxis rangeAxis = new NumberAxis("Temperature"); rangeAxis.setRange(-0.55, -0.15); final NumberAxis domainAxis = new NumberAxis("Depth"); domainAxis.setInverted(true); domainAxis.setRange(0.0, 35.0); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); final JFreeChart chart = new JFreeChart("Water Temperature By Depth", plot); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
protected void init() { seriesColors = new Color[SERIES_COLORS.length]; System.arraycopy(SERIES_COLORS, 0, seriesColors, 0, SERIES_COLORS.length); dataset = new XYSeriesCollection(); renderer = new StandardXYItemRenderer(); renderer.setPlotLines(false); renderer.setBaseShapesVisible(true); renderer.setShapesFilled(true); //set all possible series to the default shape for (int i=0; i<10; i++) renderer.setSeriesShape(i, defaultShape); XYPlot scatterPlot = new XYPlot(dataset, xAxis, yAxis, renderer); init(scatterPlot); }
/** * Adds the cash flow axis to the plot. * @param plot the plot * @param dataset the cash flow dataset */ private static void addCashFlowAxis(XYPlot plot, TimeSeriesCollection dataset) { final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio"); cashAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, cashAxis); plot.setDataset(1, dataset); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer(); cashFlowRenderer.setSeriesPaint(0, Color.blue); plot.setRenderer(1, cashFlowRenderer); }
/** * Creates a line chart (based on an {@link XYDataset}) with default settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) (<code>null</code> NOT * permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { StandardXYItemRenderer r1 = new StandardXYItemRenderer(); StandardXYItemRenderer r2 = new StandardXYItemRenderer(); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedDomainXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedRangeXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Range")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
/** * Some checks for the findDomainBounds() method. */ public void testFindDomainBounds() { AbstractXYItemRenderer renderer = new StandardXYItemRenderer(); // check the bounds of a simple dataset XYDataset dataset = createDataset1(); Range r = renderer.findDomainBounds(dataset); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(3.0, r.getUpperBound(), EPSILON); // check that a null dataset returns null bounds assertTrue(renderer.findDomainBounds(null) == null); }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedDomainXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedDomainXYPlot plot = new CombinedDomainXYPlot( new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedRangeXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis xAxis1 = new NumberAxis("X1"); XYPlot subplot1 = new XYPlot(data1, xAxis1, null, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis xAxis2 = new NumberAxis("X2"); xAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, xAxis2, null, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis( "Range")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }