List of usage examples for org.jfree.data Range Range
public Range(double lower, double upper)
From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.BulletGraph.java
public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); Dataset dataset = (Dataset) datasets.getDatasets().get("1"); ValueDataset valDataSet = (ValueDataset) dataset; Number value = valDataSet.getValue(); DefaultCategoryDataset datasetC = new DefaultCategoryDataset(); datasetC.addValue(value, "", ""); // customize a bar chart JFreeChart chart = ChartFactory.createBarChart(null, null, null, datasetC, PlotOrientation.HORIZONTAL, false, false, false);//from www .j a v a 2 s . c o m chart.setBorderVisible(false); chart.setBackgroundPaint(color); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } CategoryPlot plot = chart.getCategoryPlot(); plot.setOutlineVisible(true); plot.setOutlinePaint(Color.BLACK); plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setBackgroundPaint(null); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeCrosshairVisible(false); plot.setAnchorValue(value.doubleValue()); // add the target marker if (target != null) { ValueMarker marker = new ValueMarker(target.doubleValue(), Color.BLACK, new BasicStroke(2.0f)); plot.addRangeMarker(marker, Layer.FOREGROUND); } //sets different marks for (Iterator iterator = intervals.iterator(); iterator.hasNext();) { KpiInterval interval = (KpiInterval) iterator.next(); // add the marks IntervalMarker marker = new IntervalMarker(interval.getMin(), interval.getMax(), interval.getColor()); plot.addRangeMarker(marker, Layer.BACKGROUND); logger.debug("Added new interval to the plot"); } // customize axes CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVisible(false); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setVisible(true); // calculate the upper limit //double upperBound = target * upperFactor; rangeAxis.setRange(new Range(lower, upper)); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // customize renderer BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setMaximumBarWidth(0.18); renderer.setSeriesPaint(0, Color.BLACK); return chart; }
From source file:biz.ixnay.pivot.charts.skin.jfree.LineChartViewSkin.java
public void setRangeAxisUpperBound(double upper) { this.rangeAxisRange = new Range(getRangeAxisLowerBound(), upper); repaintComponent();// w w w . j a v a2s . com }
From source file:org.jfree.data.RangeTest.java
/** * A simple test for the expand() method. */// w ww .j a va2 s .c om @Test public void testExpand() { Range r1 = new Range(0.0, 100.0); Range r2 = Range.expand(r1, 0.10, 0.10); assertEquals(-10.0, r2.getLowerBound(), 0.001); assertEquals(110.0, r2.getUpperBound(), 0.001); // Expand by 0% does not change the range r2 = Range.expand(r1, 0.0, 0.0); assertEquals(r1, r2); try { Range.expand(null, 0.1, 0.1); fail("Null value is accepted"); } catch (Exception e) { } // Lower > upper: mid point is used r2 = Range.expand(r1, -0.8, -0.5); assertEquals(65.0, r2.getLowerBound(), 0.001); assertEquals(65.0, r2.getUpperBound(), 0.001); }
From source file:org.jfree.data.statistics.DefaultBoxAndWhiskerXYDatasetTest.java
/** * Some checks for the getRangeBounds() method. */// w w w.j a v a 2s . c o m @Test public void testGetRangeBounds() { DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset("S"); d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(true)); d1.add(new Date(1L), new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList())); assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(true)); d1.add(new Date(2L), new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList())); assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(true)); }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.bargraph.AnimatedBarGraph.java
private static JFreeChart createChart(BarGraphDataSeries dataSeries) { if (dataSeries == null) return null; BarGraphDataSeries ds = dataSeries;//from w w w. jav a2 s . com // create the chart... JFreeChart chart = ChartFactory.createBarChart(ds.getTitle(), // chart title ds.getDomainLabel(), // domain axis label ds.getRangeLabel(), // range axis label ds.getDataSet(0), // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); renderer.setSeriesPaint(3, gp3); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); ValueRange vr = ds.getRangeValueRanges().get(0); if (vr != null) { Range range = new Range(vr.getMin() / vr.getScale(), vr.getMax() / vr.getScale()); rangeAxis.setRange(range); } return chart; }
From source file:inflor.core.gates.ui.PolygonGateAnnotation.java
@Override public Range getXRange() { double[] x = getDomainPoints(); Arrays.sort(x); return new Range(x[0], x[x.length - 1]); }
From source file:br.com.OCTur.view.ContigenteController.java
@FXML private void eCarregarGraficosActionEvent(ActionEvent actionEvent) { DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); if (rbAeroporto.isSelected()) { if (inicio >= aeroportos.size() && !aeroportos.isEmpty()) { inicio = aeroportos.size() - 10; }//from w w w. jav a2 s. c o m for (EntidadeGrafico<Aeroporto> entidadegrafico : aeroportos.subList(inicio, inicio + 10 > aeroportos.size() ? aeroportos.size() : inicio + 10)) { if (entidadegrafico.getValue() >= MAX) { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Maior", entidadegrafico.toString()); } else if (entidadegrafico.getValue() <= MIN) { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Menor", entidadegrafico.toString()); } else { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas", entidadegrafico.toString()); } } } else if (rbCompanhia.isSelected()) { if (inicio >= companhias.size() && !companhias.isEmpty()) { inicio = companhias.size() - 10; } for (EntidadeGrafico<Companhia> entidadegrafico : companhias.subList(inicio, inicio + 10 > companhias.size() ? companhias.size() : inicio + 10)) { if (entidadegrafico.getValue() >= MAX) { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Maior", entidadegrafico.toString()); } else if (entidadegrafico.getValue() <= MIN) { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Menor", entidadegrafico.toString()); } else { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas", entidadegrafico.toString()); } } } else { if (inicio >= aviaos.size() && !aviaos.isEmpty()) { inicio = aviaos.size() - 10; } for (EntidadeGrafico<Aviao> entidadegrafico : aviaos.subList(inicio, inicio + 10 > aviaos.size() ? aviaos.size() : inicio + 10)) { if (entidadegrafico.getValue() >= MAX) { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Maior", entidadegrafico.toString()); } else if (entidadegrafico.getValue() <= MIN) { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Menor", entidadegrafico.toString()); } else { dcdDados.setValue(entidadegrafico.getValue(), "Pessoas", entidadegrafico.toString()); } } } JFreeChart jFreeChart = ChartFactory.createBarChart("", "", "", dcdDados, PlotOrientation.VERTICAL, false, false, false); if (rbAviao.isSelected()) { jFreeChart.getCategoryPlot().getRangeAxis().setRange(new Range(0, 100)); jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance())); jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelsVisible(true); } else { jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelGenerator( new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance())); jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelsVisible(true); } ChartPanel chartPanel = new ChartPanel(jFreeChart); snGraficos.setContent(chartPanel); snGraficos.getContent().repaint(); }
From source file:asl.util.PlotMaker.java
public void plotZNE_3x3(ArrayList<double[]> channelData, double[] xsecs, int nstart, int nend, String eventString, String plotString) { // Expecting 9 channels packed like: Panel Trace1 Trace2 Trace3 // channels[0] = 00-LHZ 1 00-LHZ 10-LHZ 20-LHZ // channels[1] = 00-LHND 2 00-LHND 10-LHND 20-LHND // channels[2] = 00-LHED 3 00-LHED 10-LHED 20-LHED // channels[3] = 10-LHZ // channels[4] = 10-LHND // channels[5] = 10-LHED // channels[6] = 20-LHZ // channels[7] = 20-LHND // channels[8] = 20-LHED final String plotTitle = String.format("%04d%03d [Stn:%s] [Event:%s] %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, eventString, plotString); final String pngName = String.format("%s/%s.%s.%s.png", outputDir, eventString, station, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotZNE_3x3: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return;/*from www . j ava2 s .c o m*/ } if (channelData.size() != channels.length) { System.out.format("== plotZNE_3x3: Error: We have [%d channels] but [%d channelData]\n", channels.length, channelData.size()); return; } XYSeries[] series = new XYSeries[channels.length]; for (int i = 0; i < channels.length; i++) { series[i] = new XYSeries(channels[i].toString()); double[] data = channelData.get(i); //for (int k = 0; k < xsecs.length; k++){ for (int k = 0; k < data.length; k++) { series[i].add(xsecs[k], data[k]); } } // I. Panel I = Verticals // Use the first data array, within the plotted range (nstart - nend) to scale the plots: double[] data = channelData.get(0); double ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Paint[] paints = new Paint[] { Color.red, Color.blue, Color.green }; for (int i = 0; i < paints.length; i++) { renderer.setSeriesPaint(i, paints[i]); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } final NumberAxis verticalAxis = new NumberAxis("Displacement (m)"); verticalAxis.setRange(new Range(-ymax, ymax)); //verticalAxis.setTickUnit( new NumberTickUnit(5) ); final NumberAxis horizontalAxis = new NumberAxis("Time (s)"); horizontalAxis.setRange(new Range(nstart, nend)); //horizontalAxis.setRange( new Range(0.00009 , 110) ); final NumberAxis hAxis = new NumberAxis("Time (s)"); hAxis.setRange(new Range(nstart, nend)); final XYSeriesCollection seriesCollection1 = new XYSeriesCollection(); seriesCollection1.addSeries(series[0]); seriesCollection1.addSeries(series[3]); seriesCollection1.addSeries(series[6]); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, null, verticalAxis, renderer); //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, horizontalAxis, verticalAxis, renderer); final XYPlot xyplot1 = new XYPlot((XYDataset) seriesCollection1, hAxis, verticalAxis, renderer); double x = .95 * xsecs[nend]; double y = .90 * ymax; XYTextAnnotation annotation1 = new XYTextAnnotation("Vertical", x, y); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot1.addAnnotation(annotation1); // II. Panel II = North // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(1); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisN = new NumberAxis("Displacement (m)"); verticalAxisN.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series[1]); seriesCollection2.addSeries(series[4]); seriesCollection2.addSeries(series[7]); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, verticalAxisN, renderer); XYTextAnnotation annotation2 = new XYTextAnnotation("North-South", x, y); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot2.addAnnotation(annotation2); // III. Panel III = East // Use the first data array, within the plotted range (nstart - nend) to scale the plots: data = channelData.get(2); ymax = 0; for (int k = nstart; k < nend; k++) { if (data[k] > ymax) ymax = data[k]; } final NumberAxis verticalAxisE = new NumberAxis("Displacement (m)"); verticalAxisE.setRange(new Range(-ymax, ymax)); final XYSeriesCollection seriesCollection3 = new XYSeriesCollection(); seriesCollection3.addSeries(series[2]); seriesCollection3.addSeries(series[5]); seriesCollection3.addSeries(series[8]); final XYPlot xyplot3 = new XYPlot((XYDataset) seriesCollection3, null, verticalAxisE, renderer); XYTextAnnotation annotation3 = new XYTextAnnotation("East-West", x, y); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 14)); xyplot3.addAnnotation(annotation3); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot1, 1); combinedPlot.add(xyplot2, 1); combinedPlot.add(xyplot3, 1); combinedPlot.setGap(15.); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:sturesy.voting.gui.VotingEvaluationPanelUI.java
private JFreeChart createChart(final CategoryDataset dataset, String questiontext, Color background, boolean showAnswers, List<Integer> correctAnswers, boolean showPercent) { String valueAxisLabel = Localize.getString(showPercent ? "label.votes.percent" : "label.votes.absolute"); final JFreeChart chart = ChartFactory.createBarChart(questiontext, Localize.getString("label.answers"), valueAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(background); final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); final CategoryItemRenderer renderer = new AnswersBarRenderer(showAnswers, correctAnswers); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(16.0f)); final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0);/*w w w.ja v a2s . co m*/ renderer.setBasePositiveItemLabelPosition(p); plot.setRenderer(renderer); // change the margin at the top of the range axis... final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); double upperrange = rangeAxis.getRange().getUpperBound(); if (showPercent) { renderer.setBaseItemLabelGenerator(new AppendPercentRenderer()); rangeAxis.setRange(new Range(0, upperrange > 100 ? 100 : upperrange), false, false); } else { renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); } plot.getDomainAxis().setMaximumCategoryLabelLines(5); return chart; }
From source file:inflor.core.gates.ui.PolygonGateAnnotation.java
@Override public Range getYRange() { double[] y = getRangePoints(); Arrays.sort(y); return new Range(y[0], y[y.length - 1]); }