List of usage examples for org.jfree.chart.plot Marker setAlpha
public void setAlpha(float alpha)
From source file:de.xirp.chart.ChartManager.java
/** * Sets some values on the given//from w w w. ja va 2 s . c o m * {@link org.jfree.chart.plot.XYPlot} corresponding to some * options of the {@link de.xirp.chart.ChartOptions} * field. <br> * <br> * If <code>options.is(OptionName.SHOW_THRESHOLD)</code> is * <code>true</code> a threshold line is painted to the chart * using the <code>threshold</code> field. <br> * <br> * If <code>options.is(OptionName.USE_RELATIVE)</code> is * <code>true</code> the date axis of the plot gets a title * indicating that relative values are used. If the flag is * <code>false</code> the plot gets a title indicating that * absolute values are used. * * @param plot * The plot to alter. * @param start * The start time. * @see de.xirp.chart.ChartOptions * @see org.jfree.chart.plot.XYPlot */ private static void setXYPlot(XYPlot plot, Date start) { plot.setNoDataMessage(NO_DATA_AVAILABLE); if (options.is(OptionName.SHOW_THRESHOLD)) { Marker marker = new ValueMarker(threshold); marker.setPaint(Color.orange); marker.setAlpha(0.8f); plot.addRangeMarker(marker); } if (options.is(OptionName.USE_RELATIVE)) { DateAxis axis = new DateAxis(I18n.getString("ChartManager.text.relativeTime")); //$NON-NLS-1$ RelativeDateFormat rdf = new RelativeDateFormat(start); axis.setDateFormatOverride(rdf); plot.setDomainAxis(axis); } else { plot.setDomainAxis(new DateAxis(I18n.getString("ChartManager.text.absoluteTime"))); //$NON-NLS-1$ } }
From source file:org.jfree.chart.demo.TimeSeriesDemo4.java
/** * A demonstration application showing a quarterly time series containing a null value. * * @param title the frame title./*from w w w .j a v a 2 s . c o m*/ */ public TimeSeriesDemo4(final String title) { super(title); final TimeSeries series = new TimeSeries("Random Data", Hour.class); final Day today = new Day(); series.add(new Hour(1, today), 500.2); series.add(new Hour(2, today), 694.1); series.add(new Hour(3, today), 734.4); series.add(new Hour(4, today), 453.2); series.add(new Hour(7, today), 500.2); series.add(new Hour(8, today), null); series.add(new Hour(12, today), 734.4); series.add(new Hour(16, today), 453.2); final TimeSeriesCollection dataset = new TimeSeriesCollection(series); // create a title with Unicode characters (currency symbols in this case)... final String chartTitle = "\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA"; final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Time", "Value", dataset, true, true, false); final XYPlot plot = chart.getXYPlot(); // plot.setInsets(new Insets(0, 0, 0, 20)); final Marker marker = new ValueMarker(700.0); marker.setPaint(Color.blue); marker.setAlpha(0.8f); plot.addRangeMarker(marker); plot.setBackgroundPaint(null); plot.setBackgroundImage(JFreeChart.INFO.getLogo()); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer r = (StandardXYItemRenderer) renderer; r.setPlotShapes(true); r.setShapesFilled(true); } final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); }
From source file:com.hmsinc.epicenter.webapp.remoting.ForecastingService.java
@Secured("ROLE_USER") @Transactional(readOnly = true)//from ww w. j a v a 2 s .c o m @RemoteMethod public String getSeasonalTrendChart(final AnalysisParametersDTO paramsDTO) { final AnalysisParameters params = convertParameters(paramsDTO); // 60 day window final DateTime windowStart = params.getEndDate().minusDays(59); // Set the start date back 1 year + 60 days params.setStartDate(windowStart.minusYears(1).minusDays(59)); final TimeSeriesChart chart = new TimeSeriesChart(); final TimeSeries ts = queryService.queryForTimeSeries(params, paramsDTO.getAlgorithmName(), null); if (ts != null) { final TimeSeries forecast = waveletSeasonalTrendForecaster.process(ts.after(windowStart), ts.before(windowStart.minusDays(1)), null); final TimeSeries known = forecast.before(params.getEndDate()); final TimeSeries predicted = forecast.after(params.getEndDate().plusDays(1)); chart.addBand("70% Confidence Prediction", predicted, ResultType.LOWER_BOUND_70, ResultType.UPPER_BOUND_70, new Color(0x0072bf), new Color(0x0072bf)); chart.addBand("80% Confidence Prediction", predicted, ResultType.LOWER_BOUND_80, ResultType.UPPER_BOUND_80, new Color(0x0099ff), new Color(0x0099ff)); chart.addBand("90% Confidence Prediction", predicted, ResultType.LOWER_BOUND_90, ResultType.UPPER_BOUND_90, new Color(0x3fb2ff), new Color(0x3fb2ff)); chart.addBand("95% Confidence Prediction", predicted, ResultType.LOWER_BOUND_95, ResultType.UPPER_BOUND_95, new Color(0xbfe5ff), new Color(0xbfe5ff)); chart.add("Actual Value", known, ChartColor.VALUE.getColor(), LineStyle.DOTTED); chart.add("Actual Trend", known, ResultType.TREND, ChartColor.VALUE.getColor(), LineStyle.THICK); final DateTime knownFirst = known.first().getTime(); final DateTime predictedFirst = predicted.first().getTime(); final Marker marker = new IntervalMarker( new Day(knownFirst.getDayOfMonth(), knownFirst.getMonthOfYear(), knownFirst.getYear()) .getFirstMillisecond(), new Day(predictedFirst.getDayOfMonth(), predictedFirst.getMonthOfYear(), predictedFirst.getYear()).getFirstMillisecond(), Color.LIGHT_GRAY, new BasicStroke(2.0f), null, null, 1.0f); marker.setAlpha(0.3f); chart.getMarkers().add(marker); chart.setYLabel(params.getDataRepresentation().getDisplayName()); chart.setAlwaysScaleFromZero(false); } return chartService.getChartURL(chart); }
From source file:org.jrecruiter.web.actions.admin.ShowStatisticsAction.java
public final String chartJobCount() throws Exception { final Calendar calendarToday = CalendarUtils.getCalendarWithoutTime(); final Calendar calendar30 = CalendarUtils.getCalendarWithoutTime(); calendar30.add(Calendar.MONTH, -36); final List<JobCountPerDay> jobCountPerDayList = jobService.getJobCountPerDayAndPeriod(calendar30.getTime(), calendarToday.getTime());//from www . j a v a 2s .c om final TimeSeries hitsPerDayData = new TimeSeries("Hits", Day.class); final XYDataset hitsPerDayDataset = new TimeSeriesCollection(hitsPerDayData); this.chart = ChartFactory.createTimeSeriesChart("", super.getText("class.ShowStatisticsAcion.chart.job.count.caption"), "", hitsPerDayDataset, false, true, false); final XYPlot xyplot = (XYPlot) this.chart.getPlot(); for (JobCountPerDay jobCountPerDay : jobCountPerDayList) { final Day day = new Day(jobCountPerDay.getJobDate()); if (jobCountPerDay.getAutomaticallyCleaned()) { final Marker originalEnd = new ValueMarker(day.getFirstMillisecond()); originalEnd.setPaint(new Color(0, 80, 138, 150)); float[] dashPattern = { 6, 2 }; originalEnd.setStroke( new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, dashPattern, 0)); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); originalEnd.setLabel("C"); originalEnd.setAlpha(0.1F); xyplot.addDomainMarker(originalEnd); } hitsPerDayData.add(day, jobCountPerDay.getTotalNumberOfJobs()); } chart.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setDomainGridlinePaint(Color.LIGHT_GRAY); xyplot.setBackgroundPaint(new Color(255, 255, 255, 0)); xyplot.setRangeGridlinePaint(Color.LIGHT_GRAY); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(false); xyitemrenderer.setSeriesPaint(0, new Color(244, 66, 0)); } DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setAutoRange(true); dateaxis.setAutoTickUnitSelection(true); NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis(); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return SUCCESS; }
From source file:ch.algotrader.client.chart.ChartTab.java
@SuppressWarnings("unchecked") public void updateData(ChartDataVO chartData) { resetAxis();/*from w ww. j av a 2 s .co m*/ // add/update indicators for (IndicatorVO indicator : chartData.getIndicators()) { RegularTimePeriod timePeriod = getRegularTimePeriod(indicator.getDateTime()); TimeSeries series = this.indicators.get(indicator.getName()); if (series != null) { series.addOrUpdate(timePeriod, indicator.getValue()); } } // add/update bars for (BarVO bar : chartData.getBars()) { OHLCSeries series = this.bars.get(bar.getSecurityId()); if (series != null) { // remove a value if it already exists RegularTimePeriod timePeriod = getRegularTimePeriod(bar.getDateTime()); if (series.indexOf(timePeriod) >= 0) { series.remove(timePeriod); } series.add(timePeriod, bar.getOpen().doubleValue(), bar.getHigh().doubleValue(), bar.getLow().doubleValue(), bar.getClose().doubleValue()); } } // make all invisible since they might not currently have a value for (Marker marker : this.markers.values()) { marker.setAlpha(0); } // update markers for (MarkerVO markerVO : chartData.getMarkers()) { Marker marker = this.markers.get(markerVO.getName()); Boolean selected = this.markersSelectionStatus.get(markerVO.getName()); String name = marker.getLabel().split(":")[0]; if (marker instanceof ValueMarker && markerVO instanceof ValueMarkerVO) { ValueMarker valueMarker = (ValueMarker) marker; ValueMarkerVO valueMarkerVO = (ValueMarkerVO) markerVO; valueMarker.setValue(valueMarkerVO.getValue()); marker.setLabel(name + ": " + valueMarkerVO.getValue()); marker.setAlpha(selected ? 1.0f : 0.0f); } else if (marker instanceof IntervalMarker && markerVO instanceof IntervalMarkerVO) { IntervalMarker intervalMarker = (IntervalMarker) marker; IntervalMarkerVO intervalMarkerVO = (IntervalMarkerVO) markerVO; intervalMarker.setStartValue(intervalMarkerVO.getStartValue()); intervalMarker.setEndValue(intervalMarkerVO.getEndValue()); marker.setLabel( name + ": " + intervalMarkerVO.getStartValue() + " - " + intervalMarkerVO.getEndValue()); marker.setAlpha(selected ? 0.5f : 0.0f); } else { throw new RuntimeException(marker.getClass() + " does not match " + markerVO.getClass()); } } // update annotations for (AnnotationVO annotationVO : chartData.getAnnotations()) { AbstractXYAnnotation annotation; if (annotationVO instanceof PointerAnnotationVO) { PointerAnnotationVO pointerAnnotationVO = (PointerAnnotationVO) annotationVO; XYPointerAnnotation pointerAnnotation = new XYPointerAnnotation(pointerAnnotationVO.getText(), pointerAnnotationVO.getDateTime().getTime(), pointerAnnotationVO.getValue(), 3.926990816987241D); pointerAnnotation.setTipRadius(0); pointerAnnotation.setBaseRadius(20); pointerAnnotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT); pointerAnnotation.setFont(new Font("SansSerif", 0, 9)); pointerAnnotation.setToolTipText("<html>" + formatter.format(pointerAnnotationVO.getDateTime()) + "<br>" + pointerAnnotationVO.getValue() + "</html>"); annotation = pointerAnnotation; } else if (annotationVO instanceof BoxAnnotationVO) { BoxAnnotationVO boxAnnotationVO = (BoxAnnotationVO) annotationVO; XYBoxAnnotation boxAnnotation = new XYBoxAnnotation(boxAnnotationVO.getStartDateTime().getTime(), boxAnnotationVO.getStartValue(), boxAnnotationVO.getEndDateTime().getTime(), boxAnnotationVO.getEndValue(), null, null, new java.awt.Color(0, 0, 0, 60)); boxAnnotation.setToolTipText("<html>" + formatter.format(boxAnnotationVO.getStartDateTime()) + " - " + formatter.format(boxAnnotationVO.getEndDateTime()) + "<br>" + boxAnnotationVO.getStartValue() + " - " + boxAnnotationVO.getEndValue() + "</html>"); annotation = boxAnnotation; } else { throw new RuntimeException("unkown annotation type" + annotationVO.getClass()); } if (!getPlot().getAnnotations().contains(annotation)) { getPlot().addAnnotation(annotation); } } // update description for (Title title : (List<Title>) this.getChart().getSubtitles()) { if (title instanceof TextTitle) { TextTitle textTitle = ((TextTitle) title); if (chartData.getDescription() != null && !("".equals(chartData.getDescription()))) { textTitle.setText(chartData.getDescription()); textTitle.setVisible(true); } else { textTitle.setVisible(false); } } } initAxis(); }
From source file:net.sf.jasperreports.customizers.marker.AbstractMarkerCustomizer.java
protected void configureMarker(Marker marker) { String label = getProperty(PROPERTY_LABEL); if (label != null && label.length() > 0) { marker.setLabel(label);/*ww w . ja va2s.c o m*/ } RectangleAnchorEnum labelAnchor = RectangleAnchorEnum.getByName(getProperty(PROPERTY_LABEL_ANCHOR)); if (labelAnchor != null) { marker.setLabelAnchor(labelAnchor.getRectangleAnchor()); } Double offsetTop = getDoubleProperty(PROPERTY_LABEL_OFFSET_TOP); Double offsetLeft = getDoubleProperty(PROPERTY_LABEL_OFFSET_LEFT); Double offsetBottom = getDoubleProperty(PROPERTY_LABEL_OFFSET_BOTTOM); Double offsetRight = getDoubleProperty(PROPERTY_LABEL_OFFSET_RIGHT); if (offsetTop != null || offsetLeft != null || offsetBottom != null || offsetRight != null) { RectangleInsets currentOffset = marker.getLabelOffset(); marker.setLabelOffset(new RectangleInsets(offsetTop == null ? currentOffset.getTop() : offsetTop, offsetLeft == null ? currentOffset.getLeft() : offsetLeft, offsetBottom == null ? currentOffset.getBottom() : offsetBottom, offsetRight == null ? currentOffset.getRight() : offsetRight)); } TextAnchorEnum labelTextAnchor = TextAnchorEnum.getByName(getProperty(PROPERTY_LABEL_TEXT_ANCHOR)); if (labelTextAnchor != null) { marker.setLabelTextAnchor(labelTextAnchor.getTextAnchor()); } Color color = JRColorUtil.getColor(getProperty(PROPERTY_COLOR), null); if (color != null) { marker.setPaint(color); } Float alpha = getFloatProperty(PROPERTY_ALPHA); if (alpha != null) { marker.setAlpha(alpha); } }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initMarker(SeriesDefinitionVO seriesDefinition) { final MarkerDefinitionVO markerDefinition = (MarkerDefinitionVO) seriesDefinition; final Marker marker; if (markerDefinition.isInterval()) { marker = new IntervalMarker(0, 0); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); // position of the label marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); // position of the text within the label } else {//from ww w. j av a 2 s . c o m marker = new ValueMarker(0); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } marker.setPaint(getColor(markerDefinition.getColor())); marker.setLabel(markerDefinition.getLabel()); marker.setLabelFont(new Font("SansSerif", 0, 9)); if (seriesDefinition.isDashed()) { marker.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f)); } else { marker.setStroke(new BasicStroke(1.0f)); } getPlot().addRangeMarker(marker, markerDefinition.isInterval() ? Layer.BACKGROUND : Layer.FOREGROUND); this.markers.put(markerDefinition.getName(), marker); this.markersSelectionStatus.put(markerDefinition.getName(), seriesDefinition.isSelected()); // add the menu item JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel()); menuItem.setSelected(seriesDefinition.isSelected()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetAxis(); boolean selected = ((JCheckBoxMenuItem) e.getSource()).isSelected(); ChartTab.this.markersSelectionStatus.put(markerDefinition.getName(), selected); if (selected) { if (marker instanceof ValueMarker) { marker.setAlpha(1.0f); } else { marker.setAlpha(0.5f); } } else { marker.setAlpha(0); } initAxis(); } }); this.getPopupMenu().add(menuItem); }