private static JFreeChart createChart( XYDataset dataset, String applicationTitle, String chartTitle, String xlabel, String ylabel, String name) { JFreeChart chart = ChartFactory.createScatterPlot( chartTitle, xlabel, ylabel, dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesOutlinePaint(0, Color.black); renderer.setUseOutlinePaint(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(0.0f); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(0.0f); return chart; }
private static void configureXYLineAndShapeRenderer( XYLineAndShapeRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); DimensionConfig domainConfig = valueSource.getDomainConfig(); DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR); DimensionConfig shapeDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE); ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); int seriesCount = valueSourceData.getSeriesDataForAllGroupCells().groupCellCount(); // Loop all series and set series format. // Format based on dimension configs will be set later on in initFormatDelegate(). for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { // configure linestyle if (seriesFormat.getLineStyle() == LineStyle.NONE) { renderer.setSeriesLinesVisible(seriesIdx, false); } else { renderer.setSeriesLinesVisible(seriesIdx, true); renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false); } // configure series shape if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) { if (seriesFormat.getItemShape() != ItemShape.NONE) { renderer.setSeriesShapesVisible(seriesIdx, true); renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape()); } else { renderer.setSeriesShapesVisible(seriesIdx, false); } } // configure series color if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) { Color itemColor = seriesFormat.getItemColor(); renderer.setSeriesPaint(seriesIdx, itemColor); renderer.setSeriesFillPaint(seriesIdx, itemColor); } renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT); renderer.setUseOutlinePaint(true); } }