List of usage examples for org.jfree.chart LegendItem getFillPaint
public Paint getFillPaint()
From source file:ca.nengo.plot.impl.DefaultPlotter.java
private static LegendItem getCopy(LegendItem original, String newLabel) { return new LegendItem(newLabel, null, //description null, //tooltip text null, //URL original.isShapeVisible(), original.getShape(), original.isShapeFilled(), original.getFillPaint(), original.isShapeOutlineVisible(), original.getOutlinePaint(), original.getOutlineStroke(), original.isLineVisible(), original.getLine(), original.getLineStroke(), original.getLinePaint()); }
From source file:edu.emory.library.tast.database.graphs.GraphTypeXY.java
public JFreeChart createChart(Object[] data) { CategoryTableXYDataset dataset = new CategoryTableXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);/* ww w. j a va 2 s.co m*/ Format formatter = getSelectedIndependentVariable().getFormat(); XYPlot plot = chart.getXYPlot(); if (formatter != null) ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride((NumberFormat) formatter); chart.setBackgroundPaint(Color.white); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; Number x = (Number) row[0]; Number y = (Number) row[j + 1]; if (x != null && y != null) dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel); } } LegendItemCollection legendItems = chart.getPlot().getLegendItems(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem legendItem = legendItems.get(i); DataSeries dataSearies = (DataSeries) allDataSeries.get(i); if (legendItem.getFillPaint() instanceof Color) { dataSearies.setColor(((Color) legendItem.getFillPaint())); } } return chart; }
From source file:edu.emory.library.tast.database.graphs.GraphTypeBar.java
public JFreeChart createChart(Object[] data) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createBarChart(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);// w w w . j a va 2 s . co m CategoryPlot plot = chart.getCategoryPlot(); plot.getDomainAxis().setMaximumCategoryLabelLines(5); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); chart.setBackgroundPaint(Color.white); Format formatter = getSelectedIndependentVariable().getFormat(); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; String cat = formatter == null ? row[0].toString() : formatter.format(row[0]); dataset.addValue((Number) row[j + 1], dataSeriesLabel, cat); } } LegendItemCollection legendItems = chart.getPlot().getLegendItems(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem legendItem = legendItems.get(i); DataSeries dataSearies = (DataSeries) allDataSeries.get(i); if (legendItem.getFillPaint() instanceof Color) { dataSearies.setColor(((Color) legendItem.getFillPaint())); } } return chart; }
From source file:gda.plots.SimpleLegendTitle.java
/** * Overrides the super class method to create a SimpleLegendGraphic instead of a LegendGraphic and a * SimpleLegendLabelBlock instead of a LabelBlock (otherwise identical except private field names replaced with * method calls). Assumes it will be passed a SimpleLegendItem and uses it to get the SimpleXYSeries to pass on to * the SimpleLegendGraphic and SimpleLegendLabelBlock. * // www . java 2 s .c om * @param item * the LegendItem for which the LegendItemBlock is to be created * @return the LegendItemBlock created */ @Override protected Block createLegendItemBlock(LegendItem item) { BlockContainer result = null; if (item instanceof SimpleLegendItem) { LegendGraphic lg = new SimpleLegendGraphic(item.getShape(), item.getFillPaint(), ((SimpleLegendItem) item).getSeries()); lg.setShapeFilled(item.isShapeFilled()); lg.setLine(item.getLine()); lg.setLineStroke(item.getLineStroke()); lg.setLinePaint(item.getLinePaint()); lg.setLineVisible(item.isLineVisible()); lg.setShapeVisible(item.isShapeVisible()); lg.setShapeOutlineVisible(item.isShapeOutlineVisible()); lg.setOutlinePaint(item.getOutlinePaint()); lg.setOutlineStroke(item.getOutlineStroke()); lg.setPadding(getLegendItemGraphicPadding()); BlockContainer legendItem = new BlockContainer(new BorderArrangement()); lg.setShapeAnchor(getLegendItemGraphicAnchor()); lg.setShapeLocation(getLegendItemGraphicLocation()); legendItem.add(lg, getLegendItemGraphicEdge()); LabelBlock labelBlock = new SimpleLegendLabelBlock(item.getLabel(), getItemFont(), getItemPaint(), ((SimpleLegendItem) item).getSeries()); labelBlock.setPadding(getItemLabelPadding()); labelBlock.setToolTipText(item.getLabel()); // labelBlock.setToolTipText("click"); legendItem.add(labelBlock); result = new BlockContainer(new CenterArrangement()); result.add(legendItem); } return result; }
From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java
/** * Creates a legend item block./*from ww w .j a v a 2 s .c o m*/ * * @param item * the legend item. * * @return The block. */ protected Block createLegendItemBlock(LegendItem item, int i) { BlockContainer result = null; LegendGraphic lg = new LegendGraphic(item.getShape(), item.getFillPaint()); lg.setFillPaintTransformer(item.getFillPaintTransformer()); lg.setShapeFilled(true); lg.setLine(item.getLine()); lg.setLineStroke(item.getLineStroke()); lg.setLinePaint(item.getFillPaint()); lg.setLineVisible(true); lg.setShapeVisible(true); lg.setShapeOutlineVisible(true); lg.setOutlinePaint(item.getFillPaint()); lg.setOutlineStroke(item.getOutlineStroke()); lg.setPadding(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); LegendItemBlockContainer legendItem = new LegendItemBlockContainer(new BorderArrangement(), 0, i); lg.setShapeAnchor(RectangleAnchor.CENTER); lg.setShapeLocation(RectangleAnchor.CENTER); legendItem.add(lg, RectangleEdge.LEFT); LabelBlock labelBlock = new LabelBlock(item.getLabel(), new Font("SansSerif", Font.BOLD, 10), Color.black); labelBlock.setPadding(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); legendItem.add(labelBlock); legendItem.setToolTipText(item.getToolTipText()); legendItem.setURLText(item.getURLText()); result = new BlockContainer(new CenterArrangement()); result.add(legendItem); return result; }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java
@Override public void update() { String source = customGroup.getSelection().getActionCommand(); String actionCommand = topGroup.getSelection().getActionCommand(); int periodPos = actionCommand.indexOf("."); String topStr = actionCommand.substring(periodPos + 1); int top = Integer.parseInt(topStr); List<Map.Entry<String, Integer>> chartEvents = ChartUtils.getTopEvents(eventDb.getEvents(), top, source); chartCards.removeAll();//from ww w .jav a 2 s . c o m String style = styleGroup.getSelection().getActionCommand(); String orientationCommand = orientationGroup.getSelection().getActionCommand(); PlotOrientation orientation = PlotOrientation.VERTICAL; if (orientationCommand.contains("horizontal")) { orientation = PlotOrientation.HORIZONTAL; } ChartPanel cp = ChartFactory.createChart(style, chartEvents, 320, 240, orientation); chartCards.add(cp, ""); chartCards.revalidate(); for (int i = defaultTableModel.getRowCount() - 1; i >= 0; i--) { defaultTableModel.removeRow(i); } LegendItemCollection legendItems = ((ChartPanel) chartCards.getComponent(0)).getChart().getPlot() .getLegendItems(); for (Map.Entry entry : chartEvents) { Color col = null; String key = (String) entry.getKey(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem item = legendItems.get(i); if (item.getLabel().equalsIgnoreCase(key)) { col = (Color) item.getFillPaint(); } } defaultTableModel.addRow(new Object[] { col, key, entry.getValue() }); } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.SmartLegendTitle.java
private Block createDefaultLegendItem(LegendItem item) { BlockContainer result = null;/*from w w w.j a v a2s . c om*/ Shape shape = item.getShape(); if (shape == null) { shape = new Rectangle(); } LegendGraphic lg = new LegendGraphic(shape, item.getFillPaint()); lg.setFillPaintTransformer(item.getFillPaintTransformer()); lg.setShapeFilled(item.isShapeFilled()); lg.setLine(item.getLine()); lg.setLineStroke(item.getLineStroke()); lg.setLinePaint(item.getLinePaint()); lg.setLineVisible(item.isLineVisible()); lg.setShapeVisible(item.isShapeVisible()); lg.setShapeOutlineVisible(item.isShapeOutlineVisible()); lg.setOutlinePaint(item.getOutlinePaint()); lg.setOutlineStroke(item.getOutlineStroke()); lg.setPadding(getLegendItemGraphicPadding()); LegendItemBlockContainer legendItem = new LegendItemBlockContainer(new BorderArrangement(), item.getDataset(), item.getSeriesKey()); lg.setShapeAnchor(getLegendItemGraphicAnchor()); lg.setShapeLocation(getLegendItemGraphicLocation()); legendItem.add(lg, getLegendItemGraphicEdge()); Font textFont = item.getLabelFont(); if (textFont == null) { textFont = getItemFont(); } Paint textPaint = item.getLabelPaint(); if (textPaint == null) { textPaint = getItemPaint(); } LabelBlock labelBlock = new LabelBlock(item.getLabel(), textFont, textPaint); labelBlock.setPadding(getItemLabelPadding()); legendItem.add(labelBlock); legendItem.setToolTipText(item.getToolTipText()); legendItem.setURLText(item.getURLText()); result = new BlockContainer(new CenterArrangement()); result.add(legendItem); return result; }
From source file:org.geotools.renderer.chart.GeometryRenderer.java
@Override public LegendItem getLegendItem(int datasetIndex, int series) { LegendItem li = super.getLegendItem(datasetIndex, series); Stroke outlineStroke = getItemStroke(series, 0); Paint fillPaint = li.getFillPaint(); Paint outlinePaint = fillPaint; if (!fillCoordinates) { fillPaint = new Color(255, 255, 255, 255); }/*from ww w . j a v a 2 s . c o m*/ return new LegendItem(li.getLabel(), li.getDescription(), li.getToolTipText(), li.getURLText(), li.getShape(), fillPaint, outlineStroke, outlinePaint); }
From source file:net.sf.dynamicreports.test.jasper.chart.ChartSeriesColorsByNameTest.java
@Override public void test() { super.test(); numberOfPagesTest(1);/*from w ww. java 2s . c o m*/ chartCountTest("summary.chart1", 1); JFreeChart chart = getChart("summary.chart1", 0); CategoryItemRenderer renderer1 = chart.getCategoryPlot().getRenderer(); CategoryDataset dataset1 = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset1.getRowCount(); i++) { String key = (String) dataset1.getRowKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer1.getSeriesPaint(i)); } chartCountTest("summary.chart2", 1); chart = getChart("summary.chart2", 0); CategoryItemRenderer renderer2 = chart.getCategoryPlot().getRenderer(); CategoryDataset dataset2 = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset2.getRowCount(); i++) { String key = (String) dataset2.getRowKey(i); key = StringUtils.substringAfter(key, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer2.getSeriesPaint(i)); } for (int i = 0; i < chart.getCategoryPlot().getFixedLegendItems().getItemCount(); i++) { LegendItem legendItem = chart.getCategoryPlot().getFixedLegendItems().get(i); Assert.assertNotNull("null series color", colors.get(legendItem.getLabel())); Assert.assertEquals("series color", colors.get(legendItem.getLabel()), legendItem.getFillPaint()); } chartCountTest("summary.chart3", 1); chart = getChart("summary.chart3", 0); PiePlot plot3 = (PiePlot) chart.getPlot(); PieDataset dataset3 = plot3.getDataset(); for (int i = 0; i < dataset3.getItemCount(); i++) { String key = (String) dataset3.getKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), plot3.getSectionPaint(key)); } chartCountTest("summary.chart4", 1); chart = getChart("summary.chart4", 0); XYItemRenderer renderer4 = chart.getXYPlot().getRenderer(); XYDataset dataset4 = chart.getXYPlot().getDataset(); for (int i = 0; i < dataset4.getSeriesCount(); i++) { String key = (String) dataset4.getSeriesKey(i); Assert.assertNotNull("null series color", colors.get(key)); Assert.assertEquals("series color", colors.get(key), renderer4.getSeriesPaint(i)); } }
From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java
/** * updates the chart, changing the menus if needed and updating the contents * of the Key table.//from w ww .j av a 2 s .c om * @param chartData */ void updateChart(List<Map.Entry<String, Integer>> chartData) { chartCards.removeAll(); for (int i = defaultTableModel.getRowCount() - 1; i >= 0; i--) { defaultTableModel.removeRow(i); } if (chartData != null && chartData.size() > 0) { String style = styleGroup.getSelection().getActionCommand(); String orientationCommand = orientationGroup.getSelection().getActionCommand(); PlotOrientation orientation = PlotOrientation.VERTICAL; if (orientationCommand.contains("horizontal")) { orientation = PlotOrientation.HORIZONTAL; } ChartPanel cp = ChartFactory.createChart(style, chartData, 320, 240, orientation); chartCards.add(cp, ""); chartCards.revalidate(); LegendItemCollection legendItems = ((ChartPanel) chartCards.getComponent(0)).getChart().getPlot() .getLegendItems(); for (Map.Entry entry : chartData) { Color col = null; String key = (String) entry.getKey(); for (int i = 0; i < legendItems.getItemCount(); i++) { LegendItem item = legendItems.get(i); if (item.getLabel().equalsIgnoreCase(key)) { col = (Color) item.getFillPaint(); } } if (key.contains(":i-")) { int posColon = key.indexOf(':'); key = key.substring(posColon + 1); } defaultTableModel.addRow(new Object[] { col, key, entry.getValue() }); } } }