List of usage examples for org.jfree.chart LegendItem LegendItem
public LegendItem(AttributedString label, String description, String toolTipText, String urlText, boolean shapeVisible, Shape shape, boolean shapeFilled, Paint fillPaint, boolean shapeOutlineVisible, Paint outlinePaint, Stroke outlineStroke, boolean lineVisible, Shape line, Stroke lineStroke, Paint linePaint)
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
/** * Creates a title item (i.e. bold font etc.) with the given string. Simply gets the default * font from the plotConfig and sets it style to bold. * //ww w .j a v a2 s .c om * @return The created legend item. */ private LegendItem createTitleLegendItem(String titleString, PlotConfiguration plotConfiguration) { LegendItem titleItem = new LegendItem(titleString, "", "", "", false, new Rectangle(), false, Color.WHITE, false, Color.WHITE, new BasicStroke(), false, new Rectangle(), new BasicStroke(), Color.WHITE); Font titleFont = titleItem.getLabelFont(); if (titleFont == null) { titleFont = plotConfiguration.getLegendConfiguration().getLegendFont(); } titleItem.setLabelFont(titleFont.deriveFont(Font.BOLD)); return titleItem; }
From source file:edu.dlnu.liuwenpeng.render.XYLineAndShapeRenderer.java
/** * Returns a legend item for the specified series. * //from w w w. j a va 2 s . c om * @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 plot = getPlot(); if (plot == null) { return null; } LegendItem result = null; XYDataset dataset = plot.getDataset(datasetIndex); if (dataset != null) { if (getItemVisible(series, 0)) { String label = getLegendItemLabelGenerator().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); } boolean shapeIsVisible = getItemShapeVisible(series, 0); Shape shape = lookupSeriesShape(series); boolean shapeIsFilled = getItemShapeFilled(series, 0); Paint fillPaint = (this.useFillPaint ? lookupSeriesFillPaint(series) : lookupSeriesPaint(series)); boolean shapeOutlineVisible = this.drawOutlines; Paint outlinePaint = (this.useOutlinePaint ? lookupSeriesOutlinePaint(series) : lookupSeriesPaint(series)); Stroke outlineStroke = lookupSeriesOutlineStroke(series); boolean lineVisible = getItemLineVisible(series, 0); Stroke lineStroke = lookupSeriesStroke(series); Paint linePaint = lookupSeriesPaint(series); result = new LegendItem(label, description, toolTipText, urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, this.legendLine, lineStroke, linePaint); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); result.setDataset(dataset); result.setDatasetIndex(datasetIndex); } } return result; }
From source file:charts.Chart.java
public static void PlotParallelCoordinates(String title, String x_axis_label, String y_axis_label, float[][] Md, int classes, int[] features, Vector featurestitles, Vector datatitles) { JFrame chartwindow = new JFrame(title); JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, null, PlotOrientation.VERTICAL, true, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.black); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int lines = Md.length; int columns = Md[0].length; LineAndShapeRenderer[] lineandshaperenderer = new LineAndShapeRenderer[classes]; for (int i = 0; i < lineandshaperenderer.length; i++) { lineandshaperenderer[i] = new LineAndShapeRenderer(); lineandshaperenderer[i].setShapesVisible(true); lineandshaperenderer[i].setDrawOutlines(true); lineandshaperenderer[i].setUseFillPaint(true); lineandshaperenderer[i].setFillPaint(Color.white); lineandshaperenderer[i].setBaseStroke(new BasicStroke(2.0f)); }//from w ww . ja v a2s . c o m int count = 0; for (int i = 0; i < lines; i++) { int classe = ((int) Md[i][columns - 1]); DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset(); int j = 0; double value = 0; while (j < features.length) { /*value recebe o valor da linha i e da coluna especificada pelo usuario, por meio do parametro de chegada features[]*/ value = Md[i][features[j]]; String strclasse = String.valueOf(classe); //especifico Marie-Anne /* if (classe == 0) { strclasse = "thi1"; lineandshaperenderer[classe].setSeriesPaint(0, Color.RED); Shape s0 = new Rectangle2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s0); } else if (classe == 1) { strclasse = "controle"; lineandshaperenderer[classe].setSeriesPaint(0, Color.PINK); Shape s1 = new Ellipse2D.Float(-3f, -3f, 6f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s1); } else if (classe == 2) { strclasse = "fotossntese"; lineandshaperenderer[classe].setSeriesPaint(0, Color.GREEN); int[] x = {-3, 0, 3}; int[] y = {-3, 3, -3}; int n = 3; Shape s2 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesShape(0, s2); } else if (classe == 3) { strclasse = "respirao"; int[] x = {-3, 0, 3}; int[] y = {3, -3, 3}; int n = 3; Shape s3 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesShape(0, s3); lineandshaperenderer[classe].setSeriesPaint(0, Color.BLUE); } else if (classe == 4) { strclasse = "sntese de tiamina"; lineandshaperenderer[classe].setSeriesPaint(0, Color.BLACK); Shape s4 = new Rectangle2D.Float(-1f, -3f, 1f, 6f); lineandshaperenderer[classe].setSeriesShape(0, s4); } else if (classe == 5) { strclasse = "gliclise"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.ORANGE); lineandshaperenderer[classe].setSeriesShape(0, s5); } else if (classe == 6) { strclasse = "AT4G34200"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.MAGENTA); lineandshaperenderer[classe].setSeriesShape(0, s5); } else if (classe == 7) { strclasse = "AT2G36530"; int[] x = {-3, 0, 3, 0}; int[] y = {0, -3, 0, 3}; int n = 4; Shape s5 = new Polygon(x, y, n); lineandshaperenderer[classe].setSeriesPaint(0, Color.CYAN); lineandshaperenderer[classe].setSeriesShape(0, s5); } */ if (featurestitles != null) { if (datatitles != null) { dataset.addValue(value, strclasse, (String) featurestitles.get(features[j] + 1)); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c + 1)); } else { dataset.addValue(value, strclasse, (String) featurestitles.get(features[j])); //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c)); } } else { dataset.addValue(value, strclasse, String.valueOf(features[j])); //datasets[i].addValue(Mo[lineindex[i]][c], label, String.valueOf(c)); } //dataset.addValue(value, String.valueOf(classe), String.valueOf(features[j])); j++; } categoryplot.setDataset(count, dataset); categoryplot.setRenderer(count, lineandshaperenderer[classe]); count++; } LegendItemCollection legends = categoryplot.getLegendItems(); LegendItemCollection newlegends = new LegendItemCollection(); for (int i = 0; i < classes; i++) { int l = 0; //especifico Marie-Anne String label1 = null; if (i == 0) { label1 = "thi1"; } else if (i == 1) { label1 = "controle"; } else if (i == 2) { label1 = "fotossntese"; } else if (i == 3) { label1 = "respirao"; } else if (i == 4) { label1 = "sntese de tiamina"; } else if (i == 5) { label1 = "gliclise"; } else if (i == 6) { label1 = "AT4G34200"; } else if (i == 7) { label1 = "AT2G36530"; } //String label1 = String.valueOf(i); String label2 = null; boolean found = false; do { label2 = legends.get(l).getLabel(); if (label1.equalsIgnoreCase(label2)) { found = true; } else { l++; } } while (!found && (l < lines)); if (found) { //newlegends.add(legends.get(l)); LegendItem li = new LegendItem(legends.get(l).getLabel(), legends.get(l).getDescription(), legends.get(l).getToolTipText(), legends.get(l).getURLText(), legends.get(l).isShapeVisible(), legends.get(l).getShape(), legends.get(l).isShapeFilled(), legends.get(l).getFillPaint(), legends.get(l).isShapeOutlineVisible(), legends.get(l).getOutlinePaint(), legends.get(l).getOutlineStroke(), legends.get(l).isLineVisible(), legends.get(l).getLine(), legends.get(l).getLineStroke(), legends.get(l).getLinePaint()); newlegends.add(li); } } categoryplot.setFixedLegendItems(newlegends); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }