List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis
public NumberAxis(String label)
From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo2.java
private static JFreeChart createTimeSeriesChart(XYDataset dataset) { //DomainAxis//from w w w . j a v a 2 s. c om DateAxis timeAxis = new DateAxis(""); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); //RangeAxis NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); // override default // valueAxis.setDefaultAutoRange(new Range(100, 1150)); //Renderer XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYURLGenerator urlGenerator = null; // urlGenerator = new StandardXYURLGenerator(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); //AbstractRenderer.dataBoundsIncludesVisibleSeriesOnly renderer.setDataBoundsIncludesVisibleSeriesOnly(false); renderer.setBaseSeriesVisibleInLegend(true); //Plot XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null) { private static final long serialVersionUID = 1L; // public void rendererChanged(RendererChangeEvent event) { // // if the event was caused by a change to series visibility, then // // the axis ranges might need updating... // if (event.getSeriesVisibilityChanged()) { //// configureDomainAxes(); //// configureRangeAxes(); // } // fireChangeEvent(); // } }; plot.setRenderer(renderer); plot.setBackgroundPaint(plotBackgroundPaint); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // plot.setRangePannable(true); //chart JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); valueAxis.setAutoRange(false); timeAxis.setAutoRange(false); return chart; }
From source file:org.spantus.exp.segment.draw.AbstractGraphGenerator.java
public JFreeChart getChart(ComparisionResult result) { CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time")); plot.setGap(10.0);/*from w w w .ja v a 2 s. c om*/ plot.setOrientation(PlotOrientation.VERTICAL); XYSeriesCollection[] seriesArr = createSeries(result); for (XYSeriesCollection series : seriesArr) { XYSeriesCollection data = series; StandardXYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.BLACK); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setLabel(((XYSeries) series.getSeries().get(0)).getDescription()); rangeAxis.setAutoRange(true); XYPlot subplot = new XYPlot(data, null, rangeAxis, renderer); plot.add(subplot); } String name = result.getName() == null ? "Segmentation" : "Segmentation: " + result.getName(); JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, true); return chart; }
From source file:org.jfree.chart.demo.CompassFormatDemo.java
/** * Creates a sample chart./*from www. ja v a2s .co m*/ * * @return a sample chart. */ private JFreeChart createChart() { final XYDataset direction = createDirectionDataset(600); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); // configure the range axis to display directions... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); final TickUnits units = new TickUnits(); units.add(new NumberTickUnit(180.0, new CompassFormat())); units.add(new NumberTickUnit(90.0, new CompassFormat())); units.add(new NumberTickUnit(45.0, new CompassFormat())); units.add(new NumberTickUnit(22.5, new CompassFormat())); rangeAxis.setStandardTickUnits(units); // add the wind force with a secondary dataset/renderer/axis plot.setRangeAxis(rangeAxis); final XYItemRenderer renderer2 = new XYAreaRenderer(); final ValueAxis axis2 = new NumberAxis("Force"); axis2.setRange(0.0, 12.0); renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128)); plot.setDataset(1, createForceDataset(600)); plot.setRenderer(1, renderer2); plot.setRangeAxis(1, axis2); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java
public JFreeChart getChart(List<String> idsToPaint) throws ParseException, UnitException { if (varX == null || varY == null || varX.getName() == null || varY.getName() == null) { return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, new XYPlot(), showLegend); }// w w w. j a v a2 s . co m NumberAxis xAxis = new NumberAxis(varX.getDisplayString()); NumberAxis yAxis = new NumberAxis(varY.getDisplayString()); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); double usedMinX = Double.POSITIVE_INFINITY; double usedMaxX = Double.NEGATIVE_INFINITY; int index = 0; List<Color> defaultColors = ChartUtils.createColorList(idsToPaint.size()); List<NamedShape> defaultShapes = ChartUtils.createShapeList(idsToPaint.size()); for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY || plotable.getType() == Plotable.Type.FUNCTION || plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) { double minArg = varX.to(MathUtils.nullToNan(plotable.getMinValues().get(varX.getName())), plotable.getUnits().get(varX.getName())); double maxArg = varX.to(MathUtils.nullToNan(plotable.getMaxValues().get(varX.getName())), plotable.getUnits().get(varX.getName())); if (Double.isFinite(minArg)) { usedMinX = Math.min(usedMinX, minArg); } if (Double.isFinite(maxArg)) { usedMaxX = Math.max(usedMaxX, maxArg); } } if (plotable.getType() == Plotable.Type.BOTH || plotable.getType() == Plotable.Type.BOTH_MANY) { for (Map<String, Integer> choice : plotable.getAllChoices(varX.getName())) { double[][] points = plotable.getPoints(varX, varY, choice); if (points != null) { for (int i = 0; i < points[0].length; i++) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } } if (plotable.getType() == Plotable.Type.DATASET || plotable.getType() == Plotable.Type.DATASET_MANY) { double[][] points = plotable.getPoints(varX, varY); if (points != null) { for (int i = 0; i < points[0].length; i++) { usedMinX = Math.min(usedMinX, points[0][i]); usedMaxX = Math.max(usedMaxX, points[0][i]); } } } if (plotable.getType() == Plotable.Type.FUNCTION_SAMPLE) { for (Double x : plotable.getSamples()) { if (x != null && Double.isFinite(x)) { usedMinX = Math.min(usedMinX, x); usedMaxX = Math.max(usedMaxX, x); } } } } if (Double.isInfinite(usedMinX)) { usedMinX = 0.0; } if (Double.isInfinite(usedMaxX)) { usedMaxX = 100.0; } if (varX.getName().equals(PmmUtils.TIME) || varX.getName().equals(PmmUtils.CONCENTRATION)) { usedMinX = Math.min(usedMinX, 0.0); xAxis.setAutoRangeIncludesZero(true); } else { xAxis.setAutoRangeIncludesZero(false); } if (varY.getName().equals(PmmUtils.TIME) || varY.getName().equals(PmmUtils.CONCENTRATION)) { yAxis.setAutoRangeIncludesZero(true); } else { yAxis.setAutoRangeIncludesZero(false); } if (usedMinX == usedMaxX) { usedMinX -= 1.0; usedMaxX += 1.0; } if (useManualRange && minX < maxX && minY < maxY) { usedMinX = minX; usedMaxX = maxX; xAxis.setRange(new Range(minX, maxX)); yAxis.setRange(new Range(minY, maxY)); } for (String id : idsToPaint) { Plotable plotable = plotables.get(id); if (plotable == null) { continue; } plotable.setFunctionSteps(resolution); switch (plotable.getType()) { case DATASET: plotDataSet(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index)); break; case DATASET_MANY: plotDataSetStrict(plot, plotable, id); break; case FUNCTION: plotFunction(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case FUNCTION_SAMPLE: plotFunctionSample(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case BOTH: plotBoth(plot, plotable, id, defaultColors.get(index), defaultShapes.get(index), usedMinX, usedMaxX); break; case BOTH_MANY: plotBothStrict(plot, plotable, id, usedMinX, usedMaxX); break; default: throw new RuntimeException("Unknown type of plotable: " + plotable.getType()); } index++; } return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, showLegend); }
From source file:sanger.team16.gui.genevar.eqtl.query.SNPGeneAssocPlot.java
private JFreeChart createChart(String populationName, CategoryDataset categoryDataset, double max, double min) { CategoryAxis categoryaxis = new CategoryAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD); //categoryaxis.setMaximumCategoryLabelWidthRatio(5F); //categoryaxis.setMaximumCategoryLabelLines(141); //categoryaxis.setCategoryMargin(450); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); lineandshaperenderer.setBaseShapesFilled(false); lineandshaperenderer.setBaseShape(ShapeUtilities.createDiamond((float) 3)); lineandshaperenderer.setBaseSeriesVisibleInLegend(false); //lineandshaperenderer.setBaseLinesVisible(false); lineandshaperenderer.setAutoPopulateSeriesShape(false); lineandshaperenderer.setAutoPopulateSeriesPaint(false); //lineandshaperenderer.findRangeBounds(categoryDataset); NumberAxis numberaxis = new NumberAxis("Expression"); numberaxis.setAutoRangeIncludesZero(false); //numberaxis.setRangeWithMargins(min, max); CategoryPlot categoryplot = new CategoryPlot(categoryDataset, categoryaxis, numberaxis, lineandshaperenderer);//from w w w.ja v a 2 s .c om categoryplot.setDomainGridlinesVisible(false); categoryplot.setOrientation(PlotOrientation.VERTICAL); JFreeChart jfreechart = new JFreeChart(populationName, new Font("SansSerif", 1, 14), categoryplot, true); return jfreechart; }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Build a new box-plot from an array of numbers using a default title and yLabel. * String dataName will be used for xLabel. * @param numbers Numbers for building box-plot * @param dataName Name of the numbers data * @return Prepared box-plot/*ww w .jav a 2 s . c o m*/ */ public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) { if (numbers == null || numbers.length == 0) { return null; } DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); final ArrayList<Number> list = new ArrayList<Number>(); list.addAll(Arrays.asList(numbers)); final String valuesString = getMessage("ChartsUtils.report.box-plot.values"); dataset.add(list, valuesString, ""); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMeanVisible(false); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.5); final CategoryAxis xAxis = new CategoryAxis(dataName); final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range")); yAxis.setAutoRangeIncludesZero(false); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setRenderer(renderer); JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot); return boxPlot; }