List of usage examples for org.jfree.chart.axis ValueAxis setLowerMargin
public void setLowerMargin(double margin)
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);/* w w w. ja v a 2 s . c om*/ 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(); }
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);//from ww w . j a va 2 s .c o 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:com.xpn.xwiki.plugin.charts.ChartCustomizer.java
public static void customizeValueAxis(ValueAxis axis, ChartParams params, String prefix) { customizeAxis(axis, params, prefix); if (params.get(prefix + ChartParams.VALUE_AXIS_AUTO_RANGE_SUFFIX) != null) { axis.setAutoRange(params.getBoolean(prefix + ChartParams.VALUE_AXIS_AUTO_RANGE_SUFFIX).booleanValue()); }//from w w w . j av a 2 s . c o m if (axis.isAutoRange()) { // work only with auto range if (params.get(prefix + ChartParams.VALUE_AXIS_AUTO_RANGE_MIN_SIZE_SUFFIX) != null) { axis.setAutoRangeMinimumSize( params.getDouble(prefix + ChartParams.VALUE_AXIS_AUTO_RANGE_MIN_SIZE_SUFFIX).doubleValue()); } if (params.get(prefix + ChartParams.AXIS_LOWER_MARGIN_SUFFIX) != null) { axis.setLowerMargin(params.getDouble(prefix + ChartParams.AXIS_LOWER_MARGIN_SUFFIX).doubleValue()); } if (params.get(prefix + ChartParams.AXIS_UPPER_MARGIN_SUFFIX) != null) { axis.setUpperMargin(params.getDouble(prefix + ChartParams.AXIS_UPPER_MARGIN_SUFFIX).doubleValue()); } } else { // work only when auto range is off if (params.get(prefix + ChartParams.VALUE_AXIS_LOWER_BOUND_SUFFIX) != null) { axis.setLowerBound( params.getDouble(prefix + ChartParams.VALUE_AXIS_LOWER_BOUND_SUFFIX).doubleValue()); } if (params.get(prefix + ChartParams.VALUE_AXIS_UPPER_BOUND_SUFFIX) != null) { axis.setUpperBound( params.getDouble(prefix + ChartParams.VALUE_AXIS_UPPER_BOUND_SUFFIX).doubleValue()); } } if (params.get(prefix + ChartParams.VALUE_AXIS_AUTO_TICK_UNIT_SUFFIX) != null) { axis.setAutoTickUnitSelection( params.getBoolean(prefix + ChartParams.VALUE_AXIS_AUTO_TICK_UNIT_SUFFIX).booleanValue()); } if (params.get(prefix + ChartParams.VALUE_AXIS_VERTICAL_TICK_LABELS_SUFFIX) != null) { axis.setVerticalTickLabels( params.getBoolean(prefix + ChartParams.VALUE_AXIS_VERTICAL_TICK_LABELS_SUFFIX).booleanValue()); } }
From source file:org.operamasks.faces.render.graph.CurveAreaChartRenderer.java
private JFreeChart createXYCurveAreaChart(XYDataset dataset, PlotOrientation orientation) { ValueAxis xAxis; if (dataset instanceof TimeSeriesCollection) { xAxis = new DateAxis(); } else {/*from w w w .j a v a2 s. c o m*/ xAxis = new NumberAxis(); ((NumberAxis) xAxis).setAutoRangeIncludesZero(false); } xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(); yAxis.setAutoRangeIncludesZero(false); XYCurveAndShapeRenderer renderer = new XYCurveAndShapeRenderer(true, false); renderer.setDrawArea(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (dataset.getSeriesCount() > 1) { plot.setForegroundAlpha(0.75f); } return new JFreeChart(null, null, plot, false); }
From source file:org.jfree.chart.demo.MarkerDemo1.java
/** * Creates a sample chart./*from w w w . j a va2 s . co m*/ * * @param data the sample data. * * @return A configured chart. */ private JFreeChart createChart(final XYDataset data) { final JFreeChart chart = ChartFactory.createScatterPlot("Marker Demo 1", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); // chart.getLegend().setAnchor(Legend.EAST); // customise... final XYPlot plot = chart.getXYPlot(); plot.getRenderer().setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); // set axis margins to allow space for marker labels... final DateAxis domainAxis = new DateAxis("Time"); domainAxis.setUpperMargin(0.50); plot.setDomainAxis(domainAxis); final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setUpperMargin(0.30); rangeAxis.setLowerMargin(0.50); // add a labelled marker for the bid start price... final Marker start = new ValueMarker(200.0); start.setPaint(Color.green); start.setLabel("Bid Start Price"); start.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); start.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(start); // add a labelled marker for the target price... final Marker target = new ValueMarker(175.0); target.setPaint(Color.red); target.setLabel("Target Price"); target.setLabelAnchor(RectangleAnchor.TOP_RIGHT); target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addRangeMarker(target); // add a labelled marker for the original closing time... final Hour hour = new Hour(2, new Day(22, 5, 2003)); double millis = hour.getFirstMillisecond(); final Marker originalEnd = new ValueMarker(millis); originalEnd.setPaint(Color.orange); originalEnd.setLabel("Original Close (02:00)"); originalEnd.setLabelAnchor(RectangleAnchor.TOP_LEFT); originalEnd.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(originalEnd); // add a labelled marker for the current closing time... final Minute min = new Minute(15, hour); millis = min.getFirstMillisecond(); final Marker currentEnd = new ValueMarker(millis); currentEnd.setPaint(Color.red); currentEnd.setLabel("Close Date (02:15)"); currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT); currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addDomainMarker(currentEnd); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // label the best bid with an arrow and label... final Hour h = new Hour(2, new Day(22, 5, 2003)); final Minute m = new Minute(10, h); millis = m.getFirstMillisecond(); final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), null); final XYAnnotation bestBid = new XYDrawableAnnotation(millis, 163.0, 11, 11, cd); plot.addAnnotation(bestBid); final XYPointerAnnotation pointer = new XYPointerAnnotation("Best Bid", millis, 163.0, 3.0 * Math.PI / 4.0); pointer.setBaseRadius(35.0); pointer.setTipRadius(10.0); pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); pointer.setPaint(Color.blue); pointer.setTextAnchor(TextAnchor.HALF_ASCENT_RIGHT); plot.addAnnotation(pointer); return chart; }
From source file:api.window.Histogram.java
private JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYAreaChart(null, null, null, xydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setForegroundAlpha(0.65F);//from ww w.jav a2 s . co m xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setTickMarkPaint(Color.black); valueaxis.setLowerMargin(0.0D); valueaxis.setUpperMargin(0.0D); renderer = xyplot.getRenderer(); if (xydataset.getSeriesCount() == 4) { renderer.setSeriesPaint(0, Color.red); renderer.setSeriesPaint(1, Color.green); renderer.setSeriesPaint(2, Color.blue); renderer.setSeriesVisible(0, true); renderer.setSeriesVisible(1, true); renderer.setSeriesVisible(2, true); renderer.setSeriesPaint(3, Color.BLACK); renderer.setSeriesVisible(3, true); } else { this.remove(this.jPanel1); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesVisible(0, true); } ValueAxis valueaxis1 = xyplot.getRangeAxis(); valueaxis1.setTickMarkPaint(Color.black); return jfreechart; }
From source file:com.polivoto.vistas.acciones.Datos.java
private JFreeChart createChartBar(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart("Votacion", "Opciones", "Total de votos", dataset, PlotOrientation.VERTICAL, true, true, true); try {// www . j a v a2 s .c om chart.addSubtitle(new TextTitle(ac.getPreguntas().getJSONObject(pox).getString("pregunta"))); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white)); CategoryPlot plot = chart.getCategoryPlot(); org.jfree.chart.axis.CategoryAxis axis = plot.getDomainAxis(); axis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D)); // final CategoryItemRenderer itemRenderer = new CustomRenderer( // new Paint[] {Color.green, Color.red, Color.blue, Color.yellow, Color.magenta, Color.cyan, Color.pink, Color.lightGray} // ); //// itemRenderer.setBaseItemLabelsVisible(true); //// BarRenderer barRenderer = (BarRenderer)itemRenderer; //// barRenderer.setItemMargin(0.2D); //// plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, new java.awt.Color(147, 60, 45))); //// // StandardCategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("{0}: {2} %", new DecimalFormat("0")); // // // plot.setNoDataMessage("SIN DATOS!"); // // //// renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // itemRenderer.setItemLabelsVisible(true); // final ItemLabelPosition p = new ItemLabelPosition( // ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0 // ); // itemRenderer.setPositiveItemLabelPosition(p); // plot.setRenderer(itemRenderer); // 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); } catch (JSONException ex) { Logger.getLogger(Datos.class.getName()).log(Level.SEVERE, null, ex); } return chart; }
From source file:com.xilinx.ultrascale.gui.BarCharts.java
License:asdf
public void setaRange() { CategoryPlot plot = chart.getCategoryPlot(); ValueAxis axis = plot.getRangeAxis(); // axis.setUpperBound(1000.0); // axis.setLowerBound(0.0); // axis.setAutoRangeMinimumSize(1.0); axis.setAutoRange(true);/*from w w w . j a v a 2 s .c om*/ // axis.setLowerMargin(0); axis.setLowerMargin(0); axis.setUpperMargin(0.40); axis.setAutoRangeMinimumSize(1.0); axis.setDefaultAutoRange(new Range(0, 1000)); }
From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java
/** * Creates a XY bar chart./* w w w. jav a 2s . com*/ * * @param title * @param categoryAxisLabel * @param valueAxisLabel * @param dataset * @param includeZero * @param shadow * @return */ public JFreeChart createXYBarChart(String title, String categoryAxisLabel, String valueAxisLabel, IntervalXYDataset dataset, boolean includeZero, boolean shadow) { JFreeChart chart = ChartFactory.createXYBarChart(title, categoryAxisLabel, false, valueAxisLabel, dataset, this.orientation, this.drawLegend, false, false); // set the background color for the chart... chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.025); domainAxis.setUpperMargin(0.025); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(includeZero); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setShadowVisible(shadow); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.red); renderer.setSeriesPaint(2, Color.green); renderer.setSeriesPaint(3, Color.darkGray); renderer.setSeriesPaint(4, Color.yellow); return chart; }
From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java
/** * Creates a line chart.//from ww w .j a va2 s . co m * * @param title * @param categoryAxisLabel * (X-Axis label) * @param valueAxisLabel * (Y-Axis label) * @param dataset * @param includeZero * True when zero shall be included to the axis range. * @return JfreeChart instance. */ public JFreeChart createXYLineChart(String title, String categoryAxisLabel, String valueAxisLabel, XYDataset dataset, boolean includeZero, boolean drawShapes) { JFreeChart chart = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset, this.orientation, this.drawLegend, false, false); // set the background color for the chart... chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.025); domainAxis.setUpperMargin(0.025); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(includeZero); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.red); renderer.setSeriesPaint(2, Color.green); renderer.setSeriesPaint(3, Color.darkGray); renderer.setSeriesPaint(4, Color.yellow); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseShapesVisible(drawShapes); renderer.setBaseShapesFilled(true); return chart; }