List of usage examples for org.jfree.chart.axis NumberAxis NumberAxis
public NumberAxis(String label)
From source file:org.matsim.contrib.socnetsim.usage.analysis.CourtesyHistogramListener.java
static JFreeChart getGraphic(final CourtesyHistogram.DataFrame dataFrame, int iteration, String actType) { final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries helloSeries = new XYSeries("hello", false, true); final XYSeries goodbyeSerie = new XYSeries("goodbye", false, true); final XYSeries togetherSerie = new XYSeries("pairs together", false, true); int together = 0; for (int i = 0; i < dataFrame.countsHello.length; i++) { together = together + dataFrame.countsHello[i] - dataFrame.countsGoodbye[i]; double hour = i * dataFrame.binSize / 60.0 / 60.0; helloSeries.add(hour, dataFrame.countsHello[i]); goodbyeSerie.add(hour, dataFrame.countsGoodbye[i]); togetherSerie.add(hour, together); }//from w w w . java 2 s . com xyData.addSeries(helloSeries); xyData.addSeries(goodbyeSerie); xyData.addSeries(togetherSerie); final JFreeChart chart = ChartFactory.createXYStepChart( "Courtesy Statistics," + "actType " + actType + " 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:LoggerGUI.DataLogger.java
public DataLogger(String title) { super(title); initialize();//from w w w. j a va 2 s . c o m final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time")); this.datasets = new TimeSeriesCollection[INPUT_COUNT]; this.lastValue[0] = 100.0; this.lastValue[1] = 100.0; this.lastValue[2] = 100.0; this.lastValue[3] = 100.0; final TimeSeries s0 = new TimeSeries("A0", Millisecond.class); final TimeSeries s1 = new TimeSeries("A1", Millisecond.class); final TimeSeries s2 = new TimeSeries("A2", Millisecond.class); final TimeSeries s3 = new TimeSeries("A3", Millisecond.class); this.datasets[0] = new TimeSeriesCollection(s0); this.datasets[1] = new TimeSeriesCollection(s1); this.datasets[2] = new TimeSeriesCollection(s2); this.datasets[3] = new TimeSeriesCollection(s3); final NumberAxis rangeAxis = new NumberAxis("ADC Signal"); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot; XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,false); XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true,false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true,false); XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(true,false); subplot= new XYPlot( new TimeSeriesCollection(), null, rangeAxis, new XYLineAndShapeRenderer(true,false) ); plot.add(subplot); renderer.setBaseShapesVisible(false); renderer.setSeriesPaint(0, Color.red); subplot.setDataset(0,datasets[0]); subplot.setRenderer(0,renderer); renderer1.setBaseShapesVisible(false); renderer1.setSeriesPaint(0, Color.blue); subplot.setDataset(1,datasets[1]); subplot.setRenderer(1,renderer1); renderer2.setBaseShapesVisible(false); renderer2.setSeriesPaint(0, Color.black); subplot.setDataset(2,datasets[2]); subplot.setRenderer(2,renderer2); subplot.getRendererForDataset(subplot.getDataset(0)).setSeriesPaint(0, Color.red); subplot.getRendererForDataset(subplot.getDataset(1)).setSeriesPaint(1, Color.blue); subplot.getRendererForDataset(subplot.getDataset(2)).setSeriesPaint(2, Color.black); renderer3.setBaseShapesVisible(false); renderer3.setSeriesPaint(0, Color.green); subplot.setDataset(3,datasets[3]); subplot.setRenderer(3,renderer3); final JFreeChart chart = new JFreeChart("Data Logger", plot); chart.setBorderPaint(Color.black); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(20000.0); // 60 seconds final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JPanel buttonPanel = new JPanel(new FlowLayout()); content.add(buttonPanel, BorderLayout.NORTH); chartPanel.setPreferredSize(new java.awt.Dimension(600, 600)); chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(content); }
From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java
private JFreeChart createChart(CheapTimeSolution solution) { TangoColorFactory tangoColorFactory = new TangoColorFactory(); NumberAxis rangeAxis = new NumberAxis("Period"); rangeAxis.setRange(-0.5, solution.getGlobalPeriodRangeTo() + 0.5); XYPlot taskAssignmentPlot = createTaskAssignmentPlot(tangoColorFactory, solution); XYPlot periodCostPlot = createPeriodCostPlot(tangoColorFactory, solution); XYPlot capacityPlot = createAvailableCapacityPlot(tangoColorFactory, solution); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(rangeAxis); combinedPlot.add(taskAssignmentPlot, 5); combinedPlot.add(periodCostPlot, 1); combinedPlot.add(capacityPlot, 1);/*from w w w . j a v a2 s .co m*/ combinedPlot.setOrientation(PlotOrientation.HORIZONTAL); return new JFreeChart("Cheap Power Time Scheduling", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, true); }
From source file:edu.ucla.stat.SOCR.chart.demo.CategoryStepChartDemo1.java
/** * Creates a chart.//from w w w .j a v a 2 s.co m * * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { CategoryItemRenderer renderer = new CategoryStepRenderer(true); CategoryAxis domainAxis = new CategoryAxis(domainLabel); NumberAxis rangeAxis = new NumberAxis(rangeLabel); CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); JFreeChart chart = new JFreeChart(chartTitle, plot); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); AbstractCategoryItemRenderer renderer2 = (AbstractCategoryItemRenderer) plot.getRenderer(); renderer2.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.addCategoryLabelToolTip("Type 1", "The first type."); domainAxis.addCategoryLabelToolTip("Type 2", "The second type."); domainAxis.addCategoryLabelToolTip("Type 3", "The third type."); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLabelAngle(0 * Math.PI / 2.0); // OPTIONAL CUSTOMISATION COMPLETED. setCategorySummary(dataset); if (legendPanelOn) chart.removeLegend(); return chart; }
From source file:org.jfree.chart.demo.DynamicDataDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from ww w . j av a 2 s .c o m */ public DynamicDataDemo2(final String title) { super(title); this.series1 = new TimeSeries("Random 1", Millisecond.class); this.series2 = new TimeSeries("Random 2", Millisecond.class); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(this.series1); final TimeSeriesCollection dataset2 = new TimeSeriesCollection(this.series2); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Dynamic Data Demo 2", "Time", "Value", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds plot.setDataset(1, dataset2); final NumberAxis rangeAxis2 = new NumberAxis("Range Axis 2"); rangeAxis2.setAutoRangeIncludesZero(false); plot.setRenderer(1, new DefaultXYItemRenderer()); plot.setRangeAxis(1, rangeAxis2); plot.mapDatasetToRangeAxis(1, 1); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add To Series 1"); button1.setActionCommand("ADD_DATA_1"); button1.addActionListener(this); final JButton button2 = new JButton("Add To Series 2"); button2.setActionCommand("ADD_DATA_2"); button2.addActionListener(this); final JButton button3 = new JButton("Add To Both"); button3.setActionCommand("ADD_BOTH"); button3.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); buttonPanel.add(button3); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:org.matsim.counts.algorithms.graphs.BiasErrorGraph.java
@Override public JFreeChart createChart(final int nbr) { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_); double[] meanRelError = errorStats.getMeanRelError(); // double[] meanAbsError = errorStats.getMeanAbsError(); double[] meanAbsBias = errorStats.getMeanAbsBias(); for (int h = 0; h < 24; h++) { dataset0.addValue(meanRelError[h], "Mean rel error", Integer.toString(h + 1)); // dataset1.addValue(meanAbsError[h], "Mean abs error", Integer.toString(h + 1)); dataset1.addValue(meanAbsBias[h], "Mean abs bias", Integer.toString(h + 1)); }/*w ww. ja va 2 s . com*/ this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean rel error [%]", dataset0, PlotOrientation.VERTICAL, true, // legend? true, // tooltips? false // URLs? ); CategoryPlot plot = this.chart_.getCategoryPlot(); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, dataset1); plot.mapDatasetToRangeAxis(1, 1); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); plot.setRenderer(0, renderer); final CategoryAxis axis1 = new CategoryAxis("Hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(axis1); // final ValueAxis axis2 = new NumberAxis("Mean abs {bias, error} [veh/h]"); final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]"); plot.setRangeAxis(1, axis2); final ValueAxis axis3 = plot.getRangeAxis(0); axis3.setRange(0.0, 100.0); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator()); renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator()); // renderer2.setSeriesPaint(0, Color.black); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); return this.chart_; }
From source file:guineu.modules.visualization.intensityboxplot.IntensityBoxPlotFrame.java
public IntensityBoxPlotFrame(ParameterSet parameters) { super("", true, true, true, true); String title = "Intensity box plot [" + GuineuCore.getDesktop().getSelectedDataFiles()[0].getDatasetName() + "]"; String xAxisLabel = parameters.getParameter(IntensityBoxPlotParameters.xAxisValueSource).getValue() .toString();//from w w w. j a va 2 s .c o m this.xAxisValueSource = parameters.getParameter(IntensityBoxPlotParameters.xAxisValueSource).getValue(); // create dataset this.selectedFiles = parameters.getParameter(IntensityBoxPlotParameters.dataFiles).getValue(); this.selectedRows = parameters.getParameter(IntensityBoxPlotParameters.selectedRows).getValue(); this.dataset = this.createSampleDataset(); // create new JFreeChart logger.finest("Creating new chart instance"); // chart = ChartFactory.createLineChart(title, xAxisLabel, "Intensity", // dataset, PlotOrientation.VERTICAL, true, true, false); // CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); // set tooltip generator renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); // plot.setRenderer(renderer); // plot.setBackgroundPaint(Color.white); // CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); // xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // set y axis properties final CategoryAxis xAxis = new CategoryAxis("Type"); final NumberAxis yAxis = new NumberAxis("Value"); NumberFormat yAxisFormat = new DecimalFormat("0.0E0"); yAxis.setNumberFormatOverride(yAxisFormat); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); final JFreeChart chart = new JFreeChart("Intensity Box plot", new Font("SansSerif", Font.BOLD, 14), plot, true); chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); // IntensityBoxPlotToolBar toolBar = new IntensityBoxPlotToolBar(this); // add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); // set shape provider IntensityBoxPlotDrawingSupplier shapeSupplier = new IntensityBoxPlotDrawingSupplier(); plot.setDrawingSupplier(shapeSupplier); setTitle(title); setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); pack(); }
From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java
/** * Write a PNG image representation of the Graph to the given output * stream// w ww . j a v a 2 s .c o m * * @param out The output stream to write the PNG bytes to * @throws IOException Indicates a problem writing to the output stream */ public void writeGraphImage(int numServersDisplayed, OutputStream out) throws IOException { ValueAxis xAxis = new DateAxis(MonitorProperties.units(DATE_TIME)); NumberAxis yAxis = new NumberAxis(yAxisUnits); yAxis.setAutoRangeIncludesZero(true); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot xyPlotLine = new XYPlot(xySeriesCollection, xAxis, yAxis, new StandardXYItemRenderer(StandardXYItemRenderer.LINES)); JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, xyPlotLine, true); chart.setBackgroundPaint(java.awt.Color.white); // Increase size of graph height to accommodate large legends for when many servers in the domain int graphAdditionalHeight = GRAPH_INCREMENT_HEIGHT * ((int) (numServersDisplayed / GRAPH_INCREMENT_SERVER_RATIO)); BufferedImage graphImage = chart.createBufferedImage(GRAPH_WIDTH, INITIAL_GRAPH_HEIGHT + graphAdditionalHeight, new ChartRenderingInfo(new StandardEntityCollection())); addNoDataLogoIfEmpty(graphImage); ChartUtilities.writeBufferedImageAsPNG(out, graphImage); // Could try extra two PNG related params: encodeAlpha and compression }
From source file:org.encog.workbench.dialogs.training.ChartPane.java
/** * Create the initial chart.// ww w .j a v a 2s. c o m * @return The chart. */ private JFreeChart createChart() { this.chart = ChartFactory.createXYLineChart(null, "Iteration", "Current Error", this.dataset1, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.getRangeAxis().setFixedDimension(15.0); // AXIS 2 final NumberAxis axis2 = new NumberAxis("Error Improvement"); axis2.setFixedDimension(10.0); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, this.dataset2); plot.mapDatasetToRangeAxis(1, 1); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); ChartUtilities.applyCurrentTheme(this.chart); return this.chart; }
From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkDeltaUtilsChart.java
public JFreeChart createChart() { XYPlot plot = new XYPlot(this.dataset, new NumberAxis("individual income"), new NumberAxis("delta utils"), null);//w w w. j a va 2s . c o m XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); plot.setRenderer(renderer); JFreeChart jchart = new JFreeChart("", plot); return jchart; }