List of usage examples for org.jfree.chart.axis ValueAxis setRange
public void setRange(Range range)
From source file:com.jaxzin.iraf.demo.Main.java
private static void customizeChart(JFreeChart chart) { // Set the transparency of the histogram bars chart.getXYPlot().setForegroundAlpha(0.5f); // Lock the y-axis to 0.0->0.5 ValueAxis axis = new NumberAxis("Probability"); axis.setAutoRange(false);/* w ww. j a va 2s .com*/ axis.setRange(new Range(0, 0.5)); chart.getXYPlot().setRangeAxis(axis); // Lock the x-axis to -6.0->6.0 ValueAxis domainAxis = new NumberAxis("Value"); domainAxis.setAutoRange(false); domainAxis.setRange(new Range(-6.0, 6.0)); chart.getXYPlot().setDomainAxis(domainAxis); }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Zoom into a chart panel//from w w w. ja v a 2 s .c om * * @param myChart * @param zoom * @param autoRangeY if true the range (Y) axis auto bounds will be restored */ public static void setZoomAxis(ValueAxis axis, Range zoom) { axis.setRange(zoom); }
From source file:org.shredzone.bullshitcharts.chart.BarChartGenerator.java
@Override public Plot generate() { LineDatasetCreator dataset = new LineDatasetCreator(); dataset.setTendency(getTendency());/*ww w .j av a2 s . c o m*/ dataset.setNumberOfValues(getResolution()); dataset.setAmplitude(getAmplitude()); CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n catAxis.setLowerMargin(0.0d); catAxis.setUpperMargin(0.0d); catAxis.setTickMarksVisible(false); catAxis.setTickLabelsVisible(false); ValueAxis valAxis = new NumberAxis(getValue("y", "Value")); valAxis.setRange(new Range(0.0d, 1.05d)); valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); valAxis.setTickMarksVisible(false); valAxis.setTickLabelsVisible(false); BarRenderer3D renderer = new BarRenderer3D(); CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); return plot; }
From source file:org.shredzone.bullshitcharts.chart.LineChartGenerator.java
@Override public Plot generate() { LineDatasetCreator dataset = new LineDatasetCreator(); dataset.setTendency(getTendency());// w w w. j av a 2 s. c o m dataset.setNumberOfValues(getResolution()); dataset.setAmplitude(getAmplitude()); CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n catAxis.setLowerMargin(0.0d); catAxis.setUpperMargin(0.0d); catAxis.setTickMarksVisible(false); catAxis.setTickLabelsVisible(false); ValueAxis valAxis = new NumberAxis(getValue("y", "Value")); valAxis.setRange(new Range(0.0d, 1.05d)); valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); valAxis.setTickMarksVisible(false); valAxis.setTickLabelsVisible(false); LineAndShapeRenderer renderer = new LineRenderer3D(); renderer.setBaseShapesVisible(false); // renderer.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER)); CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); return plot; }
From source file:de.uniol.ui.tsv.ui.StepChartDialog.java
protected JFreeChart createChart() { JFreeChart chart = ChartFactory.createXYStepChartFast(title, xTitle, yTitle, xy, PlotOrientation.VERTICAL, true, false, false);/*from ww w .j a v a 2s . c o m*/ chart.setBackgroundPaint(Color.white); chart.getLegend().setBackgroundPaint(new Color(224, 224, 224)); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setRenderer(new XYStepRendererFast(null, null)); XYItemRenderer xyr = plot.getRenderer(); // xyr.setBaseToolTipGenerator(new XYToolTipGenerator() { // public String generateToolTip(XYDataset dataset, int series, // int item) { // return nf.format(dataset.getXValue(series, item)) // + tooltipRangeUnits + ", " // + nf2.format(dataset.getYValue(series, item)) // + tooltipValueUnits; // } // }); for (int i : seriesStrokes.keySet()) { xyr.setSeriesStroke(i, seriesStrokes.get(i)); } for (int i : seriesColors.keySet()) { xyr.setSeriesPaint(i, seriesColors.get(i)); } DateAxis da = new DateAxis(xTitle); if (useRelativeHourFormat) { da.setDateFormatOverride(new RelativeHourFormat()); } da.setLowerMargin(0.03); plot.setDomainAxis(da); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setRange(new Range(minRange, maxRange)); return chart; }
From source file:biz.ixnay.pivot.charts.skin.jfree.LineChartViewSkin.java
@Override protected JFreeChart createChart() { LineChartView chartView = (LineChartView) getComponent(); String title = chartView.getTitle(); String horizontalAxisLabel = chartView.getHorizontalAxisLabel(); String verticalAxisLabel = chartView.getVerticalAxisLabel(); boolean showLegend = chartView.getShowLegend(); String seriesNameKey = chartView.getSeriesNameKey(); List<?> chartData = chartView.getChartData(); JFreeChart chart;//from www. java2 s .c om ChartView.CategorySequence categories = chartView.getCategories(); if (categories.getLength() > 0) { CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData); if (threeDimensional) { chart = ChartFactory.createLineChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, false, false); } else { chart = ChartFactory.createLineChart(title, horizontalAxisLabel, verticalAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, false, false); } CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); CategoryLabelPositions categoryLabelPositions = CategoryLabelPositions .createUpRotationLabelPositions(categoryLabelRotation); domainAxis.setCategoryLabelPositions(categoryLabelPositions); if (rangeAxisRange != null) { ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(rangeAxisRange); } } else { chart = ChartFactory.createXYLineChart(title, horizontalAxisLabel, verticalAxisLabel, new XYSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend, false, false); if (rangeAxisRange != null) { XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(rangeAxisRange); } } 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. jav 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.ja v a 2 s. com 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:de.uniol.ui.tsv.ui.LineChartDialog.java
/** * @return the resulting chart object// ww w .ja va2s .c o m */ protected JFreeChart createChart() { JFreeChart chart = ChartFactory.createTimeSeriesChartFast(title, xTitle, yTitle, xy, true, false, false); chart.setBackgroundPaint(Color.white); chart.getLegend().setBackgroundPaint(new Color(224, 224, 224)); FastXYPlot plot = (FastXYPlot) chart.getPlot(); // plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setBackgroundPaint(new Color(77, 77, 77)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); StandardXYItemRendererFast r = new StandardXYItemRendererFast(StandardXYItemRendererFast.LINES, null, null); plot.setRenderer(r); for (int i : seriesStrokes.keySet()) { r.setSeriesStroke(i, seriesStrokes.get(i)); } for (int i : seriesColors.keySet()) { r.setSeriesPaint(i, seriesColors.get(i)); } DateAxis da = new DateAxis(xTitle); if (useRelativeHourFormat) { da.setDateFormatOverride(new RelativeHourFormat()); } da.setLowerMargin(0.03); plot.setDomainAxis(da); if (minRange != 0.0 && maxRange != 0.0) { ValueAxis yaxis = plot.getRangeAxis(); yaxis.setRange(new Range(minRange, maxRange)); } return chart; }
From source file:fi.smaa.jsmaa.gui.views.CriterionView.java
private JPanel buildValueFunctionChartPanel(ScaleCriterion criterion) { UtilityFunctionDataset dataset = new UtilityFunctionDataset(criterion); JFreeChart chart = ChartFactory.createXYLineChart("", "x", "v(x)", dataset, PlotOrientation.VERTICAL, false, true, true);//from ww w . j av a 2 s .co m final XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(0, renderer); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3.0f)); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); ValueAxis rAxis = plot.getRangeAxis(); rAxis.setAutoRange(false); rAxis.setRange(new Range(-0.03, 1.03)); ValueAxis dAxis = plot.getDomainAxis(); dAxis.setLowerMargin(0.03); dAxis.setUpperMargin(0.03); ChartPanel chartPanel = new ChartPanel(chart, false, true, true, false, true); chartPanel.addChartMouseListener(new ValueFunctionMouseListener(chartPanel, criterion, parent)); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); chartPanel.setDisplayToolTips(true); chartPanel.setToolTipText("Click to add/remove partial value function points"); chartPanel.setMouseWheelEnabled(false); chartPanel.setMouseZoomable(false); plot.setDomainCrosshairLockedOnData(false); plot.setRangeCrosshairLockedOnData(false); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); FormLayout layout = new FormLayout("left:pref", "p, 3dlu, p"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(chartPanel, cc.xy(1, 1)); builder.add(new ValueFunctionPointsPanel(criterion), cc.xy(1, 3)); return builder.getPanel(); }