List of usage examples for org.jfree.chart.plot XYPlot setRangeAxis
public void setRangeAxis(ValueAxis axis)
From source file:ec.ui.view.StabilityView.java
private void configureAxis(XYPlot plot) { int nb = graphs_.size(); List<String> names = new ArrayList<>(); for (Map.Entry<Bornes, Graphs> entry : graphs_.entrySet()) { names.add(entry.getValue().label_); }/*from ww w . j a v a 2 s .com*/ NumberAxis xAxis = new NumberAxis(); xAxis.setTickLabelPaint(Color.GRAY); xAxis.setTickUnit(new StabilityTickUnit(names)); xAxis.setRange(-0.5, nb - 0.5); plot.setDomainAxis(xAxis); plot.setDomainGridlinesVisible(false); NumberAxis yaxis = new NumberAxis(); rescaleAxis(yaxis); plot.setRangeAxis(yaxis); for (int i = 0; i < nb; i++) { ValueMarker marker = new ValueMarker(i + 0.5); marker.setStroke(MARKER_STROKE); marker.setPaint(MARKER_PAINT); marker.setAlpha(MARKER_ALPHA); plot.addDomainMarker(marker); } }
From source file:KIDLYFactory.java
/** * Creates a stacked XY area plot. The chart object returned by this * method uses an {@link XYPlot} instance as the plot, with a * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and a {@link StackedXYAreaRenderer2} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A stacked XY area chart.//from w ww. j a va2 s . c o m */ public static JFreeChart createStackedXYAreaChart(String title, String xAxisLabel, String yAxisLabel, TableXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator); renderer.setOutline(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setRangeAxis(yAxis); // forces recalculation of the axis range JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:org.jfree.eastwood.ChartEngine.java
/** * Creates a scatter chart./*from ww w .j ava 2s . com*/ * * @return A scatter chart. */ private static JFreeChart createScatterChart() { JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setOutlinePaint(null); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBasePaint(new Color(0x76A4FB)); renderer.setAutoPopulateSeriesPaint(false); GValueAxis xAxis = new GValueAxis(); xAxis.setTickLabelsVisible(false); xAxis.setTickMarksVisible(false); plot.setDomainAxis(xAxis); GValueAxis yAxis = new GValueAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); plot.setRangeAxis(yAxis); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); return chart; }
From source file:org.moeaframework.analysis.plot.Plot.java
/** * If the chart has not yet been initialized, creates a chart for XY data. * If the chart is already initialized, checks if the chart is for XY data. * /* www . j av a2 s . co m*/ * @throws FrameworkException if the chart does not support XY data */ private void createXYPlot() { if (chart == null) { NumberAxis xAxis = new NumberAxis(""); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(""); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(); plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator(); XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); plot.setRenderer(renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartFactory.getChartTheme().apply(chart); } else if (!(chart.getPlot() instanceof XYPlot)) { throw new FrameworkException("Can not combine XY plot and categorial plot"); } }
From source file:SciTK.Plot.java
/** * Set the logarithmic state of the range axis. * @param enabled true enables log mode, false disables *//*from ww w. j av a 2s . com*/ public void setRangeAxisLog(boolean enabled) { // get current limits of the axis: XYPlot p = chart.getXYPlot(); // get the domain axis for this plot: ValueAxis current = p.getRangeAxis(); // set new axis type based on enabled boolean: ValueAxis newAxis; if (enabled) newAxis = new LogAxis(current.getLabel()); else newAxis = new NumberAxis(current.getLabel()); // update axis: p.setRangeAxis(newAxis); }
From source file:org.tolven.web.ChartAction.java
/** * Create Growth Chart//from w ww . ja v a 2s .c o m * * @author Suja * added on 02/01/2011 * @param type - 1: Height & 2: Weight * @return */ public JFreeChart createChart(int type) { long patientId = Long.parseLong(getRequestParameter("element").toString().split(":")[1].split("-")[1]); MenuData patMD = getMenuLocal().findMenuDataItem(patientId); int age = 0; int gender = 1; Date dob = null; if (patMD != null) { DateFormat df = new SimpleDateFormat("yyyy"); dob = patMD.getDate01(); Date cur = new Date(); age = Integer.parseInt(df.format(cur)) - Integer.parseInt(df.format(dob)); if (patMD.getString04().equals("Male")) gender = 1; else gender = 2; } // create dataset XYDataset dataset = createDataset(type, gender, age, dob); String title = ""; if (type == 1 && age < 3) title = "Height birth to 36 Months Old " + (gender == 1 ? "Male" : "Female"); else if (type == 1 && age >= 3) title = "Height 2-20 Year Old " + (gender == 1 ? "Male" : "Female"); else if (type == 2 && age < 3) title = "Weight birth to 36 Months Old " + (gender == 1 ? "Male" : "Female"); else if (type == 2 && age >= 3) title = "Weight 2-20 Year Old " + (gender == 1 ? "Male" : "Female"); JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "X-Value", // x-axis label "Y-Value", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.lightGray); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 1; i < 10; i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); } renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(renderer); plot.setDomainAxis(new NumberAxis("Age (Months)")); plot.setRangeAxis(new NumberAxis((type == 1 ? "Height (Centimeters)" : "Weight (Kilograms)"))); return chart; }
From source file:com.sun.japex.ChartGenerator.java
private JFreeChart generateDriverScatterChart() { try {/* w ww. ja v a2 s . c o m*/ DefaultTableXYDataset xyDataset = new DefaultTableXYDataset(); // Generate charts for (DriverImpl di : _testSuite.getDriverInfoList()) { if (!di.hasParam(Constants.RESULT_ARIT_MEAN_X)) { System.out.println("Error: Driver '" + di.getName() + "' does not define" + " any values for the X axis needed to generate a scatter chart"); System.exit(1); } XYSeries xySeries = new XYSeries(di.getName(), true, false); xySeries.add(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X), di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN)); xySeries.add(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X), di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN)); xySeries.add(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X), di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN)); xyDataset.addSeries(xySeries); } String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT); String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X); JFreeChart chart = ChartFactory.createScatterPlot("Result Summary", resultUnitX, resultUnit, xyDataset, PlotOrientation.VERTICAL, true, true, false); // Set log scale depending on japex.resultAxis[_X] XYPlot plot = chart.getXYPlot(); if (_testSuite.getParam(Constants.RESULT_AXIS_X).equalsIgnoreCase("logarithmic")) { LogarithmicAxis logAxisX = new LogarithmicAxis(resultUnitX); logAxisX.setAllowNegativesFlag(true); plot.setDomainAxis(logAxisX); } if (_testSuite.getParam(Constants.RESULT_AXIS).equalsIgnoreCase("logarithmic")) { LogarithmicAxis logAxis = new LogarithmicAxis(resultUnit); logAxis.setAllowNegativesFlag(true); plot.setRangeAxis(logAxis); } return chart; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.sun.japex.ChartGenerator.java
private int generateTestCaseScatterCharts(String baseName, String extension) { int nOfFiles = 0; List<DriverImpl> driverInfoList = _testSuite.getDriverInfoList(); try {//from ww w . j a v a2 s.c o m // Get number of tests from first driver final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size(); DefaultTableXYDataset xyDataset = new DefaultTableXYDataset(); // Generate charts for (DriverImpl di : driverInfoList) { XYSeries xySeries = new XYSeries(di.getName(), true, false); for (int j = 0; j < nOfTests; j++) { TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(j); try { xySeries.add(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X), tc.getDoubleParamNoNaN(Constants.RESULT_VALUE)); } catch (SeriesException e) { // Ignore duplicate x-valued points } } xyDataset.addSeries(xySeries); } String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT); String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X); JFreeChart chart = ChartFactory.createScatterPlot("Results Per Test", resultUnitX, resultUnit, xyDataset, PlotOrientation.VERTICAL, true, true, false); // Set log scale depending on japex.resultAxis[_X] XYPlot plot = chart.getXYPlot(); if (_testSuite.getParam(Constants.RESULT_AXIS_X).equalsIgnoreCase("logarithmic")) { LogarithmicAxis logAxisX = new LogarithmicAxis(resultUnitX); logAxisX.setAllowNegativesFlag(true); plot.setDomainAxis(logAxisX); } if (_testSuite.getParam(Constants.RESULT_AXIS).equalsIgnoreCase("logarithmic")) { LogarithmicAxis logAxis = new LogarithmicAxis(resultUnit); logAxis.setAllowNegativesFlag(true); plot.setRangeAxis(logAxis); } chart.setAntiAlias(true); ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension), chart, _chartWidth, _chartHeight); nOfFiles++; } catch (RuntimeException e) { throw e; } catch (Exception e) { e.printStackTrace(); } return nOfFiles; }
From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java
private void configureAxis(XYPlot plot, int start, int end) { int nb = graphs_.size(); List<String> names = new ArrayList<>(); for (int i = start; i <= end; i++) { names.add(periods.get(i).toString()); }/*from w ww . j ava 2 s . c om*/ NumberAxis xAxis = new NumberAxis(); xAxis.setTickLabelPaint(Color.GRAY); xAxis.setTickUnit(new MyTickUnit(names)); xAxis.setRange(-0.5, nb - 0.5); xAxis.setVerticalTickLabels(true); plot.setDomainAxis(xAxis); plot.setDomainGridlinesVisible(false); NumberAxis yaxis = new NumberAxis(); rescaleAxis(yaxis); yaxis.configure(); plot.setRangeAxis(yaxis); for (int i = 0; i < nb; i++) { ValueMarker marker = new ValueMarker(i + 0.5); marker.setStroke(MARKER_STROKE); marker.setPaint(MARKER_PAINT); marker.setAlpha(MARKER_ALPHA); plot.addDomainMarker(marker); } }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
@Override protected Component getRendererOrEditorComponent(JTable table0, @NonNull Object value, boolean isSelected, boolean hasFocus, int row, int column, boolean rendererCalled) { if (currentParameter != null) { currentParameter.removeListener(this); }/*w ww .ja v a 2s. c o m*/ currentParameter = (FloatRangeParameter) value; currentParameter.addGUIListener(this); table = table0; tableRow = row; evenTableRow = (row % 2 == 0); setOpaque(true); if (evenTableRow) { this.setBackground(Utils.COLOR_FOR_EVEN_ROWS); } else this.setBackground(Utils.COLOR_FOR_ODD_ROWS); textValueFrame.setBackground(getBackground()); silenceUpdate = true; readInValuesFromParameter(); if (currentParameter.histogram == null) ;// currentParameter.histogram=new XYSeries(""); if (currentParameter.histogram instanceof XYSeries) { XYSeries xyData = (XYSeries) currentParameter.histogram; if (chart != null && chart.getXYPlot().getDataset() != null) { chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot()); } chart = ChartFactory.createXYLineChart(null, // chart title null, // "Category", // domain axis label null, // "Value", // range axis label new XYSeriesCollection(xyData), // data PlotOrientation.VERTICAL, false, // include legend true, false); } else if (currentParameter.histogram != null) { // assume for now it's a histogram if (chart != null && chart.getXYPlot().getDataset() != null) { chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot()); } String plotTitle = "Histogram"; String xaxis = "number"; String yaxis = "value"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; chart = ChartFactory.createHistogram(plotTitle, xaxis, yaxis, (IntervalXYDataset) currentParameter.histogram, orientation, show, toolTips, urls);// dataset } else { if (chart != null && chart.getXYPlot().getDataset() != null) { chart.getXYPlot().getDataset(0).removeChangeListener(chart.getXYPlot()); } chart = null; } if (currentParameter.histogram != null) { add(panelForHistogram, cForHistogram); final XYPlot plot = chart.getXYPlot(); final NumberAxis domainAxis = new NumberAxis(null); domainAxis.setAutoRange(false); domainAxis.setTickLabelFont(new Font("Times", 0, 20)); domainAxis.setLowerBound(minimum); domainAxis.setUpperBound(maximum); plot.setDomainAxis(domainAxis); final NumberAxis rangeAxis = new NumberAxis(null); rangeAxis.setAutoRange(true); rangeAxis.setVisible(false); plot.setRangeAxis(rangeAxis); chart.setBackgroundPaint(Color.white); chart.setPadding(new RectangleInsets(0, 0, 0, 0)); plot.setBackgroundImage(null); plot.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); if (chartPanel == null) { chartPanel = new ChartPanel(chart); chartPanel.addMouseListener(this); chartPanel.addMouseMotionListener(this); chartPanel.setMouseWheelEnabled(true); chartPanel.setMouseZoomable(false); chartPanel.setRangeZoomable(false); panelForHistogram.add(chartPanel); } else chartPanel.setChart(chart); chartPanel.setSize(panelForHistogram.getSize()); ((XYPlot) chart.getPlot()).getRenderer().setSeriesStroke(0, new BasicStroke(5.0f)); selectionRange = new IntervalMarker(currentValue0, currentValue1); ((XYPlot) chart.getPlot()).addDomainMarker(selectionRange); } else { remove(panelForHistogram); setMaximumSize(new Dimension(700, 50)); setPreferredSize(new Dimension(700, 50)); } updateDisplays(); silenceUpdate = false; return this; }