List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setSeriesVisibleInLegend
public void setSeriesVisibleInLegend(Boolean visible, boolean notify);
From source file:PlotsBuilding.PlotPanel.java
private JFreeChart createChart(XYDataset xyDataset, ArrayList<Integer> seriesCount, double y1, double y2) { NumberAxis domainAxis = new NumberAxis("x"); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setPositiveArrowVisible(true); NumberAxis rangeAxis = new NumberAxis("y"); rangeAxis.setRange(y1, y2);/*from www.j av a2s .c om*/ rangeAxis.setPositiveArrowVisible(true); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); int start = 0; int color = 50; for (Object series : seriesCount) { for (int i = start; i < start + (int) series; i++) { Color s = new Color(color); renderer.setSeriesPaint(i, s); renderer.setSeriesVisibleInLegend(i, false); renderer.setSeriesVisibleInLegend(start, true); } start = start + (int) series; color *= 100; } renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(xyDataset, domainAxis, rangeAxis, renderer); PlotOrientation orientation = PlotOrientation.VERTICAL; plot.setOrientation(orientation); plot.setBackgroundPaint(Color.white); chart = new JFreeChart(plot); chart.setBackgroundPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.RIGHT); chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP); return chart; }
From source file:net.sf.maltcms.chromaui.charts.events.ChartPanelMouseListener.java
/** * * @param arg0/* ww w.ja v a2 s.c o m*/ */ @Override public void chartMouseClicked(final ChartMouseEvent arg0) { final ChartPanelMouseListener cpml = this; if (arg0.getEntity() != null) { if (arg0.getEntity() instanceof XYItemEntity) { XYItemEntity xyie = (XYItemEntity) arg0.getEntity(); if (arg0.getTrigger().getButton() == MouseEvent.BUTTON1) { // if (arg0.getTrigger().isAltDown() && arg0.getTrigger().isShiftDown()) { // System.out.println("Item removed"); fireEvent(new XYItemEntityRemovedEvent((XYItemEntity) arg0.getEntity(), cpml)); } else if (arg0.getTrigger().isAltDown()) { // System.out.println("Item added"); fireEvent(new XYItemEntityAddedEvent((XYItemEntity) arg0.getEntity(), cpml)); } else { setTarget(arg0); // System.out.println("Item clicked"); fireEvent(new XYItemEntityClickedEvent((XYItemEntity) arg0.getEntity(), cpml)); } } } else if (arg0.getEntity() instanceof LegendItemEntity) { JPopupMenu jpm = new JPopupMenu(); final LegendItemEntity lie = (LegendItemEntity) arg0.getEntity(); Dataset ds = lie.getDataset(); Comparable skey = lie.getSeriesKey(); Plot plot = arg0.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot xyplot = arg0.getChart().getXYPlot(); if (xyplot.getSeriesCount() > 1) { XYDataset xyds = (XYDataset) ds; XYItemRenderer xyir = xyplot.getRendererForDataset(xyds); xyir.setSeriesVisible(xyds.indexOf(skey), !xyir.isSeriesVisible(xyds.indexOf(skey))); xyir.setSeriesVisibleInLegend(xyds.indexOf(skey), Boolean.TRUE); } } else if (plot instanceof CategoryPlot) { CategoryPlot cplot = arg0.getChart().getCategoryPlot(); if (cplot.getDatasetCount() > 1) { CategoryDataset cds = (CategoryDataset) ds; CategoryItemRenderer xyir = cplot.getRendererForDataset(cds); int seriesIndex = cds.getColumnIndex(skey); if (seriesIndex == -1) { seriesIndex = cds.getRowIndex(skey); } xyir.setSeriesVisible(seriesIndex, !xyir.isSeriesVisible(seriesIndex)); xyir.setSeriesVisibleInLegend(seriesIndex, Boolean.TRUE); } } // AbstractAction hse = new AbstractAction("Hide") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; // AbstractAction hse = new AbstractAction("Show") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; // AbstractAction hse = new AbstractAction("Remove") { // // @Override // public void actionPerformed(ActionEvent ae) { // // } // }; } } }
From source file:org.projectforge.charting.XYChartBuilder.java
/** * Applies {@link #strongCircleShape} and {@link #strongStroke} if set to all series entries. * @param renderer//from w w w .jav a 2 s . c om * @param visibleInLegend * @param series * @return */ public XYChartBuilder setNormalStyle(final XYItemRenderer renderer, final boolean visibleInLegend, final Series... series) { if (series == null || series.length == 0) { return this; } for (int i = 0; i < series.length; i++) { renderer.setSeriesShape(i, circleShape); } for (int i = 0; i < series.length; i++) { renderer.setSeriesStroke(i, stroke); renderer.setSeriesVisibleInLegend(i, visibleInLegend); } return this; }
From source file:org.projectforge.charting.XYChartBuilder.java
/** * Applies {@link #strongCircleShape} and {@link #strongStroke} if set to all series entries. * @param renderer/* w w w. ja v a2 s.co m*/ * @param visibleInLegend * @param series * @return */ public XYChartBuilder setStrongStyle(final XYItemRenderer renderer, final boolean visibleInLegend, final Series... series) { if (series == null || series.length == 0) { return this; } for (int i = 0; i < series.length; i++) { renderer.setSeriesShape(i, strongCircleShape); } for (int i = 0; i < series.length; i++) { renderer.setSeriesStroke(i, strongStroke); renderer.setSeriesVisibleInLegend(i, visibleInLegend); } return this; }
From source file:no.met.jtimeseries.chart.ChartPlotter.java
/** * Hidden the series legend//from ww w . j a va 2s . c o m * * @param plotIndex * @param rangeAxisIndex */ public void hiddenSeriesLegend(int plotIndex, int rangeAxisIndex) { NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(rangeAxisIndex); numberAxis.setVisible(false); XYItemRenderer renderer = plot.getRenderer(plotIndex); renderer.setSeriesVisibleInLegend(0, false); }
From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java
private XYPlot createAvailableCapacityPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) { Map<MachineCapacity, List<Integer>> availableMap = new LinkedHashMap<MachineCapacity, List<Integer>>( solution.getMachineCapacityList().size()); for (MachineCapacity machineCapacity : solution.getMachineCapacityList()) { List<Integer> machineAvailableList = new ArrayList<Integer>(solution.getGlobalPeriodRangeTo()); for (int period = 0; period < solution.getGlobalPeriodRangeTo(); period++) { machineAvailableList.add(machineCapacity.getCapacity()); }// w w w. ja va 2s . c o m availableMap.put(machineCapacity, machineAvailableList); } for (TaskAssignment taskAssignment : solution.getTaskAssignmentList()) { Machine machine = taskAssignment.getMachine(); Integer startPeriod = taskAssignment.getStartPeriod(); if (machine != null && startPeriod != null) { Task task = taskAssignment.getTask(); List<TaskRequirement> taskRequirementList = task.getTaskRequirementList(); for (int i = 0; i < taskRequirementList.size(); i++) { TaskRequirement taskRequirement = taskRequirementList.get(i); MachineCapacity machineCapacity = machine.getMachineCapacityList().get(i); List<Integer> machineAvailableList = availableMap.get(machineCapacity); for (int j = 0; j < task.getDuration(); j++) { int period = j + taskAssignment.getStartPeriod(); int available = machineAvailableList.get(period); machineAvailableList.set(period, available - taskRequirement.getResourceUsage()); } } } } XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES); int seriesIndex = 0; for (Machine machine : solution.getMachineList()) { XYSeries machineSeries = new XYSeries(machine.getLabel()); for (MachineCapacity machineCapacity : machine.getMachineCapacityList()) { List<Integer> machineAvailableList = availableMap.get(machineCapacity); for (int period = 0; period < solution.getGlobalPeriodRangeTo(); period++) { int available = machineAvailableList.get(period); machineSeries.add(available, period); } } seriesCollection.addSeries(machineSeries); renderer.setSeriesPaint(seriesIndex, tangoColorFactory.pickColor(machine)); renderer.setSeriesShape(seriesIndex, ShapeUtilities.createDiamond(1.5F)); renderer.setSeriesVisibleInLegend(seriesIndex, false); seriesIndex++; } NumberAxis domainAxis = new NumberAxis("Capacity"); return new XYPlot(seriesCollection, domainAxis, null, renderer); }
From source file:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java
@Override public void addTimeSeries(List<TimeSeries> timeSeriesList, TimeSeriesType type) { final int timeSeriesCount; final int collectionOffset; if (TimeSeriesType.INSITU.equals(type)) { timeSeriesCount = displayAxisMapping.getInsituCount(); collectionOffset = INSITU_COLLECTION_INDEX_OFFSET; } else {//from w w w . j a v a 2 s . c o m timeSeriesCount = displayAxisMapping.getRasterCount(); if (TimeSeriesType.CURSOR.equals(type)) { collectionOffset = CURSOR_COLLECTION_INDEX_OFFSET; } else { collectionOffset = PIN_COLLECTION_INDEX_OFFSET; } } final String[] aliasNames = getAliasNames(); for (int aliasIdx = 0; aliasIdx < aliasNames.length; aliasIdx++) { final int targetCollectionIndex = collectionOffset + aliasIdx * 3; final TimeSeriesCollection targetTimeSeriesCollection = (TimeSeriesCollection) timeSeriesPlot .getDataset(targetCollectionIndex); if (targetTimeSeriesCollection != null) { targetTimeSeriesCollection.removeAllSeries(); } } if (timeSeriesCount == 0) { return; } final int numPositions = timeSeriesList.size() / timeSeriesCount; int timeSeriesIndexOffset = 0; for (int posIdx = 0; posIdx < numPositions; posIdx++) { final Shape posShape = getShapeForPosition(type, posIdx); for (int aliasIdx = 0; aliasIdx < aliasNames.length; aliasIdx++) { final int targetCollectionIndex = collectionOffset + aliasIdx * 3; final TimeSeriesCollection targetTimeSeriesCollection = (TimeSeriesCollection) timeSeriesPlot .getDataset(targetCollectionIndex); if (targetTimeSeriesCollection == null) { continue; } final XYItemRenderer renderer = timeSeriesPlot.getRenderer(targetCollectionIndex); final int dataSourceCount = getDataSourceCount(type, aliasNames[aliasIdx]); for (int ignoredIndex = 0; ignoredIndex < dataSourceCount; ignoredIndex++) { final TimeSeries currentTimeSeries = timeSeriesList.get(timeSeriesIndexOffset); targetTimeSeriesCollection.addSeries(currentTimeSeries); final int timeSeriesTargetIdx = targetTimeSeriesCollection.getSeriesCount() - 1; renderer.setSeriesShape(timeSeriesTargetIdx, posShape); renderer.setSeriesPaint(timeSeriesTargetIdx, renderer.getSeriesPaint(timeSeriesTargetIdx % dataSourceCount)); renderer.setSeriesVisibleInLegend(timeSeriesTargetIdx, !currentTimeSeries.isEmpty()); timeSeriesIndexOffset++; } final ValueAxis axisForDataset = timeSeriesPlot.getDomainAxisForDataset(targetCollectionIndex); axisForDataset.configure(); } } updateAnnotation(getCurrentView().getRaster()); }
From source file:no.met.jtimeseries.chart.ChartPlotter.java
/** * Add a line chart in the plot// w ww. ja va 2 s . c om * * @param timeBase * The base time of the data: second, minute, hour, year or auto * @param phenomenon * Phenomenon to plot. * @param plotStyle * The style preference for the plot * */ public void addLineChart(TimeBase timeBase, NumberPhenomenon ph, PlotStyle plotStyle) { NumberPhenomenon phenomenon = ph.clone(); if (phenomenon.getItems().size() > 0) { XYItemRenderer renderer = RendererFactory.createRenderer(SplineStyle.STANDARD); // if using hybrid spline if (plotStyle.getSplineStyle().equalsIgnoreCase(SplineStyle.HYBRID)) { phenomenon.doHybridSpline(0.5d, 4); renderer = RendererFactory.createRenderer(SplineStyle.NONE); } if (plotStyle.getNonNegative()) { phenomenon.removeNegativeValues(); } XYDataset dataset = phenomenon.getTimeSeries(plotStyle.getTitle(), timeBase); renderer.setSeriesPaint(0, plotStyle.getSeriesColor()); renderer.setSeriesStroke(0, plotStyle.getStroke()); // hidden the legend by default renderer.setSeriesVisibleInLegend(0, false); plot.setDataset(plotIndex, dataset); plot.setRenderer(plotIndex, renderer); // render the range axis NumberAxis numberAxis; // null check for number axis if (plotStyle.getNumberAxis() == null) { numberAxis = new NumberAxis(plotStyle.getTitle()); numberAxis.setAutoRangeIncludesZero(false); numberAxis.setLabelPaint(plotStyle.getLabelColor()); numberAxis.setTickLabelPaint(plotStyle.getLabelColor()); // ugly calculation double max = phenomenon.getMaxValue(); double min = phenomenon.getMinValue(); // increase and decrease max, min respectiivly to get the // difference pf atleast 50 while ((max - min) <= plotStyle.getDifference()) { max++; min--; } int tUnit = (int) ((max - min) / plotStyle.getTotalTicks()); if (tUnit <= 1) { tUnit = 2; } int[] range = calculateAxisMaxMin(phenomenon, tUnit, plotStyle.getTotalTicks()); NumberTickUnit ntu = new NumberTickUnit(tUnit); numberAxis.setTickUnit(ntu); numberAxis.setRangeWithMargins(range[1], range[0]); } else { numberAxis = plotStyle.getNumberAxis(); } plot.setRangeAxis(rangeAxisIndex, numberAxis); Date minDate = phenomenon.getStartTime(); Date maxDate = phenomenon.getEndTime(); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); domainAxis.setRange(minDate, maxDate); plot.mapDatasetToRangeAxis(plotIndex, rangeAxisIndex); plotIndex++; rangeAxisIndex++; } }
From source file:no.met.jtimeseries.chart.ChartPlotter.java
public void addThresholdLineChart(TimeBase timeBase, NumberPhenomenon ph, PlotStyle plotStyle) { NumberPhenomenon phenomenon = ph.clone(); if (phenomenon.getItems().size() > 0) { XYItemRenderer renderer = RendererFactory.createRenderer(SplineStyle.STANDARD); // if using hybrid if (plotStyle.getSplineStyle().equalsIgnoreCase(SplineStyle.HYBRID)) { phenomenon.doHybridSpline(0.5d, 4); renderer = RendererFactory.createRenderer(SplineStyle.NONE); }/*from ww w.j a v a 2s. c o m*/ if (plotStyle.getNonNegative()) { phenomenon.removeNegativeValues(); } // add threshold point into the dataset phenomenon.addThresholdPoints(plotStyle.getThreshold()); // create threshold data set with specified threshold value XYDataset dataset = phenomenon.getTimeSeriesWithThreshold(plotStyle.getTitle(), timeBase, plotStyle.getThreshold()); // render even series lines with color1 and odd series lines with // color2 for (int i = 0; i < dataset.getSeriesCount(); i++) { if (i % 2 == 0) renderer.setSeriesPaint(i, plotStyle.getPlusDegreeColor()); else renderer.setSeriesPaint(i, plotStyle.getMinusDegreeColor()); renderer.setSeriesStroke(i, plotStyle.getStroke()); // hidden legend renderer.setSeriesVisibleInLegend(i, false); } plot.setDataset(plotIndex, dataset); plot.setRenderer(plotIndex, renderer); NumberAxis numberAxis; // null check for number axis if (plotStyle.getNumberAxis() == null) { numberAxis = new NumberAxis(plotStyle.getTitle()); numberAxis.setAutoRangeIncludesZero(false); numberAxis.setLabelPaint(plotStyle.getLabelColor()); numberAxis.setTickLabelPaint(plotStyle.getLabelColor()); // ugly calculation double max = phenomenon.getMaxValue(); double min = phenomenon.getMinValue(); int tUnit = getTemperatureTicksUnit(max, min); int[] range = calculateAxisMaxMin(phenomenon, tUnit, plotStyle.getTotalTicks()); NumberTickUnit ntu = new NumberTickUnit(tUnit); numberAxis.setTickUnit(ntu); numberAxis.setLowerMargin(LOWER_PLOT_MARGIN); numberAxis.setRangeWithMargins(range[1], range[0]); } else { numberAxis = plotStyle.getNumberAxis(); } plot.setRangeAxis(rangeAxisIndex, numberAxis); Date minDate = phenomenon.getStartTime(); Date maxDate = phenomenon.getEndTime(); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); domainAxis.setRange(minDate, maxDate); plot.mapDatasetToRangeAxis(plotIndex, rangeAxisIndex); plotIndex++; rangeAxisIndex++; } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * Add the series//from w ww.j a v a2s.co m * * * @param series The data * @param lineState describes how to draw the line * @param paramIdx which parameter * @param renderer renderer * @param rangeVisible do we show range axis * @param addAxis include the axis * * @return the newly created range axis */ protected Axis addSeries(TimeSeries series, LineState lineState, int paramIdx, XYItemRenderer renderer, boolean rangeVisible, boolean addAxis) { if (series instanceof MyTimeSeries) { ((MyTimeSeries) series).finish(); } if (addAxis && (lineState.getRange() != null)) { addRange(lineState.getRange().getMin(), lineState.getRange().getMax(), "Fixed range from: " + lineState.getName()); } if (numberFormat == null) { numberFormat = new DecimalFormat() { public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) { String s = control.getDisplayConventions().format(number); result.append(s); return result; } }; } String name = lineState.getName(); Unit unit = lineState.unit; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.setDomainIsPointsInTime(true); dataset.addSeries(series); String axisLabel = lineState.getAxisLabel(); if (axisLabel == null) { axisLabel = name + ((unit != null) ? " [" + unit + "]" : ""); } NumberAxis rangeAxis; if (lineState.getUseLogarithmicRange() && false) { rangeAxis = new FixedWidthLogarithmicAxis(axisLabel); } else { rangeAxis = new FixedWidthNumberAxis(axisLabel); ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(lineState.getRangeIncludesZero()); } //For now lets use the default number formatting for the range // rangeAxis.setNumberFormatOverride(numberFormat); rangeAxis.setVisible(rangeVisible); ucar.unidata.util.Range r = lineState.getRange(); if (r != null) { rangeAxis.setRange(new org.jfree.data.Range(r.getMin(), r.getMax())); } if (renderer == null) { renderer = getRenderer(lineState, addAxis); } Paint c = lineState.getColor(paramIdx); rangeAxis.setLabelPaint(Color.black); renderer.setSeriesPaint(0, c); renderer.setSeriesStroke(0, lineState.getStroke()); renderer.setSeriesVisibleInLegend(0, lineState.getVisibleInLegend()); if (!lineState.getAxisVisible()) { rangeAxis.setVisible(false); } else { rangeAxis.setVisible(addAxis); } ChartHolder chartHolder = getChartHolder(lineState); AxisLocation side = null; if (rangeAxis.isVisible()) { if (lineState.getSide() == LineState.SIDE_UNDEFINED) { if (chartHolder.lastSide == AxisLocation.TOP_OR_LEFT) { side = AxisLocation.BOTTOM_OR_RIGHT; } else { side = AxisLocation.TOP_OR_LEFT; } } else if (lineState.getSide() == LineState.SIDE_LEFT) { side = AxisLocation.TOP_OR_LEFT; } else { side = AxisLocation.BOTTOM_OR_RIGHT; } chartHolder.lastSide = side; } synchronized (MUTEX) { chartHolder.add(dataset, rangeAxis, renderer, side); } return rangeAxis; }