List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis
public NumberAxis(String label)
From source file:ucar.unidata.idv.control.chart.HistogramWrapper.java
/** * Plot the displayed {@link DataChoice}. * //from w ww.j a v a 2s.c o m * @param histoWrapper Cannot be {@code null}. */ public static void plotHistogram(HistogramWrapper histoWrapper) { XYPlot p = histoWrapper.plot; List<DataChoiceWrapper> dcWrappers = histoWrapper.getDataChoiceWrappers(); try { for (int dataSetIdx = 0; dataSetIdx < p.getDatasetCount(); dataSetIdx++) { MyHistogramDataset dataset = (MyHistogramDataset) p.getDataset(dataSetIdx); dataset.removeAllSeries(); } Hashtable props = new Hashtable(); props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE); for (int paramIdx = 0; paramIdx < dcWrappers.size(); paramIdx++) { DataChoiceWrapper wrapper = dcWrappers.get(paramIdx); DataChoice dataChoice = wrapper.getDataChoice(); FlatField data = histoWrapper.getFlatField((FieldImpl) dataChoice.getData(null, props)); Unit unit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0]; double[][] samples = data.getValues(false); double[] actualValues = histoWrapper.filterData(samples[0], histoWrapper.getTimeValues(samples, data))[0]; NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit)); XYItemRenderer renderer; if (histoWrapper.stacked) { renderer = new StackedXYBarRenderer(); } else { renderer = new XYBarRenderer(); } p.setRenderer(paramIdx, renderer); Color c = wrapper.getColor(paramIdx); domainAxis.setLabelPaint(c); renderer.setSeriesPaint(0, c); MyHistogramDataset dataset = new MyHistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries(dataChoice.getName() + " [" + unit + "]", actualValues, histoWrapper.bins); p.setDomainAxis(paramIdx, domainAxis, false); p.mapDatasetToDomainAxis(paramIdx, paramIdx); p.setDataset(paramIdx, dataset); } } catch (VisADException | RemoteException e) { LogUtil.logException("Error creating data set", e); } }
From source file:com.projity.pm.graphic.chart.ChartHelper.java
/** * Creates a new chart.//from www. java2 s . c o m * * @param dataset * the dataset. * * @return The chart. */ public static JFreeChart createBarChart(final XYDataset dataset) { ValueAxis domainAxis = null; NumberAxis axis = new NumberAxis(null); axis.setAutoRangeIncludesZero(false); domainAxis = axis; ValueAxis valueAxis = new NumberAxis(null); XYItemRenderer barRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, new StandardXYToolTipGenerator(), null); XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, barRenderer); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); removeAxisAndInsets(chart); return chart; }
From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java
protected JFreeChart getPredictedTargetsChart(TSForecaster forecaster, ErrorModule preds, List<String> targetNames, int stepNumber, int instanceNumOffset, Instances data) { if (forecaster instanceof TSLagUser && data != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) { // fill in any missing time stamps only data = new Instances(data); data = weka.classifiers.timeseries.core.Utils.replaceMissing(data, null, lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries()); }//from www . j av a 2 s.com } // set up a collection of predicted and actual series XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection(); for (String target : targetNames) { XYIntervalSeries targetSeries = new XYIntervalSeries(target + "-actual", false, false); xyDataset.addSeries(targetSeries); targetSeries = new XYIntervalSeries(target + "-predicted", false, false); xyDataset.addSeries(targetSeries); } ValueAxis timeAxis = null; NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); int timeIndex = -1; boolean timeAxisIsDate = false; if (forecaster instanceof TSLagUser && data != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) { String timeName = lagMaker.getTimeStampField(); if (data.attribute(timeName).isDate()) { timeAxis = new DateAxis(""); timeAxisIsDate = true; timeIndex = data.attribute(timeName).index(); } } } if (timeAxis == null) { timeAxis = new NumberAxis(""); ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false); } // now populate the series boolean hasConfidenceIntervals = false; for (int i = 0; i < targetNames.size(); i++) { String targetName = targetNames.get(i); List<NumericPrediction> predsForI = preds.getPredictionsForTarget(targetName); int predIndex = xyDataset.indexOf(targetName + "-predicted"); int actualIndex = xyDataset.indexOf(targetName + "-actual"); XYIntervalSeries predSeries = xyDataset.getSeries(predIndex); XYIntervalSeries actualSeries = xyDataset.getSeries(actualIndex); for (int j = 0; j < predsForI.size(); j++) { double x = Utils.missingValue(); if (timeAxisIsDate) { if (instanceNumOffset + j + stepNumber - 1 < data.numInstances()) { x = data.instance(instanceNumOffset + j + stepNumber - 1).value(timeIndex); } } else { x = instanceNumOffset + j + stepNumber; } double yPredicted = predsForI.get(j).predicted(); double yHigh = yPredicted; double yLow = yPredicted; double[][] conf = predsForI.get(j).predictionIntervals(); if (conf.length > 0) { yLow = conf[0][0]; yHigh = conf[0][1]; hasConfidenceIntervals = true; } if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yPredicted)) { if (predSeries != null) { predSeries.add(x, x, x, yPredicted, yLow, yHigh); } // System.err.println("* " + yPredicted + " " + x); } double yActual = predsForI.get(j).actual(); if (!Utils.isMissingValue(x) && !Utils.isMissingValue(yActual)) { if (actualSeries != null) { actualSeries.add(x, x, x, yActual, yActual, yActual); } } } } // set up the chart String title = "" + stepNumber + " step-ahead predictions for: "; for (String s : targetNames) { title += s + ","; } title = title.substring(0, title.lastIndexOf(",")); /* * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec * + ")"; */ if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) { double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0; title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]"; } XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseLinesVisible(true); renderer.setDrawXError(false); renderer.setDrawYError(true); // renderer.setShapesFilled(true); XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(java.awt.Color.white); TextTitle chartTitle = chart.getTitle(); String fontName = chartTitle.getFont().getFontName(); java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12); chartTitle.setFont(newFont); return chart; }
From source file:org.ietr.preesm.mapper.ui.stats.PerformancePlotter.java
/** * Creates a chart in order to plot the speed-ups. * /*from www. j a v a 2 s .c o m*/ * @return A chart. */ private JFreeChart createChart(String title) { // Creating display domain NumberAxis horizontalAxis = new NumberAxis("Number of operators"); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(horizontalAxis); // Creating the best speedups subplot this.speedups = new DefaultXYDataset(); final NumberAxis xAxis = new NumberAxis("speedups"); xAxis.setAutoRangeIncludesZero(false); XYSplineRenderer renderer = new XYSplineRenderer(); final XYPlot subplot = new XYPlot(this.speedups, null, xAxis, renderer); subplot.setBackgroundPaint(Color.white); subplot.setDomainGridlinePaint(Color.lightGray); subplot.setRangeGridlinePaint(Color.lightGray); plot.add(subplot); plot.setForegroundAlpha(0.5f); final JFreeChart chart = new JFreeChart(title, plot); chart.setBorderPaint(Color.white); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); return chart; }
From source file:com.mugarov.neview.view.GraphPanel.java
public void setValues(ArrayList<DotBag> dotBags, ArrayList<Median> lines, String name) { CoordinateSeries ser;//from w w w . ja va 2 s . c om for (DotBag db : dotBags) { ser = new CoordinateSeries(db.getName()); for (Dot d : db) { ser.add(d.getCoordinates(), d.getName(), d.getScaffoldName()); // System.out.println("New dot:"+d.getLogX()+", "+d.getLogY()); } this.dotSeries.add(ser); } for (Median med : lines) { ser = new CoordinateSeries(med.getName()); ser.add(med.getStart(), med.getName(), null); ser.add(med.getEnd(), med.getName(), null); // System.out.println("New line from " + med.getStart().getX()+","+ med.getStart().getY()+" to "+med.getEnd().getX()+","+ med.getEnd().getY()); this.lineSeries.add(ser); } this.seriesCollection = new CoordinateSeriesCollection(); for (CoordinateSeries dotSeries : this.dotSeries) { this.seriesCollection.addSeries(dotSeries); } for (CoordinateSeries line : this.lineSeries) { this.seriesCollection.addSeries(line); } this.chart = ChartFactory.createXYLineChart(name, GraphPanel.XAxis, GraphPanel.YAxis, this.seriesCollection, PlotOrientation.VERTICAL, true, true, false); this.chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); ExpAxis x1Axis = new ExpAxis(GraphPanel.XAxis); ExpAxis y1Axis = new ExpAxis(GraphPanel.YAxis); NumberAxis x2Axis = new NumberAxis("Proportion to max of " + GraphPanel.XAxis); NumberAxis y2Axis = new NumberAxis("Proportion to max of " + GraphPanel.YAxis); plot.setDomainAxis(0, x1Axis); plot.setDomainAxis(1, x2Axis); plot.setRangeAxis(0, y1Axis); plot.setRangeAxis(1, y2Axis); // plot.setDomainAxis(1, yAxis); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 0; i < this.dotSeries.size(); i++) { renderer.setSeriesLinesVisible(i, false); renderer.setSeriesPaint(i, this.colorGen.get(i)); } for (int i = this.dotSeries.size(); i < this.lineSeries.size() + this.dotSeries.size(); i++) { renderer.setSeriesShapesVisible(i, false); // renderer.setSeriesPaint(i, Color.black); renderer.setSeriesPaint(i, this.colorGen.get(i - this.dotSeries.size())); } renderer.setBaseToolTipGenerator(new ItemGenerator()); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.MAGENTA); plot.setRangeGridlinePaint(Color.MAGENTA); boolean add = (this.chartPanel == null); this.chartPanel = new ChartPanel(chart); if (add) { this.content.add(this.chartPanel, BorderLayout.CENTER); this.scroll.setViewportView(this.chartPanel); } this.setBackground(Color.green); this.chartPanel.setBackground(Color.MAGENTA); this.updateUI(); }
From source file:org.jfree.chart.demo.DualAxisDemo.java
/** * Creates a new demo instance./*from www .j a v a 2 s . c om*/ * * @param title the frame title. */ public DualAxisDemo(final String title) { super(title); final CategoryDataset dataset1 = createDataset1(); // create the chart... final JFreeChart chart = ChartFactory.createBarChart("Dual Axis Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset1, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URL generator? Not required... ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // chart.getLegend().setAnchor(Legend.SOUTH); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF)); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); final CategoryDataset dataset2 = createDataset2(); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); final ValueAxis axis2 = new NumberAxis("Secondary"); plot.setRangeAxis(1, axis2); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:com.bdb.weather.display.freeplot.FreePlot.java
/** * Constructor./* w w w .j a v a 2s . c o m*/ * * @param seriesFactory The factory for creating the series * @param controlFactory The factory for creating the controls */ @SuppressWarnings("LeakingThisInConstructor") FreePlot(SeriesCollectionFactory seriesFactory) { controls = seriesFactory.createSeriesGroupControls(this); factory = seriesFactory; this.setTop(createDataRangeSelectionPanel()); this.setLeft(createDataSelectionPanel(controls.values())); ChartViewer chartViewer = new ChartViewer(new JFreeChart(plot)); chartViewer.setMaxHeight(20000); chartViewer.setMaxWidth(20000); this.setCenter(chartViewer); // // Create a default Y Axis // DateAxis dateAxis = new DateAxis("Date/Time"); plot.setDomainAxis(dateAxis); plot.setRangeAxis(new NumberAxis("Data")); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); buildStrokes(); }
From source file:org.yooreeka.util.gui.XyLogGui.java
public XyLogGui(String title, double[] x, double[] y) { super(title); errMsg = new StringBuilder(); setLoopInt(x.length);/* w w w . jav a 2 s .c o m*/ if (checkX(x) && checkY(x.length, y)) { XYSeries xydata = new XYSeries(title); for (int i = 0; i < loopInt; i++) { if (x[i] == C.ZERO_DOUBLE || x[i] < 0) { x[i] = C.SMALL_DOUBLE; } if (y[i] == C.ZERO_DOUBLE || y[i] < 0) { y[i] = C.SMALL_DOUBLE; } xydata.add(x[i], y[i]); } xycollection = new XYSeriesCollection(xydata); final JFreeChart chart = ChartFactory.createXYLineChart(title + " (XY Plot)", "X", "Y", xycollection, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); final NumberAxis domainAxis = new NumberAxis("x"); plot.setDomainAxis(domainAxis); final NumberAxis logRangeAxis = new LogarithmicAxis("Log(y)"); plot.setRangeAxis(logRangeAxis); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); } else { System.err.println(errMsg.toString()); } }
From source file:org.jfree.chart.demo.DualAxisDemo1.java
private static JFreeChart createChart() { JFreeChart jfreechart = ChartFactory.createBarChart("Dual Axis Chart", "Category", "Value", createDataset1(), PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(Color.white); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(new Color(238, 238, 255)); categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryDataset categorydataset = createDataset2(); categoryplot.setDataset(1, categorydataset); categoryplot.mapDatasetToRangeAxis(1, 1); CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); NumberAxis numberaxis = new NumberAxis("Secondary"); categoryplot.setRangeAxis(1, numberaxis); LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(); lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); categoryplot.setRenderer(1, lineandshaperenderer); categoryplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); LegendTitle legendtitle = new LegendTitle(categoryplot.getRenderer(0)); legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle.setFrame(new BlockBorder()); LegendTitle legendtitle1 = new LegendTitle(categoryplot.getRenderer(1)); legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D)); legendtitle1.setFrame(new BlockBorder()); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.add(legendtitle, RectangleEdge.LEFT); blockcontainer.add(legendtitle1, RectangleEdge.RIGHT); blockcontainer.add(new EmptyBlock(2000D, 0.0D)); CompositeTitle compositetitle = new CompositeTitle(blockcontainer); compositetitle.setPosition(RectangleEdge.BOTTOM); jfreechart.addSubtitle(compositetitle); return jfreechart; }
From source file:edu.ucla.stat.SOCR.chart.demo.BoxAndWhiskerChartDemo1.java
/** * Creates a sample chart./*from www . j av a2s .co m*/ * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(BoxAndWhiskerCategoryDataset dataset) { CategoryAxis domainAxis = new CategoryAxis(null); NumberAxis rangeAxis = new NumberAxis(rangeLabel); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); renderer.setLegendItemLabelGenerator( new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT)); //RowCount -- serie count if (dataset.getColumnCount() * dataset.getRowCount() < 5) { domainAxis.setLowerMargin(0.2); domainAxis.setUpperMargin(0.2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(0.5); // domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2); /* System.out.println("1lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ } else if (dataset.getColumnCount() * dataset.getRowCount() < 10) { domainAxis.setLowerMargin(domainAxis.getLowerMargin() * 2); domainAxis.setUpperMargin(domainAxis.getUpperMargin() * 2); if (dataset.getColumnCount() == 1) renderer.setItemMargin(renderer.getItemMargin() * 2); else domainAxis.setCategoryMargin(domainAxis.getCategoryMargin() * 2); /*System.out.println("2lowerMargin="+domainAxis.getLowerMargin()); System.out.println("ItemMargin="+renderer.getItemMargin()); System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/ } if (legendPanelOn) chart.removeLegend(); return chart; }