List of usage examples for org.jfree.chart.axis ValueAxis setAxisLinePaint
public void setAxisLinePaint(Paint paint)
From source file:eu.kprod.gui.chart.MwChartFactory.java
public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) { final JFreeChart chart; chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true); chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); chart.setBorderVisible(false);// w w w . j a va 2s . c om final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS")); axis.setAxisLineVisible(false); axis.setTickLabelsVisible(false); axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // force integer display final ValueAxis va = plot.getRangeAxis(); va.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // va.setRange(-280,280); // va.setFixedAutoRange(560); // va.setLowerBound(-280); // va.setUpperBound(280); // va.setAutoRange(false); va.setRangeWithMargins(-280, 280); final MwChartPanel chartPanel = new MwChartPanel(chart, conf); chartPanel.setMouseWheelEnabled(false); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); return chartPanel; }
From source file:org.multiwii.swingui.gui.chart.MwChartFactory.java
public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) { final JFreeChart chart; chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true); chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); chart.setBorderVisible(false);// w w w . jav a2 s.c o m final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS")); axis.setAxisLineVisible(false); axis.setTickLabelsVisible(false); axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // force integer display final ValueAxis va = plot.getRangeAxis(); va.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // va.setRange(-280,280); // va.setFixedAutoRange(560); // va.setLowerBound(-280); // va.setUpperBound(280); // va.setAutoRange(false); va.setRangeWithMargins(-280, 280); final MwChartPanel chartPanel = new MwChartPanel(chart, conf); chartPanel.setMouseWheelEnabled(false); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); return chartPanel; }
From source file:imageviewer.tools.HistogramTool.java
public void plot(MouseEvent e) { if (e.getSource() instanceof ImagePanel) { Image image = ((ImagePanel) e.getSource()).getSource(); Histogram h = image.getHistogram(); SimpleHistogramDataset shd = new SimpleHistogramDataset("Voxel distribution"); for (int i = 0, numBands = h.getNumBands(); i < numBands; i++) { int[] binData = h.getBins(i); for (int j = 0; j < binData.length; j++) { SimpleHistogramBin shb = new SimpleHistogramBin(j - 0.5, j + 0.5, true, false); shb.setItemCount(binData[j]); shd.addBin(shb);//w w w . j a va2 s. c o m } } double[] domainBounds = null, rangeBounds = null; if (chart != null) { ValueAxis va = chart.getXYPlot().getDomainAxis(); domainBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; va = chart.getXYPlot().getRangeAxis(); rangeBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; } chart = ChartFactory.createHistogram(null, "Voxel value", "Count", shd, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(new Color(20, 30, 45)); chart.setAntiAlias(true); ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); domainAxis.setLabelFont(axisFont); domainAxis.setTickLabelFont(tickFont); domainAxis.setAxisLinePaint(Color.white); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); if (domainBounds != null) { domainAxis.setAutoRange(false); domainAxis.setLowerBound(domainBounds[0]); domainAxis.setUpperBound(domainBounds[1]); } else { domainAxis.setLowerBound(0); } ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); rangeAxis.setLabelFont(axisFont); rangeAxis.setTickLabelFont(tickFont); rangeAxis.setAxisLinePaint(Color.white); rangeAxis.setTickLabelPaint(Color.white); rangeAxis.setLabelPaint(Color.white); if (rangeBounds != null) { rangeAxis.setAutoRange(false); rangeAxis.setLowerBound(rangeBounds[0]); rangeAxis.setUpperBound(rangeBounds[1]); } chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(0, 51, 113)); ((XYBarRenderer) chart.getXYPlot().getRenderer()).setDrawBarOutline(false); chart.getXYPlot().setBackgroundAlpha(0.05f); double[] mean = h.getMean(); double[] sd = h.getStandardDeviation(); IntervalMarker im = new IntervalMarker(mean[0] - sd[0] / 2, mean[0] + sd[0] / 2); im.setPaint(new Color(200, 200, 200, 128)); chart.getXYPlot().addDomainMarker(0, im, Layer.BACKGROUND); cp.setChart(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 . j av a 2 s . c o m 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(); }//w w w .j a v a2 s .c o m 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:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java
private void axisLineColorChanged(Color lineColor) { JFreeChart chart = getCurrentChart(); if (chart != null) { Plot plot = chart.getPlot();//from w w w .j a v a 2 s .c o m if (plot instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) plot; ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(), categoryPlot.getDomainAxis()); int rangeAxisCount = categoryPlot.getRangeAxisCount(); for (int i = 0; i < rangeAxisCount; ++i) { ValueAxis valueAxis = categoryPlot.getRangeAxis(i); if (valueAxis != null) { ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(), valueAxis); } } } else if (plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(), xyPlot.getDomainAxis()); int rangeAxisCount = xyPlot.getRangeAxisCount(); for (int i = 0; i < rangeAxisCount; ++i) { ValueAxis valueAxis = xyPlot.getRangeAxis(i); valueAxis.setAxisLinePaint(lineColor); if (valueAxis != null) { ChartAxisFactory.formatAxis(plotInstance.getCurrentPlotConfigurationClone(), valueAxis); } } } } }
From source file:jhplot.HChart.java
/** * Update the chart//from w ww. j a v a2 s . co m * * @param N1 * location in X * @param N2 * location in Y */ public void update(int N1, int N2) { if (cdatPie[N1][N2] != null || cdatPie3D[N1][N2] != null || cdatBar[N1][N2] != null || cdatBar3D[N1][N2] != null || cdatLine[N1][N2] != null || cdatArea[N1][N2] != null || cdatPolar[N1][N2] != null) { if (cdatPie[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart(title[N1][N2], (PieDataset) cdatPie[N1][N2], true, true, true); } else if (cdatPie3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart3D(title[N1][N2], (PieDataset) cdatPie3D[N1][N2], true, true, true); PiePlot3D pieplot3d = (PiePlot3D) chart[N1][N2].getPlot(); // pieplot3d.setStartAngle(290D); // pieplot3d.setDirection(Rotation.CLOCKWISE); // pieplot3d.setForegroundAlpha(0.5F); pieplot3d.setBackgroundPaint(DEFAULT_BG_COLOR); } else if (cdatBar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } else if (cdatBar3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart3D(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar3D[N1][N2], PlotOrientation.VERTICAL, true, true, true); } else if (cdatLine[N1][N2] != null) { chart[N1][N2] = ChartFactory.createLineChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatLine[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); lineplot.setOutlineStroke(new BasicStroke(axisPenwidth)); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); LineAndShapeRenderer renderer = (LineAndShapeRenderer) lineplot.getRenderer(); renderer.setBaseStroke(new BasicStroke(linestroke)); for (int m = 0; m < cdatLine[N1][N2].getColumnCount() + 1; m++) renderer.setSeriesStroke(m, new BasicStroke(linestroke)); } else if (cdatPolar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPolarChart(title[N1][N2], (XYSeriesCollection) cdatPolar[N1][N2], true, true, true); PolarPlot lineplot = (PolarPlot) chart[N1][N2].getPlot(); ValueAxis yy = lineplot.getAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); } else if (cdatArea[N1][N2] != null) { chart[N1][N2] = ChartFactory.createAreaChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatArea[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); return; } for (int i = 0; i < indexdat[N1][N2]; i++) { if (type[N1][N2].get(i) == "array") xyplot[N1][N2].setRenderer(i, (StandardXYItemRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "f") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "h") xyplot[N1][N2].setRenderer(i, (XYBarRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "p") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "pe") xyplot[N1][N2].setRenderer(i, (XYErrorRenderer) (rdat[N1][N2].get(i))); // System.out.println(i); } chart[N1][N2] = new JFreeChart(title[N1][N2], JFreeChart.DEFAULT_TITLE_FONT, xyplot[N1][N2], true); chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); }