List of usage examples for org.jfree.chart.plot XYPlot setBackgroundPaint
public void setBackgroundPaint(Paint paint)
From source file:com.kodemore.freechart.KmSimpleLineChart.java
private JFreeChart createChart(XYDataset dataset) { PlotOrientation orientation = PlotOrientation.VERTICAL; boolean showsTooltips = false; boolean showsUrls = false; JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), getAxisTitleX(), getAxisTitleY(), dataset, orientation, getShowsLegend(), showsTooltips, showsUrls); if (hasBackgroundColor()) chart.setBackgroundPaint(getBackgroundColor()); XYPlot plot; plot = chart.getXYPlot();/*www .ja va 2 s . c om*/ if (hasPlotBackgroundColor()) plot.setBackgroundPaint(getPlotBackgroundColor()); if (hasPlotGridLineColor()) { Color color = getPlotGridLineColor(); plot.setDomainGridlinePaint(color); plot.setRangeGridlinePaint(color); } XYLineAndShapeRenderer renderer; renderer = new XYLineAndShapeRenderer(); KmList<KmSimpleLineChartGroup> groups = getGroups(); int n = groups.size(); for (int i = 0; i < n; i++) { KmSimpleLineChartGroup group = groups.getAt(i); renderer.setSeriesLinesVisible(i, group.getShowsLines()); renderer.setSeriesShapesVisible(i, group.getShowsShapes()); } plot.setRenderer(renderer); if (getIntegerUnitsX()) { NumberAxis rangeAxis; rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } if (getIntegerUnitsY()) { NumberAxis rangeAxis; rangeAxis = (NumberAxis) plot.getDomainAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } return chart; }
From source file:net.sourceforge.subsonic.controller.StatusChartController.java
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); int index = Integer.parseInt(request.getParameter("index")); List<TransferStatus> statuses = Collections.emptyList(); if ("stream".equals(type)) { statuses = statusService.getAllStreamStatuses(); } else if ("download".equals(type)) { statuses = statusService.getAllDownloadStatuses(); } else if ("upload".equals(type)) { statuses = statusService.getAllUploadStatuses(); }/* w w w. ja v a 2 s . c om*/ if (index < 0 || index >= statuses.size()) { return null; } TransferStatus status = statuses.get(index); TimeSeries series = new TimeSeries("Kbps", Millisecond.class); TransferStatus.SampleHistory history = status.getHistory(); long to = System.currentTimeMillis(); long from = to - status.getHistoryLengthMillis(); Range range = new DateRange(from, to); if (!history.isEmpty()) { TransferStatus.Sample previous = history.get(0); for (int i = 1; i < history.size(); i++) { TransferStatus.Sample sample = history.get(i); long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp(); long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered()); double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0); series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps); previous = sample; } } // Compute moving average. series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000); // Find min and max values. double min = 100; double max = 250; for (Object obj : series.getItems()) { TimeSeriesDataItem item = (TimeSeriesDataItem) obj; double value = item.getValue().doubleValue(); if (item.getPeriod().getFirstMillisecond() > from) { min = Math.min(min, value); max = Math.max(max, value); } } // Add 10% to max value. max *= 1.1D; // Subtract 10% from min value. min *= 0.9D; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white); plot.setBackgroundPaint(background); XYItemRenderer renderer = plot.getRendererForDataset(dataset); renderer.setSeriesPaint(0, Color.blue.darker()); renderer.setSeriesStroke(0, new BasicStroke(2f)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setRange(range); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(new Range(min, max)); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT); return null; }
From source file:org.madsonic.controller.StatusChartController.java
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); int index = Integer.parseInt(request.getParameter("index")); List<TransferStatus> statuses = Collections.emptyList(); if ("stream".equals(type)) { statuses = statusService.getAllStreamStatuses(); } else if ("download".equals(type)) { statuses = statusService.getAllDownloadStatuses(); } else if ("upload".equals(type)) { statuses = statusService.getAllUploadStatuses(); }//from ww w.j av a 2 s . c om if (index < 0 || index >= statuses.size()) { return null; } TransferStatus status = statuses.get(index); TimeSeries series = new TimeSeries("Kbps", Millisecond.class); TransferStatus.SampleHistory history = status.getHistory(); long to = System.currentTimeMillis(); long from = to - status.getHistoryLengthMillis(); Range range = new DateRange(from, to); if (!history.isEmpty()) { TransferStatus.Sample previous = history.get(0); for (int i = 1; i < history.size(); i++) { TransferStatus.Sample sample = history.get(i); long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp(); long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered()); double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0); series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps); previous = sample; } } // Compute moving average. series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000); // Find min and max values. double min = 100; double max = 250; for (Object obj : series.getItems()) { TimeSeriesDataItem item = (TimeSeriesDataItem) obj; double value = item.getValue().doubleValue(); if (item.getPeriod().getFirstMillisecond() > from) { min = Math.min(min, value); max = Math.max(max, value); } } // Add 10% to max value. max *= 1.1D; // Subtract 10% from min value. min *= 0.9D; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white); plot.setBackgroundPaint(background); XYItemRenderer renderer = plot.getRendererForDataset(dataset); renderer.setSeriesPaint(0, Color.gray.darker()); renderer.setSeriesStroke(0, new BasicStroke(2f)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setRange(range); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(new Range(min, max)); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT); return null; }
From source file:net.vanosten.dings.swing.SummaryView.java
public void displayTimeSeriesChart(final TimeSeriesCollection averageScore, final int maxScoreRange, final TimeSeriesCollection numberOfEntries, final int maxTotalRange) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time Series", "Date", "Average Score", averageScore, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setPaint(Color.blue); //axis 1// ww w . ja va 2 s . c o m final NumberAxis axis1 = new NumberAxis("Average Score"); axis1.setLabelPaint(Color.blue); axis1.setTickLabelPaint(Color.blue); axis1.setRange(0.0d, maxScoreRange + 1); plot.setRangeAxis(0, axis1); //axis 2 final NumberAxis axis2 = new NumberAxis("Number of Entries"); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); axis2.setRange(0.0d, 10 * (((int) (maxTotalRange / 10)) + 1)); plot.setRangeAxis(1, axis2); plot.setDataset(1, numberOfEntries); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setPaint(Color.red); plot.setRenderer(1, renderer2); placeChart(chart); }
From source file:org.jstockchart.plot.TimeseriesPlot.java
private XYPlot createPricePlot() { Font axisFont = new Font("Arial", 0, 12); Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); PriceArea priceArea = timeseriesArea.getPriceArea(); Color averageColor = new Color(243, 182, 117); priceArea.setAverageColor(averageColor); priceArea.setPriceColor(Color.BLUE); TimeSeriesCollection priceDataset = new TimeSeriesCollection(); priceDataset.addSeries(dataset.getPriceTimeSeries().getTimeSeries()); if (priceArea.isAverageVisible()) { priceDataset.addSeries(dataset.getAverageTimeSeries().getTimeSeries()); }/*from w w w. ja va 2 s . c om*/ CentralValueAxis logicPriceAxis = priceArea.getLogicPriceAxis(); logicPriceAxis.setTickCount(7); CFXNumberAxis priceAxis = new CFXNumberAxis(logicPriceAxis.getLogicTicks()); priceAxis.setShowUD(true); priceAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); priceAxis.setTickMarksVisible(false); XYLineAndShapeRenderer priceRenderer = new XYLineAndShapeRenderer(true, false); priceAxis.setUpperBound(logicPriceAxis.getUpperBound()); priceAxis.setLowerBound(logicPriceAxis.getLowerBound()); priceAxis.setAxisLineVisible(false); priceAxis.setTickLabelFont(axisFont); priceRenderer.setSeriesPaint(0, priceArea.getPriceColor()); priceRenderer.setSeriesPaint(1, priceArea.getAverageColor()); CFXNumberAxis rateAxis = new CFXNumberAxis(logicPriceAxis.getRatelogicTicks()); rateAxis.setShowUD(true); rateAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); rateAxis.setTickMarksVisible(false); ; rateAxis.setTickLabelFont(axisFont); rateAxis.setAxisLineVisible(false); rateAxis.setUpperBound(logicPriceAxis.getUpperBound()); rateAxis.setLowerBound(logicPriceAxis.getLowerBound()); XYPlot plot = new XYPlot(priceDataset, null, priceAxis, priceRenderer); plot.setBackgroundPaint(priceArea.getBackgroudColor()); plot.setOrientation(priceArea.getOrientation()); plot.setRangeAxisLocation(priceArea.getPriceAxisLocation()); plot.setRangeMinorGridlinesVisible(false); Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 2.0f, 2.0f }, 1.0f); plot.setRangeGridlineStroke(gridLineStroke); plot.setDomainGridlineStroke(gridLineStroke); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setOutlineVisible(true); plot.setOutlineStroke(outLineStroke); plot.setOutlinePaint(Color.BLACK); if (priceArea.isRateVisible()) { plot.setRangeAxis(1, rateAxis); plot.setRangeAxisLocation(1, priceArea.getRateAxisLocation()); plot.setDataset(1, null); plot.mapDatasetToRangeAxis(1, 1); } if (priceArea.isMarkCentralValue()) { Number centralPrice = logicPriceAxis.getCentralValue(); if (centralPrice != null) { plot.addRangeMarker(new ValueMarker(centralPrice.doubleValue(), priceArea.getCentralPriceColor(), new BasicStroke())); } } return plot; }
From source file:ec.ui.view.DistributionView.java
@Override protected void onColorSchemeChange() { XYPlot plot = chartPanel.getChart().getXYPlot(); plot.setBackgroundPaint(themeSupport.getPlotColor()); plot.setDomainGridlinePaint(themeSupport.getGridColor()); plot.setRangeGridlinePaint(themeSupport.getGridColor()); chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor()); plot.getRenderer(HISTOGRAM_INDEX).setBasePaint(themeSupport.getAreaColor(HISTOGRAM_COLOR)); plot.getRenderer(HISTOGRAM_INDEX).setBaseOutlinePaint(themeSupport.getLineColor(HISTOGRAM_COLOR)); plot.getRenderer(DISTRIBUTION_INDEX).setBasePaint(themeSupport.getLineColor(DISTRIBUTION_COLOR)); }
From source file:com.haskins.cloudtrailviewer.feature.MetricsFeature.java
private void showChart(String service) { final TimeSeriesCollection chartData = generateTimeSeriesData(service); JFreeChart chart = ChartFactory.createTimeSeriesChart(service, "Time", "Calls", chartData, false, true, false);//from w ww .j a v a 2 s .c om // draw outter line XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer(); lineAndShapeRenderer.setPaint(new Color(64, 168, 228, 75)); lineAndShapeRenderer.setSeriesShape(0, new Ellipse2D.Double(-3, -3, 6, 6)); lineAndShapeRenderer.setSeriesShapesFilled(0, true); lineAndShapeRenderer.setSeriesShapesVisible(0, true); lineAndShapeRenderer.setUseOutlinePaint(true); lineAndShapeRenderer.setUseFillPaint(true); // draw filled area XYAreaRenderer renderer = new XYAreaRenderer(); renderer.setPaint(new Color(64, 168, 228, 50)); // configure Plot final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlineVisible(false); plot.setDataset(0, chartData); plot.setDataset(1, chartData); plot.setRenderer(0, lineAndShapeRenderer); plot.setRenderer(1, renderer); plot.getDomainAxis().setLowerMargin(0); plot.getDomainAxis().setUpperMargin(0); // format chart title TextTitle t = chart.getTitle(); t.setFont(new Font("Arial", Font.BOLD, 14)); // Cross Hairs xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); xCrosshair.setLabelGenerator(new DateTimeCrosshairLabelGenerator()); CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); crosshairOverlay.addDomainCrosshair(xCrosshair); // Create the panel chartPanel = new ChartPanel(chart); chartPanel.setMinimumDrawWidth(0); chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMinimumDrawHeight(0); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); chartPanel.setMouseZoomable(true, false); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(false); chartPanel.addChartMouseListener(this); chartPanel.addOverlay(crosshairOverlay); // update the display chartCards.removeAll(); chartCards.add(chartPanel, ""); chartCards.revalidate(); }
From source file:be.nbb.demetra.dfm.output.FactorChart.java
@Override protected void onColorSchemeChange() { XYPlot plot = chartPanel.getChart().getXYPlot(); plot.setBackgroundPaint(themeSupport.getPlotColor()); plot.setDomainGridlinePaint(themeSupport.getGridColor()); plot.setRangeGridlinePaint(themeSupport.getGridColor()); chartPanel.getChart().setBackgroundPaint(themeSupport.getBackColor()); XYLineAndShapeRenderer factor = (XYLineAndShapeRenderer) plot.getRenderer(FACTOR_INDEX); factor.setBasePaint(themeSupport.getLineColor(FACTOR_COLOR)); XYLineAndShapeRenderer filtered = (XYLineAndShapeRenderer) plot.getRenderer(FILTERED_INDEX); filtered.setBasePaint(themeSupport.getLineColor(FILTERED_COLOR)); XYDifferenceRenderer difference = ((XYDifferenceRenderer) plot.getRenderer(DIFFERENCE_INDEX)); Color diffArea = SwingColorSchemeSupport.withAlpha(themeSupport.getAreaColor(DIFFERENCE_COLOR), 150); difference.setPositivePaint(diffArea); difference.setNegativePaint(diffArea); difference.setBasePaint(themeSupport.getLineColor(DIFFERENCE_COLOR)); }
From source file:org.ietr.preesm.mapper.ui.BestCostPlotter.java
/** * Creates a chart./* w w w. j a v a 2 s. co m*/ * * @return A chart. */ private JFreeChart createChart(String title) { final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.datasets = new TimeSeriesCollection[subplotCount]; for (int i = 0; i < subplotCount; i++) { this.lastValue[i] = 100.0; final TimeSeries series = new TimeSeries("Real Time", Millisecond.class); this.datasets[i] = new TimeSeriesCollection(series); final NumberAxis rangeAxis = new NumberAxis("Schedule"); rangeAxis.setAutoRangeIncludesZero(false); final XYPlot subplot = new XYPlot(this.datasets[i], null, rangeAxis, new XYLineAndShapeRenderer()); subplot.setBackgroundPaint(Color.white); subplot.setDomainGridlinePaint(Color.lightGray); subplot.setRangeGridlinePaint(Color.lightGray); plot.add(subplot); } final JFreeChart chart = new JFreeChart(title, plot); chart.removeLegend(); // chart.getLegend().setPosition(RectangleEdge.BOTTOM); chart.setBorderPaint(Color.lightGray); chart.setBorderVisible(true); Paint p = GanttPlotter.getBackgroundColorGradient(); chart.setBackgroundPaint(p); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.black); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); return chart; }
From source file:Applet.EmbeddedChart.java
/** * Creates a chart.//from ww w. j a v a 2 s . c o m * * @param dataset * the data for the chart. * * @return a chart. */ private JFreeChart createChart(final XYDataset dataset, String title, boolean gofr) { // create the chart... final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart // title "Radial Distance, r/\u03c3", // x axis label title, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); chart.getLegend().setPosition(RectangleEdge.RIGHT); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYTitleAnnotation xyta = new XYTitleAnnotation(0.98, 0.98, chart.getLegend(), RectangleAnchor.TOP_RIGHT); chart.removeLegend(); plot.addAnnotation(xyta); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); for (int i = 0; i < 2; i++) { renderer.setSeriesPaint(i * 6 + 0, new Color(255, 0, 0)); renderer.setSeriesPaint(i * 6 + 1, new Color(0, 0, 255)); renderer.setSeriesPaint(i * 6 + 2, new Color(0, 139, 0)); renderer.setSeriesPaint(i * 6 + 3, new Color(255, 165, 0)); renderer.setSeriesPaint(i * 6 + 4, new Color(255, 0, 255)); renderer.setSeriesPaint(i * 6 + 5, new Color(0, 0, 0)); renderer.setSeriesStroke(i * 6 + 0, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 1, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 50.0f, 2.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 2, new BasicStroke(1.3f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_MITER, 10.0f, new float[] { 30.0f, 1.0f, 1.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 3, new BasicStroke(1.3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, new float[] { 1.0f, 3.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 4, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 1.0f, 2.0f, 3.0f, 4.0f }, 0.0f)); renderer.setSeriesStroke(i * 6 + 5, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f, 1.0f, 20.0f, 1.0f }, 0.0f)); } plot.setRenderer(renderer); return chart; }