private JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot(this.title, this.xAxisLabel, this.yAxisLable, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesOutlinePaint(0, Color.black); renderer.setUseOutlinePaint(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); return chart; }
/** * Instantiates a new XyChartTab. * @param model the model */ public XyChartTab(XyDataModel model, XyChartEditorJPanel parent){ super(ChartFactory.createXYLineChart( model.getOntologyModel().getChartSettings().getChartTitle(), model.getOntologyModel().getChartSettings().getXAxisLabel(), model.getOntologyModel().getChartSettings().getYAxisLabel(), ((XyChartModel)model.getChartModel()).getXySeriesCollection(), PlotOrientation.VERTICAL, true, false, false ), parent); this.dataModel = model; this.applySettings(); this.dataModel.getChartModel().addObserver(this); }
@Override public void replaceModel(DataModel newModel) { this.dataModel = newModel; this.chartPanel.setChart(ChartFactory.createXYLineChart( dataModel.getOntologyModel().getChartSettings().getChartTitle(), dataModel.getOntologyModel().getChartSettings().getXAxisLabel(), dataModel.getOntologyModel().getChartSettings().getYAxisLabel(), ((XyChartModel)dataModel.getChartModel()).getXySeriesCollection(), PlotOrientation.VERTICAL, true, false, false )); this.applySettings(); this.dataModel.getChartModel().addObserver(this); }
/** * Check that the renderer is calculating the range bounds correctly. */ public void testFindRangeBounds() { TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart( "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); Range bounds = rangeAxis.getRange(); assertFalse(bounds.contains(1.0)); assertTrue(bounds.contains(2.0)); assertTrue(bounds.contains(5.0)); assertFalse(bounds.contains(6.0)); }
public static CategoryAxis createCategoryDomainAxis(PlotConfiguration plotConfiguration) { CategoryAxis domainAxis = new CategoryAxis(null); String label = plotConfiguration.getDomainConfigManager().getLabel(); if (label == null) { label = I18N.getGUILabel("plotter.unnamed_value_label"); } domainAxis.setLabel(label); Font axesFont = plotConfiguration.getAxesFont(); if (axesFont != null) { domainAxis.setLabelFont(axesFont); domainAxis.setTickLabelFont(axesFont); } // rotate labels if (plotConfiguration.getOrientation() != PlotOrientation.HORIZONTAL) { domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } formatAxis(plotConfiguration, domainAxis); return domainAxis; }
/** * Creates the histogram chart. * * @return */ private JFreeChart createBarChart() { JFreeChart chart = ChartFactory.createBarChart(null, null, null, createBarDataset(), PlotOrientation.VERTICAL, false, false, false); AbstractAttributeStatisticsModel.setDefaultChartFonts(chart); chart.setBackgroundPaint(null); chart.setBackgroundImageAlpha(0.0f); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setOutlineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setDomainGridlinesVisible(false); plot.setBackgroundPaint(COLOR_INVISIBLE); plot.setBackgroundImageAlpha(0.0f); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NOMINAL)); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); return chart; }
/** * Creates the histogram chart. * * @param exampleSet * @return */ private JFreeChart createHistogramChart(ExampleSet exampleSet) { JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet), PlotOrientation.VERTICAL, false, false, false); AbstractAttributeStatisticsModel.setDefaultChartFonts(chart); chart.setBackgroundPaint(null); chart.setBackgroundImageAlpha(0.0f); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setOutlineVisible(false); plot.setRangeZeroBaselineVisible(false); plot.setDomainZeroBaselineVisible(false); plot.setBackgroundPaint(COLOR_INVISIBLE); plot.setBackgroundImageAlpha(0.0f); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.NUMERICAL)); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowVisible(false); return chart; }
/** * A test for bug 1654215 (where a renderer is added to the plot without * a corresponding dataset and it throws an exception at drawing time). */ public void test1654215() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(1, new XYLineAndShapeRenderer()); boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { e.printStackTrace(); success = false; } assertTrue(success); }
/** * A simple test for the auto-range calculation looking at a * NumberAxis used as the range axis for a CategoryPlot. In this * case, the 'autoRangeIncludesZero' flag is set to false AND the * original dataset is replaced with a new dataset. */ public void testAutoRange3() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createLineChart("Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); assertEquals(axis.getLowerBound(), 95.0, EPSILON); assertEquals(axis.getUpperBound(), 205.0, EPSILON); // now replacing the dataset should update the axis range... DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.setValue(900.0, "Row 1", "Column 1"); dataset2.setValue(1000.0, "Row 1", "Column 2"); plot.setDataset(dataset2); assertEquals(axis.getLowerBound(), 895.0, EPSILON); assertEquals(axis.getUpperBound(), 1005.0, EPSILON); }
@Override public JFreeChart getChart() throws IOException { if (chart == null) { final YIntervalSeriesCollection series_collection = getDataset(); chart = ChartFactory.createXYLineChart(chart_title, "Time through experiment (s)", y_axis_label, series_collection, PlotOrientation.VERTICAL, getDataset().getSeriesCount() > 1, false, false); final XYErrorRenderer error_renderer = new XYErrorRenderer(); error_renderer.setBaseShapesVisible(false); error_renderer.setBaseLinesVisible(true); error_renderer.setDrawYError(false); final XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setLowerBound(0); plot.setRenderer(error_renderer); PlainChartTheme.applyTheme(chart); } return chart; }
/** * Test chart drawing with an empty dataset to ensure that this special * case doesn't cause any exceptions. */ public void testDrawWithEmptyDataset() { boolean success = false; JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x", "y", new DefaultTableXYDataset(), PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(new StackedXYAreaRenderer2()); try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createScatterPlot( "Scatter Plot", // chart title "Domain", "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createXYStepChart( "Step Chart", // chart title "Domain", "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips true // urls ); }
/** * Creates a sample chart. * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart( "Performance: JFreeSVG vs Batik", null /* x-axis label*/, "Milliseconds" /* y-axis label */, dataset, PlotOrientation.HORIZONTAL,false,false,false); chart.addSubtitle(new TextTitle("Time to generate 1000 charts in SVG " + "format (lower bars = better performance)")); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // chart.getLegend().setFrame(BlockBorder.NONE); return chart; }
public void inicializacionJFreeChart(String title, String xAxisLabel, String yAxisLabel, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { chart1 = ChartFactory.createXYLineChart( title, // chart title Titulo local del grafico xAxisLabel, // x axis label yAxisLabel, // y axis label null, // data orientation, legend, // include legend tooltips, // tooltips urls // urls ); // get a reference to the plot for further customisation... plot = chart1.getXYPlot(); }
@Override public void crearEInicializarVisorGraficaEstadisticas(String tituloVentanaVisor, String tituloLocalGrafico, String tituloEjeX, String tituloEjeY) throws Exception { PlotOrientation orientacionPlot = PlotOrientation.VERTICAL; boolean incluyeLeyenda = true; boolean incluyeTooltips = true; Color colorChartBackgroundPaint = Color.white; Color colorChartPlotBackgroundPaint = Color.lightGray; Color colorChartPlotDomainGridlinePaint = Color.white; Color colorChartPlotRangeGridlinePaint = Color.white; // VisualizacionJfreechart visualizadorJFchart = new VisualizacionJfreechart("tituloVenanaVisor"); visualizadorJFchart = new VisualizacionJfreechart(tituloVentanaVisor); visualizadorJFchart.inicializacionJFreeChart(tituloLocalGrafico, tituloEjeX, tituloEjeY, orientacionPlot, incluyeLeyenda, incluyeTooltips, false); visualizadorJFchart.setColorChartBackgroundPaint(colorChartBackgroundPaint); visualizadorJFchart.setColorChartPlotBackgroundPaint(colorChartPlotBackgroundPaint); visualizadorJFchart.setColorChartPlotDomainGridlinePaint(colorChartPlotDomainGridlinePaint); visualizadorJFchart.setColorChartPlotRangeGridlinePaint(colorChartPlotRangeGridlinePaint); }
/** * A simple test for the auto-range calculation looking at a * NumberAxis used as the range axis for a CategoryPlot. */ public void testAutoRange1() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createBarChart( "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false ); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); assertEquals(axis.getLowerBound(), 0.0, EPSILON); assertEquals(axis.getUpperBound(), 210.0, EPSILON); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createBarChart3D() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createBarChart3D("Bar Chart 3D", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, true, true); }
/** * Creates a sample chart. * * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(IntervalXYDataset dataset,String s) { final JFreeChart chart = ChartFactory.createXYBarChart( "Histogram Plot: "+s, "Keyword index", false, "frequency", dataset, PlotOrientation.VERTICAL, true, true, false ); XYPlot plot = (XYPlot) chart.getPlot(); final IntervalMarker target = new IntervalMarker(400.0, 700.0); //target.setLabel("Target Range"); target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); target.setLabelAnchor(RectangleAnchor.LEFT); target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); target.setPaint(new Color(222, 222, 255, 128)); plot.addRangeMarker(target, Layer.BACKGROUND); return chart; }
private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2) throws IOException { new File(Workfolder + "/RT_Mapping/").mkdir(); String pngfile = Workfolder + "/RT_Mapping/" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1)) + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1)) + "_RT.png"; XYSeries smoothline = new XYSeries("RT fitting curve"); for (XYZData data : regression.PredictYList) { smoothline.add(data.getX(), data.getY()); } xySeriesCollection.addSeries(smoothline); xySeriesCollection.addSeries(series); JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2, "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName), "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection, PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(1, Color.blue); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); xyPlot.setBackgroundPaint(Color.white); ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); IntervalXYDataset dataset = new XYBarDataset(new XYSeriesCollection( series1), 1.0); // create the chart... return ChartFactory.createXYBarChart( "XY Bar Chart", // chart title "Domain", false, "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips true // urls ); }
/** * Draws the annotation. This method is called by the drawing code in the {@link XYPlot} class, * you don't normally need to call this method directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation); float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } xx = xx - this.image.getWidth(null) / 2.0f; yy = yy - this.image.getHeight(null) / 2.0f; g2.drawImage(this.image, (int) xx, (int) yy, null); }
/** * Creates a wafer map chart. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) (<code>null</code> NOT * permitted. * @param legend display a legend? * @param tooltips generate tooltips? * @param urls generate URLs? * * @return a wafer map chart. */ public static JFreeChart createWaferMapChart(String title, WaferMapDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } WaferMapPlot plot = new WaferMapPlot(dataset); WaferMapRenderer renderer = new WaferMapRenderer(); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart( title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend ); return chart; }
/** * A test for bug 1654215 (where a renderer is added to the plot without * a corresponding dataset and it throws an exception at drawing time). */ public void test1654215() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y", dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(1, new LineAndShapeRenderer()); boolean success = false; try { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); success = true; } catch (Exception e) { e.printStackTrace(); success = false; } assertTrue(success); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createXYAreaChart( "Area Chart", // chart title "Domain", "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips true // urls ); }
/** * Create a bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createBarChart() { // create a dataset... Number[][] data = new Integer[][] {{new Integer(-3), new Integer(-2)}, {new Integer(-1), new Integer(1)}, {new Integer(2), new Integer(3)}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); // create the chart... return ChartFactory.createBarChart( "Bar Chart", "Domain", "Range", dataset, PlotOrientation.HORIZONTAL, true, // include legend true, true ); }
/** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); Rectangle2D area = new Rectangle2D.Double(j2DX - this.width / 2.0, j2DY - this.height / 2.0, this.width, this.height); this.drawable.draw(g2, area); String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, area, rendererIndex, toolTip, url); } }
/** * A simple test for the auto-range calculation. */ public void testAutoRange2() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.setValue(100.0, "Row 1", "Column 1"); dataset.setValue(200.0, "Row 1", "Column 2"); JFreeChart chart = ChartFactory.createBarChart( "Test", "Categories", "Value", dataset, PlotOrientation.VERTICAL, false, false, false ); NumberAxis axis = (NumberAxis) chart.getCategoryPlot().getRangeAxis(); axis.setAutoRangeIncludesZero(false); // range should be 100.0 - 205.0 assertTrue(same(axis.getLowerBound(), 95.0, 0.00001)); assertTrue(same(axis.getUpperBound(), 205.0, 0.00001)); }
private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart( "MONA TIME AND COST GRAPH", "KeyGeneration Cost ", "KeyGenerating time for task(secs)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot1 = chart.getXYPlot(); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); final XYPlot plot2 = chart.getXYPlot(); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); final XYPlot plot3 = chart.getXYPlot(); plot3.setBackgroundPaint(Color.lightGray); plot3.setDomainGridlinePaint(Color.white); plot3.setRangeGridlinePaint(Color.white); return chart; }
/** * Draws a grid line against the range axis. * * @param g2 the graphics device. * @param plot the plot. * @param axis the value axis. * @param dataArea the area for plotting data (not yet adjusted for any 3D effect). * @param value the value at which the grid line should be drawn. * */ public void drawRangeGridline(Graphics2D g2, CategoryPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) { Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } Paint paint = plot.getRangeGridlinePaint(); if (paint == null) { paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT; } g2.setPaint(paint); Stroke stroke = plot.getRangeGridlineStroke(); if (stroke == null) { stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE; } g2.setStroke(stroke); g2.draw(line); }
/** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. */ public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) { CategoryDataset dataset = plot.getDataset(); int catIndex = dataset.getColumnIndex(this.category); int catCount = dataset.getColumnCount(); float anchorX = 0.0f; float anchorY = 0.0f; PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); if (orientation == PlotOrientation.HORIZONTAL) { anchorY = (float) domainAxis.getCategoryJava2DCoordinate( this.categoryAnchor, catIndex, catCount, dataArea, domainEdge); anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge); } else if (orientation == PlotOrientation.VERTICAL) { anchorX = (float) domainAxis.getCategoryJava2DCoordinate( this.categoryAnchor, catIndex, catCount, dataArea, domainEdge); anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge); } g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); }
/** * Returns the plot orientation. * * @return True = {@link org.jfree.chart.plot.PlotOrientation#VERTICAL VERTICAL}; False = * {@link org.jfree.chart.plot.PlotOrientation#HORIZONTAL HORIZONTAL} */ protected boolean isHorizontalPlot(Plot plot) { if (plot instanceof XYPlot) { return ((XYPlot) plot).getOrientation() == PlotOrientation.HORIZONTAL; } if (plot instanceof FastScatterPlot) { return ((FastScatterPlot) plot).getOrientation() == PlotOrientation.HORIZONTAL; } return false; }
/** * Creates a line chart with default settings. The chart object returned by * this method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as * the range axis, and a {@link LineRenderer3D} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the chart 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 A line chart. */ public static JFreeChart createLineChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); LineRenderer3D renderer = new LineRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator( new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator( new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
protected JFreeChart createChart(XYDataset dataset) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart("Quantidade de pixels", "Pixel", "Quantidade", dataset, PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(java.awt.Color.white); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(java.awt.Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(java.awt.Color.white); plot.setRangeGridlinePaint(java.awt.Color.white); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
/** * 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; }
private void plotOrientationChanged(PlotOrientation orientation) { JFreeChart chart = getCurrentChart(); if (chart != null) { Plot plot = chart.getPlot(); if (plot instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) plot; categoryPlot.setOrientation(orientation); } else if (plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; xyPlot.setOrientation(orientation); } } }
/** * @param orientation * the orientation to set */ public void setOrientation(PlotOrientation orientation) { if (!this.orientation.equals(orientation)) { this.orientation = orientation; firePlotConfigurationChanged(new PlotConfigurationChangeEvent(this, orientation)); } }
/** * Creates a bubble chart with default settings. The chart is composed of * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} * to draw the data items. * * @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 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 A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset 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); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer( XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Draws a grid line against the domain axis. * <P> * Note that this default implementation assumes that the horizontal axis * is the domain axis. If this is not the case, you will need to override * this method. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the area for plotting data (not yet adjusted for any * 3D effect). * @param value the Java2D value at which the grid line should be drawn. * * @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis, * Rectangle2D, double) */ public void drawDomainGridline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) { Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY()); } Paint paint = plot.getDomainGridlinePaint(); if (paint == null) { paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT; } g2.setPaint(paint); Stroke stroke = plot.getDomainGridlineStroke(); if (stroke == null) { stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE; } g2.setStroke(stroke); g2.draw(line); }