List of usage examples for org.jfree.chart.axis ValueAxis setAutoRange
public void setAutoRange(boolean auto)
From source file:com.jaxzin.iraf.demo.CdfInv.java
private static void customizeChart(JFreeChart chart) { // Set the transparency of the histogram bars chart.getCategoryPlot().setForegroundAlpha(0.5f); // Lock the y-axis to 0.0->0.5 ValueAxis axis = new NumberAxis("Value"); axis.setAutoRange(true); chart.getCategoryPlot().setRangeAxis(axis); // Lock the x-axis to -6.0->6.0 CategoryAxis domainAxis = new CategoryAxis("Probability"); domainAxis.setTickLabelsVisible(false); chart.getCategoryPlot().setDomainAxis(domainAxis); }
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); 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);/* w w w. ja v a 2 s . c o m*/ domainAxis.setRange(new Range(-6.0, 6.0)); chart.getXYPlot().setDomainAxis(domainAxis); }
From source file:temp1.RealTimeChart.java
public static JFreeChart createChart(String chartContent, String title, String yaxisName) { thread1 = new Thread(); timeseries1 = new TimeSeries(chartContent, Millisecond.class); timeseries2 = new TimeSeries(chartContent, Millisecond.class); timeseries3 = new TimeSeries(chartContent, Millisecond.class); timeseries4 = new TimeSeries(chartContent, Millisecond.class); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries1); TimeSeriesCollection timeseriescollection1 = new TimeSeriesCollection(timeseries2); TimeSeriesCollection timeseriescollection2 = new TimeSeriesCollection(timeseries3); TimeSeriesCollection timeseriescollection3 = new TimeSeriesCollection(timeseries4); jfreechart = ChartFactory.createTimeSeriesChart("", "", "", timeseriescollection, false, false, false); final XYPlot xyplot = jfreechart.getXYPlot(); xyplot.setOutlinePaint(Color.magenta); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.gray); xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(20000D); //Value/*from w w w. j a v a 2 s . co m*/ valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(800D, 3300D); xyplot.setDataset(0, timeseriescollection); xyplot.setDataset(1, timeseriescollection1); xyplot.setDataset(2, timeseriescollection2); xyplot.setDataset(3, timeseriescollection3); XYLineAndShapeRenderer xylineandshaperenderer0 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer(); xylineandshaperenderer0.setBaseShapesVisible(false); xylineandshaperenderer1.setBaseShapesVisible(false); xylineandshaperenderer2.setBaseShapesVisible(false); xylineandshaperenderer3.setBaseShapesVisible(false); xylineandshaperenderer0.setSeriesPaint(0, Color.RED); xylineandshaperenderer1.setSeriesPaint(0, Color.cyan); xylineandshaperenderer2.setSeriesPaint(0, Color.yellow); xylineandshaperenderer3.setSeriesPaint(0, Color.blue); xyplot.setRenderer(0, xylineandshaperenderer0); xyplot.setRenderer(1, xylineandshaperenderer1); xyplot.setRenderer(2, xylineandshaperenderer2); xyplot.setRenderer(3, xylineandshaperenderer3); //xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F, 1, 1, 5F, new float[] { 5F, 10F }, 0.0F)); return jfreechart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
public static JFreeChart createTimeChart(ITimeSeriesSet timeSeriesSet) { // TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); JFreeChart chart = ChartFactory.createTimeSeriesChart(timeSeriesSet.getTitle(), null, timeSeriesSet.getYTitle()//from w ww .j a va 2 s . c o m + (timeSeriesSet.getYUnits() != null ? " (" + timeSeriesSet.getYUnits() + ")" : ""), timeSeriesSet, true, true, false); XYPlot xyplot = chart.getXYPlot(); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); // valueaxis.setFixedAutoRange(60000D); valueaxis = xyplot.getRangeAxis(); valueaxis.setRange(0.0D, 200D); valueaxis.setAutoRange(true); XYItemRenderer renderer = xyplot.getRenderer(); if (renderer instanceof XYLineAndShapeRenderer) { ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(false); } chartTheme.apply(chart); Font font = valueaxis.getLabelFont(); valueaxis.setLabelFont(font.deriveFont(Font.PLAIN)); return chart; }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * This is a helper method for creating a line chart. This should only do * the chart creation and not setting up the dataset. The calling method * should do the logic for the dataset setup. * @param c /*from ww w . j a v a2s. co m*/ * * @param xyCollection * The dataset to display a chart for. * @param chartType * The chart type. This must be a valid chart type that can be * created from an XY dataset. At current only line and scatter * are supported * @param legendPosition * The position of the legend. * @param chartName * The name of the chart. * @param yaxisName * The name of the y axis. * @param xaxisName * The name of the x axis. * @return A chart of the specified chartType based on the given dataset. */ private static JFreeChart createChartFromXYDataset(Chart c, XYDataset xyCollection, ChartType chartType, LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) { boolean showLegend = !legendPosition.equals(LegendPosition.NONE); JFreeChart chart; if (chartType.equals(ChartType.LINE)) { chart = ChartFactory.createXYLineChart(chartName, xaxisName, yaxisName, xyCollection, PlotOrientation.VERTICAL, showLegend, true, false); } else if (chartType.equals(ChartType.SCATTER)) { chart = ChartFactory.createScatterPlot(chartName, xaxisName, yaxisName, xyCollection, PlotOrientation.VERTICAL, showLegend, true, false); } else { throw new IllegalArgumentException("Unknown chart type " + chartType + " for an XY dataset."); } if (chart == null) return null; XYPlot plot = (XYPlot) chart.getPlot(); // XXX the following instance check is brittle; there are many ways to represent a time // series in JFreeChart. This check uses knowledge of the inner workings of DatasetUtil. if (xyCollection instanceof TimePeriodValuesCollection) { logger.debug("Switching x-axis to date axis so labels render properly"); plot.setDomainAxis(new DateAxis(xaxisName)); // TODO user-settable date format // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); } if (legendPosition != LegendPosition.NONE) { chart.getLegend().setPosition(legendPosition.getRectangleEdge()); } if (!c.isAutoXAxisRange()) { XYPlot xyplot = chart.getXYPlot(); ValueAxis axis = xyplot.getDomainAxis(); axis.setAutoRange(false); axis.setRange(c.getXAxisMinRange(), c.getXAxisMaxRange()); } if (!c.isAutoYAxisRange()) { XYPlot xyplot = chart.getXYPlot(); ValueAxis axis = xyplot.getRangeAxis(); axis.setAutoRange(false); axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange()); } return chart; }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * This is a helper method for creating charts and is split off as it does * only the chart creation and tweaking of a category chart. All of the * decisions for what columns are defined as what and how the data is stored * should be done in the method that calls this. * <p>//from www. ja v a 2s. com * Given a dataset and other chart properties this will create an * appropriate JFreeChart. * @param c * * @param dataset * The data to create a chart from. * @param chartType * The type of chart to create for the category dataset. * @param legendPosition * The position where the legend should appear. * @param chartName * The title of the chart. * @param yaxisName * The title of the Y axis. * @param xaxisName * The title of the X axis. * @return A JFreeChart that represents the dataset given. */ private static JFreeChart createCategoryChartFromDataset(Chart c, CategoryDataset dataset, ChartType chartType, LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) { if (chartType == null || dataset == null) { return null; } boolean showLegend = !legendPosition.equals(LegendPosition.NONE); JFreeChart chart; ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); BarRenderer.setDefaultBarPainter(new StandardBarPainter()); if (chartType == ChartType.BAR) { chart = ChartFactory.createBarChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else if (chartType == ChartType.PIE) { chart = createPieChart(chartName, dataset, TableOrder.BY_ROW, showLegend, true, false); } else if (chartType == ChartType.CATEGORY_LINE) { chart = ChartFactory.createLineChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else { throw new IllegalArgumentException("Unknown chart type " + chartType + " for a category dataset."); } if (chart == null) return null; if (legendPosition != LegendPosition.NONE) { chart.getLegend().setPosition(legendPosition.getRectangleEdge()); //chart.getTitle().setPadding(4,4,15,4); } if (chart.getPlot() instanceof MultiplePiePlot) { MultiplePiePlot mplot = (MultiplePiePlot) chart.getPlot(); PiePlot plot = (PiePlot) mplot.getPieChart().getPlot(); plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE); if (showLegend) { // for now, legend and items labels are mutually exclusive. Could make this a user pref. plot.setLabelGenerator(null); } } if (!c.isAutoYAxisRange()) { CategoryPlot plot = chart.getCategoryPlot(); ValueAxis axis = plot.getRangeAxis(); axis.setAutoRange(false); axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange()); } 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()); }/* w w w . j av a2 s . c om*/ 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.ewhoxford.swt.bloodpressure.ui.MeasurePageTab.java
/** * Creates a chart./*from w w w. j ava2s .c o m*/ * * @param dataset * a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset, XYPlot bpMeasureXYPlot) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Blood Pressure Measure", // title "time(s)", // x-axis label "Pressure(mmHg)", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); bpMeasureXYPlot = (XYPlot) chart.getPlot(); bpMeasureXYPlot.setBackgroundPaint(Color.lightGray); bpMeasureXYPlot.setDomainGridlinePaint(Color.white); bpMeasureXYPlot.setRangeGridlinePaint(Color.white); // bpMeasureXYPlot.setAxisOffset(new RectangleInsets(300, 0, 0, // BOUNDARY_NUMBER_OF_POINTS)); // bpMeasureXYPlot.setDomainCrosshairVisible(true); // bpMeasureXYPlot.setRangeCrosshairVisible(true); XYItemRenderer r = bpMeasureXYPlot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } ValueAxis axis = bpMeasureXYPlot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); // axis.setRange(0, 1000); axis.setAutoRange(true); axis = bpMeasureXYPlot.getRangeAxis(); axis.setRange(0, 300.0); // DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); // axis.setRange(0, 1000); return chart; }
From source file:org.jfree.chart.demo.CloneTest1.java
private JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Clone Test 1", "Time", "Value", xydataset, true, true, false);//from ww w . j a va 2s . c om XYPlot xyplot = (XYPlot) jfreechart.getPlot(); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(60000D); return jfreechart; }
From source file:monitoring.suhu.DynamicCharts.java
private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart("Temperature Graph", "Time", "Celcius", dataset, true, true, false); final XYPlot plot = result.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds axis = plot.getRangeAxis();/*from w ww .j ava 2 s. co m*/ axis.setRange(0.0, 50.0); return result; }