private static JFreeChart createChart(final XYSeriesWithLegend[] criteria) { final XYSeriesCollection dataset = new XYSeriesCollection(); for (XYSeries serie : criteria) { dataset.addSeries(serie); } final JFreeChart chart = ChartFactory.createXYLineChart("Model order selection", "model order", "criterion value", dataset, PlotOrientation.VERTICAL, true, false, false); final XYPlot plot = chart.getXYPlot(); ((NumberAxis) plot.getDomainAxis()).setTickUnit(new NumberTickUnit(1.0)); final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setLegendItemToolTipGenerator(new XYSeriesLabelGenerator() { @Override public String generateLabel(XYDataset xyd, int i) { return (i>=0 && i<criteria.length) ? criteria[i].getLegend() : ""; } }); for (int i=0; i<dataset.getSeriesCount(); ++i) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShapesFilled(i, true); } return chart; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series); } Paint paint = lookupSeriesPaint(series); result = new LegendItem(label, description, toolTipText, urlText, this.legendArea, paint); result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); } } return result; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ @Override public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series); } Paint paint = lookupSeriesPaint(series); result = new LegendItem(label, description, toolTipText, urlText, this.legendArea, paint); result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); } } return result; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series); } Shape shape = this.legendBar; Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke outlineStroke = getSeriesOutlineStroke(series); if (this.drawBarOutline) { result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); } else { result = new LegendItem(label, description, toolTipText, urlText, shape, paint); } if (getGradientPaintTransformer() != null) { result.setFillPaintTransformer( getGradientPaintTransformer()); } } } return result; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series); } Paint paint = getSeriesPaint(series); result = new LegendItem(label, description, toolTipText, urlText, this.legendArea, paint); } } return result; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series); } Shape shape = this.legendBar; Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Stroke outlineStroke = lookupSeriesOutlineStroke(series); if (this.drawBarOutline) { result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); } else { result = new LegendItem(label, description, toolTipText, urlText, shape, paint); } result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); if (getGradientPaintTransformer() != null) { result.setFillPaintTransformer( getGradientPaintTransformer()); } } } return result; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ @Override public LegendItem getLegendItem(int datasetIndex, int series) { XYPlot xyplot = getPlot(); if (xyplot == null) { return null; } XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset == null) { return null; } LegendItem result; XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel(dataset, series); } Shape shape = this.legendBar; Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Stroke outlineStroke = lookupSeriesOutlineStroke(series); if (this.drawBarOutline) { result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); } else { result = new LegendItem(label, description, toolTipText, urlText, shape, paint); } result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); if (getGradientPaintTransformer() != null) { result.setFillPaintTransformer(getGradientPaintTransformer()); } return result; }
/** * Returns a default legend item for the specified series. Subclasses should * override this method to generate customised items. * * @param datasetIndex * the dataset index (zero-based). * @param series * the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel(dataset, series); } Shape shape = getLegendBar(); Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke outlineStroke = getSeriesOutlineStroke(series); // This is the fix for bug #2695 if (paint instanceof java.awt.GradientPaint) { // When the paintstyle is "shade" use the lighter // color while with "light" use the darker color // NOTE: if we take the lighter color (Color2) and make it darker // and it equals the darker color (Color1) then the paintstyle // is "shade". GradientPaint gp = ((GradientPaint) paint); if (cfCHART.getDarkerColor(gp.getColor2()).equals(gp.getColor1())) paint = gp.getColor2(); // the lighter color else paint = gp.getColor1(); // the darker color } result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); } } return result; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem result = null; XYPlot xyplot = getPlot(); if (xyplot != null) { XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset != null) { XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series); } // FIXME: Use the general mechanism Shape shape = this.legendBar; Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Stroke outlineStroke = lookupSeriesOutlineStroke(series); if (this.drawBarOutline) { result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); } else { result = new LegendItem(label, description, toolTipText, urlText, shape, paint); } result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); if (getGradientPaintTransformer() != null) { result.setFillPaintTransformer( getGradientPaintTransformer()); } } } return result; }
/** * Returns a default legend item for the specified series. Subclasses * should override this method to generate customised items. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { XYPlot xyplot = getPlot(); if (xyplot == null) { return null; } XYDataset dataset = xyplot.getDataset(datasetIndex); if (dataset == null) { return null; } LegendItem result = null; XYSeriesLabelGenerator lg = getLegendItemLabelGenerator(); String label = lg.generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel(dataset, series); } Shape shape = this.legendBar; Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Stroke outlineStroke = lookupSeriesOutlineStroke(series); if (this.drawBarOutline) { result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); } else { result = new LegendItem(label, description, toolTipText, urlText, shape, paint); } result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setDataset(dataset); result.setDatasetIndex(datasetIndex); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); if (getGradientPaintTransformer() != null) { result.setFillPaintTransformer(getGradientPaintTransformer()); } return result; }