List of usage examples for org.jfree.chart LegendItem LegendItem
public LegendItem(AttributedString label, String description, String toolTipText, String urlText, Shape shape,
Paint fillPaint)
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.XYDotRenderer.java
/** * Returns a legend item for the specified series. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * @return A legend item for the series (possibly <code>null</code>). */// w ww .j a v a 2 s . com public LegendItem getLegendItem(final int datasetIndex, final int series) { // if the renderer isn't assigned to a plot, then we don't have a // dataset... final XYPlot plot = getPlot(); if (plot == null) { return null; } final XYDataset dataset = plot.getDataset(datasetIndex); if (dataset == null) { return null; } LegendItem result = null; if (getItemVisible(series, 0)) { final String label = getLegendItemLabelGenerator().generateLabel(dataset, series); String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel(dataset, series); } final Paint fillPaint = lookupSeriesPaint(series); result = new LegendItem(label, label, toolTipText, urlText, getLegendShape(), fillPaint); result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); result.setDataset(dataset); result.setDatasetIndex(datasetIndex); } return result; }
From source file:edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo4.java
/** * Creates the legend items for the chart. In this case, we set them * manually because we only want legend items for a subset of the data * series.//from w ww.j av a2 s. co m * * @return The legend items. */ private static LegendItemCollection createLegendItems() { LegendItemCollection result = new LegendItemCollection(); LegendItem item1 = new LegendItem("US", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX, new Color(0x22, 0x22, 0xFF)); LegendItem item2 = new LegendItem("Europe", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX, new Color(0x22, 0xFF, 0x22)); LegendItem item3 = new LegendItem("Asia", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX, new Color(0xFF, 0x22, 0x22)); LegendItem item4 = new LegendItem("Middle East", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX, new Color(0xFF, 0xFF, 0x22)); result.add(item1); result.add(item2); result.add(item3); result.add(item4); return result; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYDataset dataset = (XYDataset) datasets.getDatasets().get("1"); final JFreeChart sparkLineGraph = ChartFactory.createTimeSeriesChart(null, null, null, dataset, legend, false, false);//w ww. j a va2 s . c o m sparkLineGraph.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); sparkLineGraph.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); sparkLineGraph.addSubtitle(subTitle); } sparkLineGraph.setBorderVisible(false); sparkLineGraph.setBorderPaint(Color.BLACK); XYPlot plot = sparkLineGraph.getXYPlot(); plot.setOutlineVisible(false); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(color); // calculate the last marker color Paint colorLast = getLastPointColor(); // Calculate average, minimum and maximum to draw plot borders. boolean isFirst = true; double avg = 0, min = Double.POSITIVE_INFINITY, max = Double.NEGATIVE_INFINITY; int count = 0; for (int i = 0; i < timeSeries.getItemCount(); i++) { if (timeSeries.getValue(i) != null) { count++; if (isFirst) { min = timeSeries.getValue(i).doubleValue(); max = timeSeries.getValue(i).doubleValue(); isFirst = false; } double n = timeSeries.getValue(i).doubleValue(); //calculate avg, min, max avg += n; if (n < min) min = n; if (n > max) max = n; } } // average avg = avg / (double) count; // calculate min and max between thresholds! boolean isFirst2 = true; double lb = 0, ub = 0; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); if (isFirst2 == true) { ub = thres.doubleValue(); lb = thres.doubleValue(); isFirst2 = false; } if (thres.doubleValue() > ub) ub = thres.doubleValue(); if (thres.doubleValue() < lb) lb = thres.doubleValue(); } plot.getRangeAxis().setRange(new Range(Math.min(lb, min - 2), Math.max(ub, max + 2) + 2)); addMarker(1, avg, Color.GRAY, 0.8f, plot); //addAvaregeSeries(series, plot); addPointSeries(timeSeries, plot); int num = 3; for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); TargetThreshold targThres = thresholds.get(thres); Color color = Color.WHITE; if (targThres != null && targThres.getColor() != null) { color = targThres.getColor(); } if (targThres.isVisible()) { addMarker(num++, thres.doubleValue(), color, 0.5f, plot); } } ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); domainAxis.setUpperMargin(0.2); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(false); plot.getRenderer().setSeriesPaint(0, Color.BLACK); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public boolean getItemShapeVisible(int _series, int item) { TimeSeriesDataItem tsdi = timeSeries.getDataItem(item); if (tsdi == null) return false; Month period = (Month) tsdi.getPeriod(); int currMonth = period.getMonth(); int currYear = period.getYearValue(); int lastMonthFilled = lastMonth.getMonth(); int lastYearFilled = lastMonth.getYearValue(); boolean isLast = false; if (currYear == lastYearFilled && currMonth == lastMonthFilled) { isLast = true; } return isLast; } }; renderer.setSeriesPaint(0, Color.decode("0x000000")); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(colorLast); renderer.setBaseOutlinePaint(Color.BLACK); renderer.setUseOutlinePaint(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0)); if (wlt_mode.doubleValue() == 0) { renderer.setBaseItemLabelsVisible(Boolean.FALSE, true); } else { renderer.setBaseItemLabelsVisible(Boolean.TRUE, true); renderer.setBaseItemLabelFont( new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize())); renderer.setBaseItemLabelPaint(styleValueLabels.getColor()); renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.###"), new DecimalFormat("0.###")) { public String generateLabel(CategoryDataset dataset, int row, int column) { if (dataset.getValue(row, column) == null || dataset.getValue(row, column).doubleValue() == 0) return ""; String columnKey = (String) dataset.getColumnKey(column); int separator = columnKey.indexOf('-'); String month = columnKey.substring(0, separator); String year = columnKey.substring(separator + 1); int monthNum = Integer.parseInt(month); if (wlt_mode.doubleValue() >= 1 && wlt_mode.doubleValue() <= 4) { if (wlt_mode.doubleValue() == 2 && column % 2 == 0) return ""; Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MONTH, monthNum - 1); SimpleDateFormat dataFormat = new SimpleDateFormat("MMM"); return dataFormat.format(calendar.getTime()); } else return "" + monthNum; } }); } if (wlt_mode.doubleValue() == 3) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 2)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 2)); } else if (wlt_mode.doubleValue() == 4) { renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, org.jfree.ui.TextAnchor.BOTTOM_CENTER, org.jfree.ui.TextAnchor.BOTTOM_RIGHT, Math.PI / 4)); renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, org.jfree.ui.TextAnchor.TOP_CENTER, org.jfree.ui.TextAnchor.HALF_ASCENT_LEFT, Math.PI / 4)); } if (legend == true) { LegendItemCollection collection = createThresholdLegend(plot); LegendItem item = new LegendItem("Avg", "Avg", "Avg", "Avg", new Rectangle(10, 10), colorAverage); collection.add(item); plot.setFixedLegendItems(collection); } plot.setRenderer(0, renderer); logger.debug("OUT"); return sparkLineGraph; }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java
private void buildLegend() { LegendTitle legend = corrChart.getLegend(); LegendItemSource[] sources = new LegendItemSource[1]; CorrLegendItemSource legendSrc = new CorrLegendItemSource(); LegendItem item = null;/*from ww w .ja v a2 s . c o m*/ //Rect=survival less than 10 months GeneralPath downtriangle = new GeneralPath(); downtriangle.moveTo(-4.0f, -4.0f); downtriangle.lineTo(4.0f, -4.0f); downtriangle.lineTo(0.0f, 4.0f); downtriangle.closePath(); item = new LegendItem("Tumor size reduced by 30% or more (MRI)", null, null, null, downtriangle, Color.BLACK); legendSrc.addLegendItem(item); item = new LegendItem("Tumor size reduced less than 30% or no change (MRI)", null, null, null, new Ellipse2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); GeneralPath uptriangle = new GeneralPath(); uptriangle.moveTo(0.0f, -4.0f); uptriangle.lineTo(4.0f, 4.0f); uptriangle.lineTo(-4.0f, 4.0f); uptriangle.closePath(); item = new LegendItem("Tumor size increased (MRI)", null, null, null, uptriangle, Color.BLACK); legendSrc.addLegendItem(item); item = new LegendItem("Tumor size change N/A", null, null, null, new Rectangle2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); if (colorBy == ColorByType.CLINICALRESPONSE) { for (ClinicalResponseType cr : ClinicalResponseType.values()) { item = new LegendItem(cr.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), cr.getColor()); legendSrc.addLegendItem(item); } } else if (colorBy == ColorByType.DISEASESTAGE) { for (ClinicalStageType ds : ClinicalStageType.values()) { if (!ds.name().endsWith("ALL")) { item = new LegendItem(ds.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ds.getColor()); legendSrc.addLegendItem(item); } } } else if (colorBy == ColorByType.TIMEPOINT) { for (TimepointType tp : TimepointType.values()) { item = new LegendItem(tp.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), tp.getColor()); legendSrc.addLegendItem(item); } } else if ((colorBy == ColorByType.IHC_EXPRESSION_X) || (colorBy == ColorByType.IHC_EXPRESSION_Y)) { // for (CorrScatterColorByIHCType ihcType : CorrScatterColorByIHCType.values()) { // item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), ihcType.getColor()); // legendSrc.addLegendItem(item); // } if (ihcBiomarkerType == IHCBiomarkerType.BCL2) { for (BCL2ihcType ihcType : BCL2ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.EGFR) { for (EGFRihcType ihcType : EGFRihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.FAK) { for (FAKihcType ihcType : FAKihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.HER2) { for (HER2ihcType ihcType : HER2ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.KI67) { for (Ki67ihcType ihcType : Ki67ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.P27) { for (P27ihcType ihcType : P27ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.P53) { for (P53ihcType ihcType : P53ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.CYCLIN_D1) { for (CCND1ihcType ihcType : CCND1ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } } sources[0] = legendSrc; legend.setSources(sources); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.SpeedometerMultiValue.java
/** * Creates a chart of type speedometer./*from ww w.j av a2 s. co m*/ * * @param chartTitle the chart title. * @param dataset the dataset. * * @return A chart speedometer. */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); JFreeChart chart = null; try { MyDialPlot plot = new MyDialPlot(); HashMap hmDataset = datasets.getDatasets(); Set keyDataset = hmDataset.keySet(); int i = 0; Iterator itDataset = keyDataset.iterator(); while (itDataset.hasNext()) { String key = (String) itDataset.next(); Dataset dataset = (Dataset) hmDataset.get(key); plot.setDataset(i, (ValueDataset) dataset); if (key.indexOf("__") > 0) setName(key.substring(0, key.indexOf("__"))); else setName(key); i++; } plot.setDialFrame(new StandardDialFrame()); plot.setBackground(new DialBackground()); if (dialtextuse) { DialTextAnnotation annotation1 = new DialTextAnnotation(dialtext); annotation1.setFont(styleTitle.getFont()); annotation1.setRadius(0.7); plot.addLayer(annotation1); } StandardDialScale scale = new StandardDialScale(lower, upper, -120, -300, 10.0, 4); if (!(increment > 0)) { logger.warn("increment cannot be less than 0, put default to 0.1 "); increment = 0.1; } scale.setMajorTickIncrement(increment); scale.setMinorTickCount(minorTickCount); scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); //set tick label style scale.setTickLabelsVisible(true); Font tickLabelsFont = new Font(labelsTickStyle.getFontName(), Font.PLAIN, labelsTickStyle.getSize()); scale.setTickLabelFont(tickLabelsFont); scale.setTickLabelPaint(labelsTickStyle.getColor()); plot.addScale(0, scale); DialCap cap = new DialCap(); plot.setCap(cap); // sets intervals for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); StandardDialRange range = new StandardDialRange(interval.getMin(), interval.getMax(), interval.getColor()); range.setInnerRadius(0.50); range.setOuterRadius(0.85); range.setPaint(interval.getColor()); plot.addLayer(range); } plot.setBackground(new DialBackground()); logger.debug("Set values color"); Vector arValuesName = getValuesNames(); legendItems = new LegendItemCollection(); for (int j = 0; j < arValuesName.size(); j++) { DialPointer.Pin p = new DialPointer.Pin(j); if (colorMap != null) { String valueName = (String) arValuesName.get(j); Color color = (Color) colorMap.get(valueName); if (color != null) p.setPaint(color); if (serieLegend.equalsIgnoreCase(name)) { if (j < arValuesName.size()) { LegendItem item = new LegendItem(valueName, "", "", "", new Ellipse2D.Double(-3, -5, 8, 8), color); if (item != null) { legendItems.add(item); } } if (legend) super.height = super.height + (super.height * 12 / 100); } } plot.addLayer(p); } plot.setLegendItems(legendItems); chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, false); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.setBackgroundPaint(color); if (legend == true) drawLegend(chart); } catch (Exception ex) { logger.debug("Error while creating speedometer multivalue: " + ex); } logger.debug("OUT"); return chart; }
From source file:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Returns a legend item for the specified series. * /*from w w w . jav a 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 (possibly <code>null</code>). * @see * org.jfree.chart.renderer.xy.XYItemRenderer#getLegendItem(int, * int) */ public LegendItem getLegendItem(int datasetIndex, int series) { // if the renderer isn't assigned to a plot, then we don't have a // dataset... XYPlot plot = getPlot(); if (plot == null) { return null; } XYDataset dataset = plot.getDataset(datasetIndex); if (dataset == null) { return null; } LegendItem result = 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); } Paint fillPaint = lookupSeriesPaint(series); result = new LegendItem(label, description, toolTipText, urlText, getLegendShape(), fillPaint); result.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { result.setLabelPaint(labelPaint); } result.setSeriesKey(dataset.getSeriesKey(series)); result.setSeriesIndex(series); result.setDataset(dataset); result.setDatasetIndex(datasetIndex); } return result; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.TargetCharts.java
public LegendItemCollection createThresholdLegend(Plot plot) { logger.debug("IN"); LegendItemCollection collection = new LegendItemCollection(); for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) { Double thres = (Double) iterator.next(); TargetThreshold thresTarg = thresholds.get(thres); String thresholdName = thresTarg != null ? thresTarg.getName() : ""; Color color = Color.BLACK; if (thresTarg.getColor() != null) { color = thresTarg.getColor(); }// w ww .jav a 2 s. c om // could add bottom only if used LegendItem item = new LegendItem(thresholdName, thresholdName, thresholdName, thresholdName, new Rectangle(10, 10), color); collection.add(item); } logger.debug("OUT"); return collection; }