List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis
public NumberAxis(String label)
From source file:statistic.graph.gui.Charts.java
private static void initXAxis(XYPlot plot, XYDataset dataset) { plot.setDomainAxis(new NumberAxis(plot.getDomainAxis().getLabel())); XYSeriesCollection collection = (XYSeriesCollection) dataset; double max = Double.NEGATIVE_INFINITY; double min = Double.POSITIVE_INFINITY; if (collection != null) { for (int s = 0; s < collection.getSeriesCount(); s++) { for (int d = 0; d < collection.getItemCount(s); d++) { XYDataItem data = collection.getSeries(s).getDataItem(d); if (data.getX().longValue() == Integer.MAX_VALUE || data.getX().longValue() == Integer.MIN_VALUE) { continue; }//from www. j a va 2s . c om if (data.getX().doubleValue() > max) { max = data.getX().doubleValue(); } if (data.getX().doubleValue() < min) { min = data.getX().doubleValue(); } } } if (min < max) { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(min - 0.5, max + 0.5); for (int s = 0; s < collection.getSeriesCount(); s++) { XYSeries series = collection.getSeries(s); if (series.indexOf(Integer.MIN_VALUE) >= 0) { XYDataItem item = series.remove((Number) Integer.MIN_VALUE); if (series.indexOf(min) < 0) { series.add(min, item.getY()); } } if (series.indexOf(Integer.MAX_VALUE) >= 0) { XYDataItem item = series.remove((Number) Integer.MAX_VALUE); if (series.indexOf(max) < 0) { series.add(max, item.getY()); } } } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(0 - 0.5, 1 + 0.5); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(0 - 0.5, 1 + 0.5); } }
From source file:org.mwc.cmap.grideditor.chart.Date2ValueManager.java
public ValueAxis createYAxis() { final NumberAxis result = new NumberAxis(null); result.setAutoRangeIncludesZero(false); return result; }
From source file:org.jfree.chart.demo.AnnotationDemo2.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset1(); JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit", xydataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); NumberAxis numberaxis1 = new NumberAxis("Secondary"); numberaxis1.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createDataset2()); xyplot.mapDatasetToRangeAxis(1, 1);/*from www. j a va 2 s .c o m*/ XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D, 167.30000000000001D, -0.78539816339744828D); xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); xypointerannotation.setPaint(Color.red); xypointerannotation.setArrowPaint(Color.red); xylineandshaperenderer.addAnnotation(xypointerannotation); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true); xylineandshaperenderer1.setSeriesPaint(0, Color.black); xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D, 613.20000000000005D, 1.5707963267948966D); xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER); xylineandshaperenderer1.addAnnotation(xypointerannotation1); xyplot.setRenderer(1, xylineandshaperenderer1); LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer); LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1); 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:org.jfree.eastwood.GValueAxis.java
/** * Creates a new axis.// ww w . j a va 2s.c om */ public GValueAxis() { super(); this.axisForAutoLabels = new NumberAxis(null); this.axisForAutoLabels.setRange(0.0, 100.0); this.axisForAutoLabels.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); this.labelAxisStart = 0.0; this.labelAxisEnd = 100.0; this.tickLabels = new java.util.ArrayList(); this.tickLabelPositions = new java.util.ArrayList(); setLowerMargin(0.0); setUpperMargin(0.0); // the data is normalised into the range 0.0 to 1.0, so the real axis // has the same range... setRange(0.0, 1.0); setTickLabelPaint(Color.darkGray); setTickLabelFont(new Font("Dialog", Font.PLAIN, 11)); }
From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java
@Override protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) { XYDatasetWrapper mainDataset = datasetWrappers[0]; JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time", mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // all adjustments for first/main dataset plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum()); plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum()); // some additional "design" stuff for the plot plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor()); plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke())); for (int i = 1; i < datasetWrappers.length; i++) { XYDatasetWrapper wrapper = datasetWrappers[i]; plot.setDataset(i, wrapper.getDataset()); chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName()); NumberAxis axis = new NumberAxis(wrapper.getSeriesName()); plot.setRangeAxis(i, axis);//from ww w. j a v a2 s . c o m plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0); plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0); // map the second dataset to the second axis plot.mapDatasetToRangeAxis(i, i); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke())); plot.setRenderer(i, renderer); plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor()); } // change the background and gridline colors plot.setBackgroundPaint(Color.white); plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // format the date axis DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm")); axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1)); axis.setVerticalTickLabels(true); return chart; }
From source file:org.esa.beam.smos.visat.GridPointBtDataChartToolView.java
@Override protected JComponent createGridPointComponent() { coPolDataset = new YIntervalSeriesCollection(); crossPolDataset = new YIntervalSeriesCollection(); chart = ChartFactory.createXYLineChart(null, null, null, coPolDataset, PlotOrientation.VERTICAL, true, // Legend? true, false);/*from ww w . jav a 2s .c om*/ plot = chart.getXYPlot(); plot.setNoDataMessage("No data"); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); final NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setLabel("Incidence Angle (deg)"); xAxis.setRange(0, 70); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); final NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel("Co-Pol BT(K)"); yAxis.setRange(50, 350); final NumberAxis yAxis2 = new NumberAxis("Cross-Pol BT(K)"); yAxis2.setRange(-25, 25); plot.setRangeAxis(1, yAxis2); plot.setDataset(1, crossPolDataset); plot.mapDatasetToRangeAxis(1, 1); DeviationRenderer coPolRenderer = new DeviationRenderer(true, false); coPolRenderer.setSeriesFillPaint(0, new Color(255, 127, 127)); coPolRenderer.setSeriesFillPaint(1, new Color(127, 127, 255)); DeviationRenderer crossPolRenderer = new DeviationRenderer(true, false); crossPolRenderer.setSeriesFillPaint(0, new Color(127, 255, 127)); crossPolRenderer.setSeriesFillPaint(1, new Color(255, 255, 127)); plot.setRenderer(0, coPolRenderer); plot.setRenderer(1, crossPolRenderer); return new ChartPanel(chart); }
From source file:de.fub.maps.project.detector.model.inference.ui.charts.PrecisionRecallBarChartPanel.java
/** * Creates new form PrecisionRecallBarChartPanel *///from w ww . java 2 s . c om public PrecisionRecallBarChartPanel() { super(); initComponents(); barChart = ChartFactory.createBarChart( NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Chart_Precision_Recall_Name"), NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Doman_Axis_Name"), NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name"), dataset, PlotOrientation.VERTICAL, true, true, true); Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14); barChart.getTitle().setFont(font); barChart.getTitle().setPaint(new Color(153, 153, 153)); plot = barChart.getCategoryPlot(); NumberAxis preciAxis = new NumberAxis( NbBundle.getMessage(PrecisionRecallBarChartPanel.class, "CLT_Value_Axis_Name")); preciAxis.setAutoRange(true); preciAxis.setUpperMargin(.20); plot.setRangeAxis(0, preciAxis); plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); plot.setBackgroundPaint(Color.white); BarRenderer barRenderer = new BarRenderer(); barRenderer.setBarPainter(new StandardBarPainter()); barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat())); barRenderer.setBaseItemLabelsVisible(true); barRenderer.setSeriesPaint(0, precColor); barRenderer.setSeriesPaint(1, recColor); plot.setRenderer(barRenderer); chartPanel = new ChartPanel(barChart, false); chartPanel.setVerticalAxisTrace(false); add(chartPanel, BorderLayout.CENTER); }
From source file:chart.DualAxis.java
/** * Creates a new demo instance./*from www .ja v a2 s .c om*/ * * @param title the frame title. */ public DualAxis(final String title, double[] xData, double[] YDataAnalitic, double[] YDataNumerical) { super(title); final CategoryDataset dataset1 = createDataset1(xData, YDataAnalitic); // create the chart... final JFreeChart chart = ChartFactory.createLineChart("", // chart title "x", // domain axis label "y", // 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(xData, YDataNumerical); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); //final ValueAxis axis2 = new NumberAxis(""); final ValueAxis axis2 = new NumberAxis(" "); 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); // panel.removeAll(); // panel.add(chartPanel); // panel.validate(); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelDetailMass.java
public boolean loadData() { super.loadData(); // Tabelle /* w w w. ja v a 2 s .c o m*/ MassenTableModel m = new MassenTableModel(app.getXmlClient()); m.load(objektNode, t, s); panelMass.setModel(m); panelMass.setObjektNode(objektNode); // Grafik XYDataset xyDataset = new TableModelXYDataset(m, true); StatusItemRenderer statusRenderer = new StatusItemRenderer(m, 2); NumberAxis rangeAxis = new NumberAxis( ChartUtils.getNumberAxisLabel(app.getXmlClient(), objektNode.getId())); DateAxis domainAxis = new DateAxis("Time"); Plot plot = new StatusXYPlot(xyDataset, domainAxis, rangeAxis, statusRenderer); JFreeChart f = new JFreeChart(plot); StandardLegend l = new StandardLegend(f); panelChart.setChart(f); panelChart.setLegend(l); // Link m.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { panelChart.repaint(); } }); return true; }
From source file:org.jfree.chart.demo.OverlaidBarChartDemo1.java
public static JFreeChart createChart() { DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(1.0D, "S1", "Category 1"); dataset1.addValue(4D, "S1", "Category 2"); dataset1.addValue(3D, "S1", "Category 3"); dataset1.addValue(5D, "S1", "Category 4"); dataset1.addValue(5D, "S1", "Category 5"); dataset1.addValue(7D, "S1", "Category 6"); dataset1.addValue(7D, "S1", "Category 7"); dataset1.addValue(8D, "S1", "Category 8"); dataset1.addValue(5D, "S2", "Category 1"); dataset1.addValue(7D, "S2", "Category 2"); dataset1.addValue(6D, "S2", "Category 3"); dataset1.addValue(8D, "S2", "Category 4"); dataset1.addValue(4D, "S2", "Category 5"); dataset1.addValue(4D, "S2", "Category 6"); dataset1.addValue(2D, "S2", "Category 7"); dataset1.addValue(1.0D, "S2", "Category 8"); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); dataset2.addValue(9D, "T1", "Category 1"); dataset2.addValue(7D, "T1", "Category 2"); dataset2.addValue(2D, "T1", "Category 3"); dataset2.addValue(6D, "T1", "Category 4"); dataset2.addValue(6D, "T1", "Category 5"); dataset2.addValue(9D, "T1", "Category 6"); dataset2.addValue(5D, "T1", "Category 7"); dataset2.addValue(4D, "T1", "Category 8"); DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); dataset3.addValue(94D, "R1", "Category 1"); dataset3.addValue(75D, "R1", "Category 2"); dataset3.addValue(22D, "R1", "Category 3"); dataset3.addValue(74D, "R1", "Category 4"); dataset3.addValue(83D, "R1", "Category 5"); dataset3.addValue(9D, "R1", "Category 6"); dataset3.addValue(23D, "R1", "Category 7"); dataset3.addValue(98D, "R1", "Category 8"); ///*from www . ja v a 2 s .co m*/ StandardCategoryItemLabelGenerator standardcategoryitemlabelgenerator = new StandardCategoryItemLabelGenerator(); BarRenderer renderer1 = new BarRenderer(); renderer1.setBaseItemLabelGenerator(standardcategoryitemlabelgenerator); renderer1.setBaseItemLabelsVisible(true); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); LineAndShapeRenderer renderer3 = new LineAndShapeRenderer(); //plot CategoryPlot plot = new CategoryPlot(); plot.setDataset(dataset1); plot.setRenderer(renderer1); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setDataset(2, dataset3); plot.setRenderer(2, renderer3); plot.setDomainAxis(new CategoryAxis("Category")); //more rangeAxis plot.setRangeAxis(new NumberAxis("Value")); plot.setRangeAxis(1, new NumberAxis("Axis 2")); plot.mapDatasetToRangeAxis(2, 1); // plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); //chart JFreeChart chart = new JFreeChart(plot); chart.setTitle("Overlaid Bar Chart"); return chart; }