List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis
public NumberAxis(String label)
From source file:peakml.util.jfreechart.FastTimePlot.java
public FastTimePlot(String xlabel, String ylabel) { // create the x-axis xaxis = new NumberAxis(xlabel); xaxis.setPlot(this); xaxis.setAutoRange(false);//from w w w . ja va 2s .c om xaxis.addChangeListener(this); xaxis.setNumberFormatOverride(new java.text.NumberFormat() { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { if (number > 3600) { int hrs = (int) (number / 3600); return toAppendTo.append(String.format("%02d:%02d:%02d", hrs, (int) ((number / 60) - hrs * 60), (int) (number % 60))); } return toAppendTo.append(String.format("%02d:%02d", (int) (number / 60), (int) (number % 60))); } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return null; } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } private static final long serialVersionUID = -6728259541513959179L; }); // create the y-axis yaxis = new NumberAxis(ylabel); yaxis.setPlot(this); yaxis.setAutoRange(false); yaxis.addChangeListener(this); }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChart.java
/** * Set up the X and Y axes.//from w w w .ja va2s. c o m */ public void setAxes() { XYPlot xyplot = chart.getXYPlot(); String ylabel = showdelta ? KstatResources.getString("CHART.RATE") : KstatResources.getString("CHART.VALUE"); NumberAxis loadaxis = new NumberAxis(ylabel); loadaxis.setAutoRange(true); loadaxis.setAutoRangeIncludesZero(true); xyplot.setRangeAxis(loadaxis); DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME")); daxis.setAutoRange(true); // let a sequnce show its full date range if (!(jkstat instanceof SequencedJKstat)) { daxis.setFixedAutoRange(maxage); } xyplot.setDomainAxis(daxis); }
From source file:wsattacker.plugin.intelligentdos.ui.helper.ChartHelper.java
public static JFreeChart createOverlaidChart(SuccessfulAttack sa) { // create subplot 1... final XYSeries data1 = createDatasetResponseTime(RequestType.UNTAMPERED, sa.getUntamperedMetrics()); final XYSeries data2 = createDatasetResponseTime(RequestType.TAMPERED, sa.getTamperedMetrics()); final XYSeries data3 = createDatasetResponseTime(RequestType.TESTPROBES, sa.getTestProbes()); final XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(data1);//from w w w. j a va 2 s . com collection.addSeries(data2); collection.addSeries(data3); final XYItemRenderer renderer = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("duration in ms"); final XYPlot plot = new XYPlot(collection, new NumberAxis(""), rangeAxis1, renderer); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesPaint(1, Color.RED); renderer.setSeriesPaint(2, Color.BLUE); // return a new chart containing the overlaid plot... return new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.kurento.test.latency.ChartWriter.java
public void drawChart(String filename, int width, int height) throws IOException { // Create plot NumberAxis xAxis = new NumberAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYSplineRenderer renderer = new XYSplineRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); // Create chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartUtilities.applyCurrentTheme(chart); ChartPanel chartPanel = new ChartPanel(chart, false); // Draw png// w ww. j a va 2s. c om BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics graphics = bi.getGraphics(); chartPanel.setBounds(0, 0, width, height); chartPanel.paint(graphics); ImageIO.write(bi, "png", new File(filename)); }
From source file:statistic.graph.XYChart.java
private void initXAxis(String label) { plot.setDomainAxis(new NumberAxis(label)); double max = Double.NEGATIVE_INFINITY; double min = Double.POSITIVE_INFINITY; 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; }/*w ww . jav a 2s . c om*/ if (data.getX().doubleValue() > max) { max = data.getX().doubleValue(); } if (data.getX().doubleValue() < min) { min = data.getX().doubleValue(); } } } plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setRange(min - 0.5, max + 0.5); }
From source file:ta4jexamples.analysis.CashFlowToChart.java
/** * Adds the cash flow axis to the plot.// w w w .j a v a 2 s. co m * @param plot the plot * @param dataset the cash flow dataset */ private static void addCashFlowAxis(XYPlot plot, TimeSeriesCollection dataset) { final NumberAxis cashAxis = new NumberAxis("Cash Flow Ratio"); cashAxis.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, cashAxis); plot.setDataset(1, dataset); plot.mapDatasetToRangeAxis(1, 1); final StandardXYItemRenderer cashFlowRenderer = new StandardXYItemRenderer(); cashFlowRenderer.setSeriesPaint(0, Color.blue); plot.setRenderer(1, cashFlowRenderer); }
From source file:org.matsim.analysis.LegHistogramChart.java
static JFreeChart getGraphic(final LegHistogram.DataFrame dataFrame, final String mode, int iteration) { final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries departuresSerie = new XYSeries("departures", false, true); final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true); final XYSeries onRouteSerie = new XYSeries("en route", false, true); int onRoute = 0; for (int i = 0; i < dataFrame.countsDep.length; i++) { onRoute = onRoute + dataFrame.countsDep[i] - dataFrame.countsArr[i] - dataFrame.countsStuck[i]; double hour = i * dataFrame.binSize / 60.0 / 60.0; departuresSerie.add(hour, dataFrame.countsDep[i]); arrivalsSerie.add(hour, dataFrame.countsArr[i]); onRouteSerie.add(hour, onRoute); }//from w w w . j av a 2s . c o m xyData.addSeries(departuresSerie); xyData.addSeries(arrivalsSerie); xyData.addSeries(onRouteSerie); final JFreeChart chart = ChartFactory.createXYStepChart("Leg Histogram, " + mode + ", it." + iteration, "time", "# persons", xyData, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("time")); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f)); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); plot.setDomainGridlinePaint(Color.gray); return chart; }
From source file:de.hs.mannheim.modUro.controller.diagram.BoxAndWhiskerPlotController.java
/** * Plots Data for Chart// w ww .j a va2 s . c o m */ private void boxWhiskerPlot() { BoxAndWhiskerCategoryDataset dataset = createDataset(); CategoryAxis xAxis = new CategoryAxis("Model"); NumberAxis yAxis = new NumberAxis("Fitness"); yAxis.setRange(0.0, 1.0); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.2); renderer.setItemMargin(0.5); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); final JFreeChart chart = new JFreeChart("Model comparison", new Font("Palatino", Font.BOLD, 14), plot, true); chart.removeLegend(); ChartViewer viewer = new ChartViewer(chart, this); boxWhiskerPane.setCenter(viewer); }
From source file:org.jfree.chart.demo.SymbolicChartDemo1.java
/** * A demonstration application.//from ww w . j a v a 2 s . c o m * * @param title * the frame title. */ public SymbolicChartDemo1(final String title) { super(title); // create a title... final XYDataset dataset = createDataset(); final ValueAxis domainAxis = new NumberAxis("X"); final SymbolicAxis symbolicAxis = new SymbolicAxis("Y", ((YisSymbolic) dataset).getYSymbolicValues()); final XYPlot plot = new XYPlot(dataset, domainAxis, symbolicAxis, null); final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, new SymbolicXYItemLabelGenerator()); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart(title, plot); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:sim.app.sugarscape.Charts.java
JFreeChart createCultureTagChart() { JFreeChart chart = ChartFactory.createXYLineChart("Culture Tag Time Series", "Time", "Fraction Blue", model.culture_tag_coll, PlotOrientation.VERTICAL, true, true, false); model.culture_tag_chart = chart;/*from w w w . j av a 2 s . c om*/ NumberAxis rangeAxis1 = new NumberAxis("Time"); rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot = chart.getXYPlot(); ValueAxis xAxis = plot.getDomainAxis(); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.BLACK); return chart; }