List of usage examples for org.jfree.chart.plot XYPlot getDomainAxis
public ValueAxis getDomainAxis()
From source file:org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
/** * Creates a chart.//w w w. j a va2 s .c o m * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); lt.setBackgroundPaint(new Color(200, 200, 255, 100)); lt.setFrame(new BlockBorder(Color.white)); lt.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, RectangleAnchor.BOTTOM_RIGHT); ta.setMaxWidth(0.48); plot.addAnnotation(ta); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setLowerMargin(0.35); return chart; }
From source file:eu.stratosphere.addons.visualization.swt.SWTJobTabItem.java
private ChartComposite initializeCPUChart(Composite parentComposite, TableXYDataset dataset) { final JFreeChart chart = ChartFactory.createStackedXYAreaChart("CPU", "Time [sec.]", "Average CPU utilization [%]", dataset, PlotOrientation.VERTICAL, true, true, false); // Set axis properly final XYPlot xyPlot = chart.getXYPlot(); xyPlot.getDomainAxis().setAutoRange(true); xyPlot.getDomainAxis().setAutoRangeMinimumSize(60); xyPlot.getRangeAxis().setAutoRange(false); xyPlot.getRangeAxis().setRange(0, 100); return new ChartComposite(parentComposite, SWT.NONE, chart, true); }
From source file:eu.stratosphere.addons.visualization.swt.SWTJobTabItem.java
private ChartComposite initializeNetworkChart(Composite parentComposite, TableXYDataset dataset) { final JFreeChart chart = ChartFactory.createStackedXYAreaChart("Network", "Time [sec.]", "Average throughput [MBit/s]", dataset, PlotOrientation.VERTICAL, true, true, false); // Set axis properly final XYPlot xyPlot = chart.getXYPlot(); xyPlot.getDomainAxis().setAutoRange(true); xyPlot.getDomainAxis().setAutoRangeMinimumSize(60); // TODO: Repair auto range for range axis xyPlot.getRangeAxis().setAutoRange(false); xyPlot.getRangeAxis().setRange(0, 4096); return new ChartComposite(parentComposite, SWT.NONE, chart, true); }
From source file:no.ntnu.mmfplanner.ui.graph.NpvChart.java
/** * Creates the main chart, but does not fill inn any data *//*from w w w .j a v a 2 s . c o m*/ private void createChart() { JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title "Period", // x axis label "Discounted Cash", // y axis label null, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.getDomainAxis().setTickMarksVisible(false); setChart(chart); setMouseZoomable(false); }
From source file:eu.stratosphere.addons.visualization.swt.SWTJobTabItem.java
private ChartComposite initializeMemoryChart(Composite parentComposite, TableXYDataset dataset) { final JFreeChart chart = ChartFactory.createStackedXYAreaChart("Memory", "Time [sec.]", "Average amount of memory allocated [MB]", dataset, PlotOrientation.VERTICAL, true, true, false); // Set axis properly final XYPlot xyPlot = chart.getXYPlot(); xyPlot.getDomainAxis().setAutoRange(true); xyPlot.getDomainAxis().setAutoRangeMinimumSize(60); // Workaround because auto range does not seem to work properly on the range axis final InstanceVisualizationData instanceVisualizationData = (InstanceVisualizationData) this.visualizationData .getNetworkTopology().getAttachment(); xyPlot.getRangeAxis().setAutoRange(false); xyPlot.getRangeAxis().setRange(0, instanceVisualizationData.getUpperBoundForMemoryChart()); return new ChartComposite(parentComposite, SWT.NONE, chart, true); }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.tasks.ChromatogramViewLoaderWorker.java
private void configurePlot(XYPlot plot, RTUnit rtAxisUnit) { NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setNumberFormatOverride(new RTNumberFormatter(rtAxisUnit)); domainAxis.setLabel("RT[" + rtAxisUnit.name().toLowerCase() + "]"); plot.setRangeZeroBaselineVisible(true); plot.setDomainZeroBaselineVisible(false); domainAxis.setAutoRange(true);/* w w w .j av a 2 s. c o m*/ domainAxis.setAutoRangeIncludesZero(false); ((NumberAxis) plot.getRangeAxis()).setAutoRange(true); ((NumberAxis) plot.getRangeAxis()).setAutoRangeIncludesZero(true); Logger.getLogger(getClass().getName()).info("Adding chart"); plot.setBackgroundPaint(Color.WHITE); }
From source file:net.sf.maltcms.chromaui.charts.overlay.Peak1DHeatmapOverlay.java
/** * * @param g2//from w ww . j a v a 2 s.c om * @param chartPanel */ @Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { if (isVisible()) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Color c = g2.getColor(); Color fillColor = peakAnnotations.getColor(); if (fillColor == null || fillColor.equals(Color.WHITE) || fillColor.equals(new Color(255, 255, 255, 0))) { Logger.getLogger(getClass().getName()) .info("Peak annotation color was null or white, using color from treatment group!"); fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor(); } g2.setColor(ChartCustomizer.withAlpha(fillColor, 0.5f)); for (IPeakAnnotationDescriptor descr : peakAnnotations.getMembers()) { double x = descr.getApexTime(); double xx = xAxis.valueToJava2D(x, dataArea, xAxisEdge); double width = xAxis.valueToJava2D(1, dataArea, xAxisEdge); double mzRange = (descr.getMassValues()[descr.getMassValues().length - 1] - descr.getMassValues()[0]); double y = mzRange / 2.0d; double yy = yAxis.valueToJava2D(y, dataArea, yAxisEdge); double height = yAxis.valueToJava2D(mzRange, dataArea, yAxisEdge); AffineTransform at = AffineTransform.getTranslateInstance(xx, yy); at.concatenate(AffineTransform.getTranslateInstance(-x, -y)); Rectangle2D.Double r = new Rectangle2D.Double(xx - (width / 2.0d), yy, width, height); g2.fill(at.createTransformedShape(r)); } g2.setColor(c); g2.setClip(savedClip); } }
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateChartByType(String title, String xLabel, String yLabel, Dataset dataset, String outputdir, String type, String filename) throws IOException { JFreeChart jChart = null;/*from ww w .j a v a2 s . c o m*/ if ("line".equalsIgnoreCase(type)) { jChart = ChartFactory.createLineChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } else if ("bar".equalsIgnoreCase(type)) { System.out.println("Setting up jChart"); jChart = ChartFactory.createBarChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); System.out.println("Writing image...."); } else if ("xyline".equalsIgnoreCase(type)) { jChart = ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } if ("xyline".equalsIgnoreCase(type)) { XYPlot plot = (XYPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); domain.setAutoRangeIncludesZero(false); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } else { CategoryPlot plot = (CategoryPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); CategoryAxis domain = (CategoryAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + filename + ".png"), jChart, 900, 500); }
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;/* ww w .jav a 2 s . c o m*/ 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; }
From source file:sim.app.sugarscape.Charts.java
JFreeChart createEvolution() { JFreeChart chart = ChartFactory.createXYLineChart("Evolution of Mean Agent Vision and Metabolism", "Time", "Level", model.evolution_vision_coll, PlotOrientation.VERTICAL, true, true, false); model.evolution_chart = chart;/*from w w w .j a v a 2s. com*/ NumberAxis rangeAxis1 = new NumberAxis("Time"); rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); org.jfree.chart.axis.NumberAxis domainAxis = new NumberAxis("Bins"); XYPlot plot = chart.getXYPlot(); ValueAxis xAxis = plot.getDomainAxis(); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.BLACK); plot.setDataset(1, model.evolution_metabolism_coll); renderer.setSeriesPaint(1, Color.BLUE); return chart; }