/** * Creates a new legend title with the specified arrangement. * * @param source the source. * @param hLayout the horizontal item arrangement (<code>null</code> not * permitted). * @param vLayout the vertical item arrangement (<code>null</code> not * permitted). */ public LegendTitle(LegendItemSource source, Arrangement hLayout, Arrangement vLayout) { this.sources = new LegendItemSource[] {source}; this.items = new BlockContainer(hLayout); this.hLayout = hLayout; this.vLayout = vLayout; this.backgroundPaint = null; this.legendItemGraphicEdge = RectangleEdge.LEFT; this.legendItemGraphicAnchor = RectangleAnchor.CENTER; this.legendItemGraphicLocation = RectangleAnchor.CENTER; this.legendItemGraphicPadding = new RectangleInsets(2.0, 2.0, 2.0, 2.0); this.itemFont = DEFAULT_ITEM_FONT; this.itemPaint = DEFAULT_ITEM_PAINT; this.itemLabelPadding = new RectangleInsets(2.0, 2.0, 2.0, 2.0); }
/** * Creates a new legend title with the specified arrangement. * * @param source the source. * @param hLayout the horizontal item arrangement (<code>null</code> not * permitted). * @param vLayout the vertical item arrangement (<code>null</code> not * permitted). */ public LegendTitle(LegendItemSource source, Arrangement hLayout, Arrangement vLayout) { this.sources = new LegendItemSource[] {source}; this.items = new BlockContainer(hLayout); this.hLayout = hLayout; this.vLayout = vLayout; this.backgroundPaint = null; this.legendItemGraphicEdge = RectangleEdge.LEFT; this.legendItemGraphicAnchor = RectangleAnchor.CENTER; this.legendItemGraphicLocation = RectangleAnchor.CENTER; this.legendItemGraphicPadding = new RectangleInsets(2.0, 2.0, 2.0, 2.0); this.itemFont = DEFAULT_ITEM_FONT; this.itemPaint = DEFAULT_ITEM_PAINT; this.itemLabelPadding = new RectangleInsets(2.0, 2.0, 2.0, 2.0); this.sortOrder = SortOrder.ASCENDING; }
/** * Creates a new legend title with the specified arrangement. * * @param source the source. * @param hLayout the horizontal item arrangement ({@code null} not * permitted). * @param vLayout the vertical item arrangement ({@code null} not * permitted). */ public LegendTitle(LegendItemSource source, Arrangement hLayout, Arrangement vLayout) { this.sources = new LegendItemSource[] {source}; this.items = new BlockContainer(hLayout); this.hLayout = hLayout; this.vLayout = vLayout; this.backgroundPaint = null; this.legendItemGraphicEdge = RectangleEdge.LEFT; this.legendItemGraphicAnchor = RectangleAnchor.CENTER; this.legendItemGraphicLocation = RectangleAnchor.CENTER; this.legendItemGraphicPadding = new RectangleInsets(2.0, 2.0, 2.0, 2.0); this.itemFont = DEFAULT_ITEM_FONT; this.itemPaint = DEFAULT_ITEM_PAINT; this.itemLabelPadding = new RectangleInsets(2.0, 2.0, 2.0, 2.0); this.sortOrder = SortOrder.ASCENDING; }
protected void removeItemFromLegend(int itemToRemove, JFreeChart chart) { LegendItemCollection legendItems = chart.getPlot().getLegendItems(); final LegendItemCollection newLegendItems = new LegendItemCollection(); for (int i = 0; i < legendItems.getItemCount(); i++) { if (itemToRemove != i) newLegendItems.add(legendItems.get(i)); } LegendItemSource source = new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { return newLegendItems; } }; chart.removeLegend(); chart.addLegend(new LegendTitle(source)); }
public static LegendTitle createLegend() { final LegendItemCollection legendItems = new LegendItemCollection(); FontRenderContext frc = new FontRenderContext(null, true, true); Font legenfont = new Font(Font.SANS_SERIF, Font.PLAIN, 12); GlyphVector gv = legenfont.createGlyphVector(frc, new char[] {'I', 'I'}); Shape shape = gv.getVisualBounds(); Rectangle2D bounds = shape.getBounds2D(); { LegendItem li = new LegendItem("Standard error", null, null, null, new ErrorIndicator(bounds), new BasicStroke(), ErrorIndicator.ERROR_INDICATOR_COLOR); li.setLabelFont(legenfont); legendItems.add(li); } LegendTitle legend = new LegendTitle(new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { return legendItems; }}); legend.setPosition(RectangleEdge.BOTTOM); legend.setMargin(new RectangleInsets(0,30,0,0)); legend.setPadding(RectangleInsets.ZERO_INSETS); legend.setLegendItemGraphicPadding(new RectangleInsets(0,20,0,0)); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); return legend; }
private LegendTitle createLegend() { final LegendItemCollection legendItems = new LegendItemCollection(); FontRenderContext frc = new FontRenderContext(null, true, true); GlyphVector gv = LEGEND_FONT.createGlyphVector(frc, new char[] {'X'}); Shape shape = gv.getGlyphVisualBounds(0); for(Pair<String, Color> p : getLegend()) { LegendItem li = new LegendItem(p.getLeft(), null, null, null, shape, p.getRight()); li.setLabelFont(LEGEND_FONT); legendItems.add(li); } LegendTitle legend = new LegendTitle(new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { return legendItems; }}); legend.setPosition(RectangleEdge.BOTTOM); return legend; }
public static void createLegend(JFreeChart kmPlot, List<KMPlotPointSeriesSet> plotPointSeriesSetCollection) { LegendTitle legend = kmPlot.getLegend(); LegendItemSource[] sources = new LegendItemSource[1]; KMLegendItemSource legendSrc = new KMLegendItemSource(); Comparator<KMPlotPointSeriesSet> nameComparator = new Comparator<KMPlotPointSeriesSet>() { public int compare(KMPlotPointSeriesSet series1, KMPlotPointSeriesSet series2) { return series1.getName().compareToIgnoreCase(series2.getName()); } }; Collections.sort(plotPointSeriesSetCollection, nameComparator); LegendItem item ; for (KMPlotPointSeriesSet plotPointSeries : plotPointSeriesSetCollection) { Color color = plotPointSeries.getColor(); String title = plotPointSeries.getLegendTitle() + " (" + plotPointSeries.getGroupSize() + ")"; item = new LegendItem(title, null, null, null, new Rectangle2D.Double(2,2,10,10), color); legendSrc.addLegendItem(item); } sources[0] = legendSrc; legend.setSources(sources); }
/** * Sets the legend item sources and sends a {@link TitleChangeEvent} to * all registered listeners. * * @param sources the sources (<code>null</code> not permitted). */ public void setSources(LegendItemSource[] sources) { if (sources == null) { throw new IllegalArgumentException("Null 'sources' argument."); } this.sources = sources; notifyListeners(new TitleChangeEvent(this)); }
private static JFreeChart createBarChart(ADCDataset dataset) { AutoSubCategoryAxis categoryAxis = new AutoSubCategoryAxis(dataset); categoryAxis.setCategoryLabelPositionOffset(0); categoryAxis.setLabel(dataset.get(Attribute.X_AXIS_LABEL)); CategoryDataset fixedDataset = categoryAxis.getFixedDataset(); PartitionedNumberAxis vAxis = new PartitionedNumberAxis( dataset.get(Attribute.Y_AXIS_LABEL)); CategoryPlot plot = new CategoryPlot(fixedDataset, categoryAxis, vAxis, new Renderer(fixedDataset)); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(dataset.get(Attribute.TITLE), JFreeChart.DEFAULT_TITLE_FONT, plot, false); final LegendItemCollection items = new LegendItemCollection(); for(Condition c : Condition.values()) { if(c != Condition.NOT_EVALUATED) { items.add(new LegendItem(c.getLabel(), null, null, null, new Rectangle2D.Double(-6.0, -6.0, 10.0,10.0), c.getColor())); } } LegendTitle legend = new LegendTitle(new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { return items; }}); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); chart.addLegend(legend); new StandardChartTheme("JFree").apply(chart); return chart; }
public SmartLegendTitle(LegendItemSource source, Arrangement hLayout, Arrangement vLayout) { super(source, hLayout, vLayout); }
public SmartLegendTitle(LegendItemSource source) { super(source); }
@Override public void run() { DefaultTableXYDataset dataset = new DefaultTableXYDataset(); XYSeries serie = new XYSeries("insert", true, false); for (int ligne = 0; ligne < getDatas().size(); ++ligne) { serie.add(ligne, getDatas().get(ligne)); } dataset.addSeries(serie); NumberAxis Laxis = new NumberAxis("n°revision"); XYBarRenderer revBarRenderer = new XYBarRenderer(); XYPlot revPlot = new XYPlot(); revPlot.setDataset(dataset); revPlot.setRangeAxis(Laxis); revPlot.setRenderer(revBarRenderer); XYSeriesCollection xySerieCollectiondataset = new XYSeriesCollection(); XYLineAndShapeRenderer lengthRenderer = new XYLineAndShapeRenderer(); int i = -1; int iName = 0; for (ArrayList<Integer> lengthSerie : lengths) { serie = new XYSeries(legend.get(iName)); ++iName; lengthRenderer.setSeriesShapesVisible(++i, false); // PROMPT LENGTHS DATA for (int ligne = 0; ligne < lengthSerie.size(); ++ligne) { serie.add(ligne, lengthSerie.get(ligne)); } xySerieCollectiondataset.addSeries(serie); } NumberAxis Raxis = new NumberAxis("length"); XYPlot lengthPlot = new XYPlot(); lengthPlot.setDataset(xySerieCollectiondataset); lengthPlot.setRangeAxis(Raxis); lengthRenderer.setSeriesPaint(2, Color.MAGENTA); lengthPlot.setRenderer(lengthRenderer); CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(); mainPlot.add(revPlot); mainPlot.add(lengthPlot); setChart(new JFreeChart("Spectrum of " + getOpName(), null, mainPlot, false)); final LegendItemCollection legendItemsOld = mainPlot.getLegendItems(); LegendItemSource source = new LegendItemSource() { public LegendItemCollection getLegendItems() { LegendItemCollection lic = new LegendItemCollection(); int itemCount = legendItemsOld.getItemCount(); for (int i = 0; i < itemCount; i++) { lic.add(legendItemsOld.get(i)); } return lic; } }; getChart().addLegend(new LegendTitle(source)); getChart().getLegend().setPosition(RectangleEdge.TOP); getChart().getLegend().getItemContainer().getBlocks(); if (!note.isEmpty()){ TextTitle legendText = new TextTitle("Notes : \n"+note); legendText.setPosition(RectangleEdge.BOTTOM); getChart().addSubtitle(legendText); } setFrame(new ChartFrame(getPageName(), getChart())); }
/** * Constructs a new (empty) legend for the specified source. * * @param source the source. */ public LegendTitle(LegendItemSource source) { this(source, new FlowArrangement(), new ColumnArrangement()); }
/** * Returns the legend item sources. * * @return The sources. */ public LegendItemSource[] getSources() { return this.sources; }
/** * Sets the legend item sources and sends a {@link TitleChangeEvent} to * all registered listeners. * * @param sources the sources (<code>null</code> not permitted). */ public void setSources(LegendItemSource[] sources) { ParamChecks.nullNotPermitted(sources, "sources"); this.sources = sources; notifyListeners(new TitleChangeEvent(this)); }