List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis
public NumberAxis(String label)
From source file:org.jfree.chart.demo.DualAxisDemo2.java
/** * A demonstration application showing how to create a time series chart with dual axes. * * @param title the frame title./*from w ww . j a v a2 s . c o m*/ */ public DualAxisDemo2(final String title) { super(title); // create a title... final String chartTitle = "Dual Axis Demo 2"; final XYDataset dataset = createDataset1(); final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset, true, true, false); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); final NumberAxis axis2 = new NumberAxis("Secondary"); axis2.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, axis2); plot.setDataset(1, createDataset2()); plot.mapDatasetToRangeAxis(1, 1); final XYItemRenderer renderer = plot.getRenderer(); renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; rr.setPlotShapes(true); rr.setShapesFilled(true); } final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.black); renderer2.setPlotShapes(true); renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); plot.setRenderer(1, renderer2); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:br.upe.ecomp.dosa.controller.chart.FileBoxplotChartManager.java
private JFreeChart createChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset, boolean logarithmicYAxis) { final CategoryAxis xAxis = new CategoryAxis("Sample"); final NumberAxis yAxis; if (logarithmicYAxis) { yAxis = new LogarithmicAxis("Fitness (Log10)"); ((LogarithmicAxis) yAxis).setExpTickLabelsFlag(true); } else {// w ww . ja v a2 s .co m yAxis = new NumberAxis("Fitness"); } yAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRange(true); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setBaseCreateEntities(true); // renderer.setArtifactPaint(Color.green); renderer.setBaseOutlinePaint(Color.blue); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(title, xAxis.getLabel(), yAxis.getLabel(), dataset, true); final CategoryPlot plot = chart.getCategoryPlot();// new CategoryPlot(dataset, xAxis, yAxis, // renderer); plot.setBackgroundPaint(Color.white); // chart.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setRenderer(renderer); plot.setRangeAxis(yAxis); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartDualAxisGraphSource.java
@Override public JFreeChart createChart(String title, String xLabel, String yLabel, CategoryDataset dataset, boolean legend, boolean graphToolTip) { PlotOrientation orientation = getParam(JFreeChartBarGraphSource.PLOT_ORIENTATION, PlotOrientation.class, JFreeChartBarGraphSource.DEFAULT_PLOT_ORIENTATION); // create the base plot, which is the time series graph JFreeChart dualAxisGraph = ChartFactory.createLineChart(title, xLabel, tsLabel, tsDataset, orientation, legend, graphToolTip, false); // add the bar graph data to the plot dualAxisGraph.getCategoryPlot().setDataset(1, barDataset); // create the second y-axis dualAxisGraph.getCategoryPlot().setRangeAxis(1, new NumberAxis(barLabel)); dualAxisGraph.getCategoryPlot().mapDatasetToRangeAxis(1, 1); // create separate renderers for the time series and bar graphs to be // overlaid on the same plot CategoryLineGraphRenderer tsRenderer = new CategoryLineGraphRenderer(tsData); CategoryBarGraphRenderer barRenderer = new CategoryBarGraphRenderer(barData); setupLineRenderer(tsRenderer);/*from www .ja v a2 s . c om*/ setupBarRenderer(barRenderer); dualAxisGraph.getCategoryPlot().setRenderer(0, tsRenderer); dualAxisGraph.getCategoryPlot().setRenderer(1, barRenderer); return dualAxisGraph; }
From source file:org.aksw.iguana.reborn.charts.datasets.StatisticalBarChartDemo.java
/** * Creates a new demo.//w w w. jav a 2s . co m * * @param title * the frame title. * @throws DocumentException * @throws FileNotFoundException */ public StatisticalBarChartDemo(final String title) throws FileNotFoundException, DocumentException { super(title); final StatisticalCategoryDataset dataset = createDataset(); final CategoryAxis xAxis = new CategoryAxis("Type"); xAxis.setLowerMargin(0.01d); // percentage of space before first bar xAxis.setUpperMargin(0.01d); // percentage of space after last bar xAxis.setCategoryMargin(0.05d); // percentage of space between // categories final ValueAxis yAxis = new NumberAxis("Value"); // define the plot final CategoryItemRenderer renderer = new StatisticalBarRenderer(); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); final JFreeChart chart = new JFreeChart("Statistical Bar Chart Demo", new Font("Helvetica", Font.BOLD, 14), plot, true); ChartUtilities2.saveChartAsPDF(new File("/home/raven/tmp/foo.pdf"), chart, 1000, 300); // chart.setBackgroundPaint(Color.white); // 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:de.fub.maps.project.detector.model.inference.ui.charts.ClassificationBarChart.java
/** * Creates new form ClassificationBarChart *//*from www . jav a 2 s . c om*/ public ClassificationBarChart() { super(); initComponents(); plot = new CustomCategoryPlot(); barChart = new JFreeChart(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Chart_Classify_Name"), null, plot, true); ChartFactory.getChartTheme().apply(barChart); plot.setDomainAxis(new CategoryAxis()); plot.getDomainAxis().setLabel(NbBundle.getMessage(ClassificationBarChart.class, "CLT_Doman_Axis_Name")); plot.setOrientation(PlotOrientation.VERTICAL); Font font = new JLabel().getFont().deriveFont(Font.BOLD, 14); barChart.getTitle().setFont(font); barChart.getTitle().setPaint(new Color(153, 153, 153)); plot.setDataset(0, relDataset); plot.setDataset(1, absDataset); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToRangeAxis(1, 1); NumberAxis relAxis = new NumberAxis( NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Axis_Name")); relAxis.setAutoRange(true); relAxis.setUpperMargin(.20); NumberAxis absAxis = new NumberAxis( NbBundle.getMessage(ClassificationBarChart.class, "CLT_Value_Rel_Axis_Name")); absAxis.setAutoRange(true); absAxis.setUpperMargin(.20); plot.setRangeAxis(0, relAxis); plot.setRangeAxis(1, absAxis); plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); BarRenderer relRenderer = new BarRenderer(); relRenderer.setBasePaint(relColor); relRenderer.setAutoPopulateSeriesPaint(false); relRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); relRenderer.setBarPainter(new StandardBarPainter()); relRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat())); relRenderer.setBaseItemLabelsVisible(true); BarRenderer absRenderer = new BarRenderer(); absRenderer.setBasePaint(absColor); absRenderer.setAutoPopulateSeriesPaint(false); absRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); absRenderer.setBarPainter(new StandardBarPainter()); absRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new CustomNumberFormat())); absRenderer.setBaseItemLabelsVisible(true); plot.setRenderer(0, relRenderer); plot.setRenderer(1, absRenderer); plot.setBackgroundPaint(Color.white); barChart.setBackgroundPaint(Color.white); plot.setRangeGridlinesVisible(false); chartPanel = new ChartPanel(barChart, false); chartPanel.setVerticalAxisTrace(false); chartPanel.setDisplayToolTips(true); chartPanel.setBackground(Color.white); add(chartPanel, BorderLayout.CENTER); }
From source file:ascensionxyplot.AscensionXYPlot.java
/** * Creates a combined chart./*w w w . j a v a 2 s . c o m*/ * * @return The combined chart. */ private JFreeChart createCombinedChart(File dataFile) { // create subplot 1... final XYDataset data1 = createDataset1(dataFile); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Range 1"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // add secondary axis // subplot1.setDataset(1, createDataset2()); // final NumberAxis axis2 = new NumberAxis("Range Axis 2"); // axis2.setAutoRangeIncludesZero(false); // subplot1.setRangeAxis(1, axis2); // subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // subplot1.setRenderer(1, new StandardXYItemRenderer()); // subplot1.mapDatasetToRangeAxis(1, 1); final XYTextAnnotation annotation1 = new XYTextAnnotation("x value", 20.0, 120000.0); final XYTextAnnotation annotation2 = new XYTextAnnotation("y value", 20.0, 110000.0); final XYTextAnnotation annotation3 = new XYTextAnnotation("z value", 20.0, 100000.0); final XYTextAnnotation annotation4 = new XYTextAnnotation("timepoint", 20.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation4.setFont(new Font("SansSerif", Font.PLAIN, 9)); // annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation1); subplot1.addAnnotation(annotation2); subplot1.addAnnotation(annotation3); subplot1.addAnnotation(annotation4); // create subplot 2... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("Is this the title?", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesUnkownFailuresChart.java
@Override protected JFreeChart createGraph() { TimeTableXYDataset dataset = createDataset(); ValueAxis xAxis = new DateAxis(); xAxis.setLowerMargin(0.0);//w ww . j a v a2 s .co m xAxis.setUpperMargin(0.0); Calendar lowerBound = getLowerGraphBound(); xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis()); NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL); yAxis.setRange(0, HUNDRED_PERCENT); XYItemRenderer renderer = new XYBarRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(graphTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.removeLegend(); return chart; }
From source file:com.jbombardier.console.charts.XYTimeChartPanel.java
public XYTimeChartPanel() { DateAxis numberaxis = new DateAxis("Time"); yAxis = new NumberAxis("Count"); yAxis.setAutoRangeIncludesZero(true); XYSplineRenderer renderer = new XYSplineRenderer(); // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); xyplot = new XYPlot(xyseriescollection, numberaxis, yAxis, renderer); xyplot.setBackgroundPaint(Color.white); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.lightGray); // xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); // XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) // xyplot.getRenderer(); // xylineandshaperenderer.setBaseShapesVisible(false); // xylineandshaperenderer.setBaseShapesFilled(false); chart = new JFreeChart("Running threads", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true); /*//from w w w . j a v a2 s . c om * ValueMarker valuemarker1 = new ValueMarker(175D); * valuemarker1.setLabelOffsetType(LengthAdjustmentType.EXPAND); * valuemarker1.setPaint(Color.red); valuemarker1.setLabel("Target Price"); * valuemarker1.setLabelAnchor(RectangleAnchor.TOP_RIGHT); * valuemarker1.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); * xyplot.addRangeMarker(valuemarker1); */ LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); // ChartUtilities.applyCurrentTheme(chart); setLayout(new BorderLayout()); jFreeChartPanel = new ChartPanel(chart); jFreeChartPanel.setMinimumDrawHeight(0); jFreeChartPanel.setMinimumDrawWidth(0); jFreeChartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); jFreeChartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); add(jFreeChartPanel, BorderLayout.CENTER); JPanel controls = new JPanel(new MigLayout("gap 0, ins 0", "[grow,center,fill]", "[grow,center]")); final JCheckBox checkbox = new JCheckBox("Auto-scale"); checkbox.setSelected(true); checkbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleAutoscroll(checkbox.isSelected()); } }); checkbox.setHorizontalAlignment(SwingConstants.RIGHT); controls.add(checkbox, "cell 0 0,alignx center"); add(controls, BorderLayout.SOUTH); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelDetailAggr.java
public boolean loadData() { super.loadData(); AggregationTableModel m = new AggregationTableModel(app.getXmlClient()); m.load(objektNode, t, a);/*from w w w. ja va 2 s .c om*/ panelAggr.setModel(m); panelAggr.setObjektNode(objektNode); // Grafik XYDataset xyDataset = new TableModelXYDataset(m, true); DateAxis domainAxis = new DateAxis("Time"); StringBuffer buf = new StringBuffer(); buf.append(hashf.get(a.getFunctionId())); buf.append(" per "); buf.append(hashi.get(a.getIntervallId())); buf.append(" of "); buf.append(ChartUtils.getNumberAxisLabel(app.getXmlClient(), objektNode.getId())); NumberAxis rangeAxis = new NumberAxis(buf.toString()); int rend = pref.getInt("xyitemrenderer", DefaultXYItemRenderer.LINES); Plot plot = new StatusXYPlot(xyDataset, domainAxis, rangeAxis, new DefaultItemRenderer()); panelChart.setChart(new JFreeChart(plot)); return true; }
From source file:org.apache.qpid.disttest.charting.chartbuilder.StatisticalBarChartBuilder.java
@Override public JFreeChart createChartImpl(String title, String xAxisTitle, String yAxisTitle, final Dataset dataset, PlotOrientation plotOrientation, boolean showLegend, boolean showToolTips, boolean showUrls) { CategoryAxis xAxis = new CategoryAxis(xAxisTitle); ValueAxis yAxis = new NumberAxis(yAxisTitle); CategoryItemRenderer renderer = new StatisticalBarRenderer(); CategoryPlot plot = new CategoryPlot((StatisticalCategoryDataset) dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(title, new Font("Arial", Font.PLAIN, 10), plot, true); chart.getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); return chart; }