List of usage examples for org.jfree.chart LegendItemCollection add
public void add(LegendItem item)
From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.GroupedStackedBarRendererCustomizer.java
@Override public void customize(JFreeChart chart, ReportParameters reportParameters) { this.seriesColors = new LinkedHashMap<String, Paint>(); this.map = null; Set<String> groups = new LinkedHashSet<String>(); CategoryDataset dataset = chart.getCategoryPlot().getDataset(); for (int i = 0; i < dataset.getRowCount(); i++) { String rowKey = (String) dataset.getRowKey(i); String group = StringUtils.substringBefore(rowKey, GROUP_SERIES_KEY); String series = StringUtils.substringAfter(rowKey, GROUP_SERIES_KEY); if (map == null) { map = new KeyToGroupMap(group); }/* w w w .j a v a 2 s . c o m*/ map.mapKeyToGroup(rowKey, group); groups.add(group); if (!seriesColors.containsKey(series)) { Paint paint = chart.getCategoryPlot().getDrawingSupplier().getNextPaint(); seriesColors.put(series, paint); } } DefaultCategoryDataset newDataset = new DefaultCategoryDataset(); for (Object column : dataset.getColumnKeys()) { for (String group : groups) { for (String series : seriesColors.keySet()) { try { Number value = dataset.getValue(group + GROUP_SERIES_KEY + series, (Comparable<?>) column); newDataset.addValue(value, group + GROUP_SERIES_KEY + series, (Comparable<?>) column); } catch (UnknownKeyException e) { newDataset.addValue(0, group + GROUP_SERIES_KEY + series, (Comparable<?>) column); } } } } dataset = newDataset; GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); renderer.setSeriesToGroupMap(map); StackedBarRenderer categoryRenderer = (StackedBarRenderer) chart.getCategoryPlot().getRenderer(); renderer.setBaseItemLabelsVisible(categoryRenderer.getBaseItemLabelsVisible()); renderer.setBaseItemLabelFont(categoryRenderer.getBaseItemLabelFont()); renderer.setBaseItemLabelPaint(categoryRenderer.getBaseItemLabelPaint()); renderer.setBaseItemLabelGenerator(categoryRenderer.getBaseItemLabelGenerator()); renderer.setShadowVisible(categoryRenderer.getShadowsVisible()); renderer.setItemMargin(0.10); renderer.setDrawBarOutline(false); for (int i = 0; i < dataset.getRowCount(); i++) { String rowKey = (String) dataset.getRowKey(i); String score = StringUtils.substringAfter(rowKey, GROUP_SERIES_KEY); renderer.setSeriesPaint(i, seriesColors.get(score)); } CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis(); SubCategoryAxis newDomainAxis = new SubCategoryAxis(domainAxis.getLabel()); newDomainAxis.setLabelFont(domainAxis.getLabelFont()); newDomainAxis.setTickLabelFont(domainAxis.getTickLabelFont()); newDomainAxis.setLabelPaint(domainAxis.getLabelPaint()); newDomainAxis.setTickLabelPaint(domainAxis.getTickLabelPaint()); newDomainAxis.setAxisLinePaint(domainAxis.getAxisLinePaint()); newDomainAxis.setTickMarkPaint(domainAxis.getTickMarkPaint()); newDomainAxis.setTickLabelsVisible(domainAxis.isTickLabelsVisible()); newDomainAxis.setTickMarksVisible(domainAxis.isTickMarksVisible()); newDomainAxis.setCategoryMargin(0.05); for (String group : groups) { newDomainAxis.addSubCategory(group); } CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(newDomainAxis); plot.setRenderer(renderer); LegendItemCollection legendItems = new LegendItemCollection(); for (String item : seriesColors.keySet()) { legendItems.add(new LegendItem(item, seriesColors.get(item))); } plot.setFixedLegendItems(legendItems); chart.getCategoryPlot().setDataset(dataset); }
From source file:net.sf.mzmine.modules.visualization.ida.IDAVisualizerWindow.java
/** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) *///from w w w . ja va 2 s . c om public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("SHOW_SPECTRUM")) { CursorPosition pos = getCursorPosition(); if (pos != null) { SpectraVisualizerModule.showNewSpectrumWindow(pos.getDataFile(), pos.getScanNumber()); } } if (command.equals("SETUP_AXES")) { AxesSetupDialog dialog = new AxesSetupDialog(this, IDAPlot.getXYPlot()); dialog.setVisible(true); } if (command.equals("SHOW_DATA_POINTS")) { IDAPlot.switchDataPointsVisible(); } if (command.equals("SWITCH_TOOLTIPS")) { if (tooltipMode) { IDAPlot.showPeaksTooltips(false); toolBar.setTooltipButton(false); tooltipMode = false; } else { IDAPlot.showPeaksTooltips(true); toolBar.setTooltipButton(true); tooltipMode = true; } } if (command.equals("FIND_SPECTRA")) { // Parameters final DoubleParameter inputMZ = new DoubleParameter("Ion m/z", "m/z value of ion to search for."); final MZToleranceParameter inputMZTolerance = new MZToleranceParameter(); final DoubleParameter inputIntensity = new DoubleParameter("Min. ion intensity", "Only ions with intensities above this value will be searched for."); final BooleanParameter inputNL = new BooleanParameter("Neutral Loss", "If selected, the ion to be searched for will be a neutral loss ion.\nIn this case, only ions above the min. intensity will be examined.", false); final ComboParameter<Colors> inputColors = new ComboParameter<Colors>("Color", "The color which the data points will be marked with.", Colors.values()); Parameter<?>[] parameters = new Parameter<?>[5]; parameters[0] = inputMZ; parameters[1] = inputMZTolerance; parameters[2] = inputIntensity; parameters[3] = inputNL; parameters[4] = inputColors; final ParameterSet parametersSearch = new SimpleParameterSet(parameters); ExitCode exitCode = parametersSearch.showSetupDialog(this, true); if (exitCode != ExitCode.OK) return; double searchMZ = parametersSearch.getParameter(inputMZ).getValue(); MZTolerance searchMZTolerance = parametersSearch.getParameter(inputMZTolerance).getValue(); double minIntensity = parametersSearch.getParameter(inputIntensity).getValue(); boolean neutralLoss = parametersSearch.getParameter(inputNL).getValue(); Color highligtColor = Color.red; ; if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.green)) { highligtColor = Color.green; } if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.blue)) { highligtColor = Color.blue; } // Find and highlight spectra with specific ion dataset.highlightSpectra(searchMZ, searchMZTolerance, minIntensity, neutralLoss, highligtColor); // Add legend entry LegendItemCollection chartLegend = IDAPlot.getXYPlot().getLegendItems(); chartLegend.add(new LegendItem("Ion: " + searchMZ, "", "MS/MS spectra which contain the " + searchMZ + " ion\nTolerance: " + searchMZTolerance.toString() + "\nMin intensity: " + minIntensity, "", new Ellipse2D.Double(0, 0, 7, 7), highligtColor)); IDAPlot.getXYPlot().setFixedLegendItems(chartLegend); } }
From source file:com.xilinx.kintex7.PowerDial.java
public void createDial() { plot = new MeterPlot(); dset = new DefaultValueDataset(0); plot.setUnits("Watts"); plot.setRange(new Range(1, 10)); plot.addInterval(new MeterInterval("Acceptable", new Range(1.0, 6.0), Color.lightGray, new BasicStroke(2.0f), Color.GREEN)); plot.addInterval(new MeterInterval("Warning", new Range(6.0, 8.0), Color.lightGray, new BasicStroke(2.0f), Color.YELLOW));/*from ww w. j a v a 2 s. c o m*/ plot.addInterval(new MeterInterval("Dangerous", new Range(8.0, 10.0), Color.lightGray, new BasicStroke(2.0f), Color.RED)); //sets different marks for (int i = 0; i < 10; i += 1) { if (i == 0) plot.addInterval( new MeterInterval("", new Range(1, 1), Color.lightGray, new BasicStroke(2.0f), null)); else plot.addInterval( new MeterInterval("", new Range(i, i), Color.lightGray, new BasicStroke(2.0f), null)); } plot.setNeedlePaint(Color.darkGray); plot.setDialBackgroundPaint(Color.white); plot.setDialOutlinePaint(Color.gray); plot.setDialShape(DialShape.PIE); plot.setMeterAngle(180); plot.setTickLabelsVisible(true); plot.setTickLabelFont(new Font("Dialog", Font.BOLD, 10)); plot.setTickLabelPaint(Color.DARK_GRAY); plot.setTickSize(10.0); plot.setTickPaint(Color.lightGray); plot.setValuePaint(Color.BLACK); plot.setDataset(dset); LegendItemCollection legendItemsOld = plot.getLegendItems(); final LegendItemCollection legendItemsNew = new LegendItemCollection(); for (int i = 0; i < 3; i++) { LegendItem item = legendItemsOld.get(i); item.setLabelPaint(Color.WHITE); legendItemsNew.add(item); } LegendItemSource source = new LegendItemSource() { LegendItemCollection lic = new LegendItemCollection(); { lic.addAll(legendItemsNew); } @Override public LegendItemCollection getLegendItems() { return lic; } }; chart = new JFreeChart(plot); chart.addLegend(new LegendTitle(source)); chart.removeLegend(); chart.setTitle(""); //chart.setBackgroundPaint(new GradientPaint(0,0,new Color(139,137,137),0,height,Color.BLUE )); // chart.getTitle().setPaint(Color.white); plot.setValueFont(new Font("Dialog", Font.BOLD, 14)); //chartpanel = new ChartPanel(chart); }
From source file:pwm.visualizer.MDPPolicyPanel.java
private JFreeChart createChart() { NumberAxis nutritionAxis = new NumberAxis("Calories/Day"); nutritionAxis.setLowerBound(0);/*w w w. j a v a 2 s . c om*/ nutritionAxis.setUpperBound(5000); nutritionAxis.setAutoRange(false); // CategoryPlot categoryplot = new CategoryPlot(nutritionDataSet, new CategoryAxis("Weight(KG)"), nutritionAxis, new BarRenderer()); CategoryAxis xaxis = categoryplot.getDomainAxis(); xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); LegendItemCollection legend = new LegendItemCollection(); LegendItem nutritionLegend = new LegendItem("Calories/Day"); LegendItem exerciseLegend = new LegendItem("Physical Activity Level"); nutritionLegend.setFillPaint(Color.BLUE); exerciseLegend.setFillPaint(Color.RED); legend.add(nutritionLegend); legend.add(exerciseLegend); categoryplot.setFixedLegendItems(legend); JFreeChart jfreechart = new JFreeChart("Policy Visualizer", categoryplot); categoryplot.setDataset(1, exerciseDataSet); categoryplot.mapDatasetToRangeAxis(1, 1); NumberAxis exerciseAxis = new NumberAxis("Physical Activity Level"); exerciseAxis.setLowerBound(0); exerciseAxis.setUpperBound(3.0); exerciseAxis.setAutoRange(false); categoryplot.setRangeAxis(1, exerciseAxis); BarRenderer barrenderer1 = new BarRenderer(); categoryplot.setRenderer(1, barrenderer1); // BarRenderer stackedbarrenderer = (BarRenderer)categoryplot.getRenderer(); // stackedbarrenderer.setDrawBarOutline(true); // stackedbarrenderer.setBaseItemLabelsVisible(false); // stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java
private LegendItemCollection createLegendItems() { LegendItemCollection result = new LegendItemCollection(); LegendItem item1 = new LegendItem("DCM ", color1); LegendItem item2 = new LegendItem("JPG ", color2); result.add(item1); result.add(item2);/* w w w . j a va 2s.c om*/ return result; }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet2.java
private LegendItemCollection createLegendItems() { LegendItemCollection result = new LegendItemCollection(); LegendItem item1 = new LegendItem("", color1); LegendItem item2 = new LegendItem("", color2); result.add(item1); result.add(item2);//from ww w.j a va 2 s . com return result; }
From source file:org.tsho.dmc2.core.chart.TrajectoryMultiRenderer.java
public LegendItemCollection getLegendItems() { Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL); Shape shape = new Rectangle2D.Double(-3, -3, 6, 6); LegendItemCollection legendItems = new LegendItemCollection(); for (int i = 0; i < stepperList.length; i++) { legendItems.add(new LegendItem(Integer.toString(i), "", shape, true, paintList[i], stroke, Color.yellow, stroke));//from ww w . j a v a 2 s . c o m } return legendItems; }
From source file:org.tsho.dmc2.core.chart.Bifurcation2DRenderer.java
public LegendItemCollection getLegendItems() { Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL); Shape shape = new Rectangle2D.Double(-3, -3, 6, 6); LegendItemCollection legendItems = new LegendItemCollection(); for (int i = 0; i < period; i++) { legendItems.add(new LegendItem(Integer.toString(i + 1), "", shape, true, (DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i]), stroke, Color.yellow, stroke)); }/* w w w.j a va2 s .com*/ legendItems.add(new LegendItem(">" + period, "", shape, true, Color.white, stroke, Color.yellow, stroke)); legendItems.add(new LegendItem("infinity", "", shape, true, Color.black, stroke, Color.yellow, stroke)); return legendItems; }
From source file:com.alcatel_lucent.nz.wnmsreport.chart.TimeSeriesIuRChartCustomiser.java
public void customise(JFreeChart chart, JRChart jasperchart) { XYPlot xyplot = chart.getXYPlot();/* w w w .j ava 2s . c om*/ XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); XYDataset xyDataset = xyplot.getDataset(); LegendItemCollection legend = xyplot.getLegendItems(); LegendItemCollection revised = new LegendItemCollection(); if (xyDataset != null) { for (int i = 0; i < xyDataset.getSeriesCount(); i++) { if (i < 1) { //make line 1 dashed renderer.setSeriesStroke(i, stroke_dashed); } else { //make other lines filled and add to new legend renderer.setSeriesStroke(i, stroke_normal); revised.add(legend.get(i)); } renderer.setSeriesLinesVisible(i, true); } } xyplot.setFixedLegendItems(revised); }
From source file:de.fub.maps.project.detector.model.inference.ui.InferenceResultPanel.java
public void updateView(InferenceDataProcessHandler.ClassificationResult classificationResult) { DefaultCategoryDataset relDataset = getClassificationBarChart().getRelDataset(); DefaultCategoryDataset absDataset = getClassificationBarChart().getAbsDataset(); relDataset.clear();/*from w w w . ja v a 2 s.co m*/ absDataset.clear(); dataItemList.clear(); Map<String, List<Instance>> resultMap = classificationResult.getResultMap(); if (!resultMap.isEmpty()) { double sum = 0; for (Entry<String, List<Instance>> entry : resultMap.entrySet()) { sum += entry.getValue().size(); } CategoryPlot plot = getClassificationBarChart().getPlot(); CategoryItemRenderer relRenderer = plot.getRenderer(0); CategoryItemRenderer absRenderer = plot.getRenderer(1); ArrayList<String> arrayList = new ArrayList<String>(resultMap.keySet()); Collections.sort(arrayList); for (String transportMode : arrayList) { double abs = resultMap.get(transportMode).size(); double rel = abs / sum * 100; absDataset.addValue(null, "Instances (rel.)", transportMode); absDataset.addValue(abs, "Instances (abs.)", transportMode); relDataset.addValue(rel, "Instances (rel.)", transportMode); relDataset.addValue(null, "Instances (abs.)", transportMode); dataItemList.add(new DataItem(transportMode, rel, abs)); } final LegendItemCollection result = new LegendItemCollection(); result.add(relRenderer.getLegendItem(0, 0)); result.add(absRenderer.getLegendItem(1, 1)); double classified = (sum / classificationResult.getInstanceToTrackSegmentMap().size() * 100); double notClassified = ((classificationResult.getInstanceToTrackSegmentMap().size() - sum) / classificationResult.getInstanceToTrackSegmentMap().size() * 100); getClassifiedInstances().setText(MessageFormat.format("{0, number, 000.00} %", classified)); getNotClassifiedInstances().setText(MessageFormat.format("{0, number, 000.00} %", notClassified)); repaint(); } }