List of usage examples for org.jfree.chart.plot XYPlot setRangeAxis
public void setRangeAxis(ValueAxis axis)
From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java
public static JFreeChart createStackedAreaChart(String title, XYSeriesCollection areaData, XYSeriesCollection lineData, String xLabel, String yLabel, ColorTheme theme) { final ValueAxis xAxis = new NumberAxis(xLabel); final ValueAxis yAxis = new NumberAxis(yLabel); XYPlot mainPlot = new XYPlot(); mainPlot.setDomainAxis(xAxis);//from www . jav a2s . c o m mainPlot.setRangeAxis(yAxis); mainPlot.setForegroundAlpha(0.9f); //[ stacked area DefaultTableXYDataset areaDs = new DefaultTableXYDataset(); for (int i = 0; i < areaData.getSeriesCount(); i++) { areaDs.addSeries(areaData.getSeries(i)); } XYItemRenderer stackedRenderer = new StackedXYAreaRenderer2(); mainPlot.setDataset(areaDs); mainPlot.setRenderer(stackedRenderer); Color[] colors = generateJetSpectrum(areaData.getSeriesCount()); for (int i = 0; i < areaData.getSeriesCount(); i++) { stackedRenderer.setSeriesPaint(i, colors[i]); } //] //[ lines if (lineData != null) { XYItemRenderer lineRenderer = new StandardXYItemRenderer(); DefaultTableXYDataset lineDs = new DefaultTableXYDataset(); for (int i = 0; i < lineData.getSeriesCount(); i++) { lineDs.addSeries(lineData.getSeries(i)); } mainPlot.setDataset(1, lineDs); mainPlot.setRenderer(1, lineRenderer); colors = new Color[] { Color.black, Color.red, Color.darkGray }; for (int i = 0; i < lineData.getSeriesCount(); i++) { lineRenderer.setSeriesPaint(i, colors[i % colors.length]); lineRenderer.setSeriesStroke(i, new BasicStroke(2f)); } } //] mainPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true); formatColorTheme(chart, theme); return chart; }
From source file:osproject.Drawer.java
private static JFreeChart createChart(IntervalXYDataset paramIntervalXYDataset) { JFreeChart localJFreeChart = ChartFactory.createXYBarChart("Procssing schadual", "Resource", false, "Timing", paramIntervalXYDataset, PlotOrientation.HORIZONTAL, true, false, false); localJFreeChart.setBackgroundPaint(Color.BLACK); XYPlot localXYPlot = (XYPlot) localJFreeChart.getPlot(); SymbolAxis localSymbolAxis = new SymbolAxis("Process", arr); localSymbolAxis.setGridBandsVisible(false); localXYPlot.setDomainAxis(localSymbolAxis); XYBarRenderer localXYBarRenderer = (XYBarRenderer) localXYPlot.getRenderer(); localXYBarRenderer.setUseYInterval(true); localXYPlot.setRangeAxis(new DateAxis("Timing")); ChartUtilities.applyCurrentTheme(localJFreeChart); return localJFreeChart; }
From source file:de.laures.cewolf.taglib.CewolfChartFactory.java
public static JFreeChart getOverlaidChartInstance(String chartType, String title, String xAxisLabel, String yAxisLabel, int xAxisType, int yAxisType, List plotDefinitions) throws ChartValidationException, DatasetProduceException { final int chartTypeConst = getChartTypeConstant(chartType); final AxisFactory axisFactory = AxisFactory.getInstance(); switch (chartTypeConst) { case OVERLAY_XY: ValueAxis domainAxis = (ValueAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel);/* w w w . j a v a 2s. co m*/ // get main plot PlotDefinition mainPlotDef = (PlotDefinition) plotDefinitions.get(0); check((Dataset) mainPlotDef.getDataset(), XYDataset.class, chartType); XYPlot plot = (XYPlot) mainPlotDef.getPlot(chartTypeConst); plot.setDomainAxis(domainAxis); plot.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel)); //plot.setRenderer(new StandardXYItemRenderer()); // add second and later datasets to main plot for (int plotidx = 1; plotidx < plotDefinitions.size(); plotidx++) { PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx); check((Dataset) subPlotDef.getDataset(), XYDataset.class, chartType); plot.setDataset(plotidx, (XYDataset) subPlotDef.getDataset()); int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType()); XYItemRenderer rend = (XYItemRenderer) PlotTypes.getRenderer(rendererIndex); plot.setRenderer(plotidx, rend); } return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); case OVERLAY_CATEGORY://added by lrh 2005-07-11 CategoryAxis domainAxis2 = (CategoryAxis) axisFactory.createAxis(ORIENTATION_HORIZONTAL, xAxisType, xAxisLabel); // get main plot mainPlotDef = (PlotDefinition) plotDefinitions.get(0); check((Dataset) mainPlotDef.getDataset(), CategoryDataset.class, chartType); CategoryPlot plot2 = (CategoryPlot) mainPlotDef.getPlot(chartTypeConst); plot2.setDomainAxis(domainAxis2); plot2.setRangeAxis((ValueAxis) axisFactory.createAxis(ORIENTATION_VERTICAL, yAxisType, yAxisLabel)); //plot.setRenderer(new StandardXYItemRenderer()); // add second and later datasets to main plot for (int plotidx = 1; plotidx < plotDefinitions.size(); plotidx++) { PlotDefinition subPlotDef = (PlotDefinition) plotDefinitions.get(plotidx); check((Dataset) subPlotDef.getDataset(), CategoryDataset.class, chartType); plot2.setDataset(plotidx, (CategoryDataset) subPlotDef.getDataset()); int rendererIndex = PlotTypes.getRendererIndex(subPlotDef.getType()); CategoryItemRenderer rend2 = (CategoryItemRenderer) PlotTypes.getRenderer(rendererIndex); plot2.setRenderer(plotidx, rend2); } return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot2, true); default: throw new UnsupportedChartTypeException(chartType + " is not supported."); } }
From source file:org.matsim.contrib.dvrp.util.chart.ScheduleChartUtils.java
public static <T extends Task> JFreeChart chartSchedule(List<? extends Vehicle> vehicles, DescriptionCreator<T> descriptionCreator, PaintSelector<T> paintSelector) { // data/* w w w . ja va2s. c o m*/ TaskSeriesCollection dataset = createScheduleDataset(vehicles, descriptionCreator); XYTaskDataset xyTaskDataset = new XYTaskDataset(dataset); // chart JFreeChart chart = ChartFactory.createXYBarChart("Schedules", "Time", false, "Vehicles", xyTaskDataset, PlotOrientation.HORIZONTAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // Y axis String[] series = new String[vehicles.size()]; for (int i = 0; i < series.length; i++) { series[i] = vehicles.get(i).getId().toString(); } SymbolAxis symbolAxis = new SymbolAxis("Vehicles", series); symbolAxis.setGridBandsVisible(false); plot.setDomainAxis(symbolAxis); // X axis plot.setRangeAxis(new DateAxis("Time", TimeZone.getTimeZone("GMT"), Locale.getDefault())); // Renderer XYBarRenderer xyBarRenderer = new ChartTaskRenderer<T>(dataset, paintSelector); xyBarRenderer.setUseYInterval(true); plot.setRenderer(xyBarRenderer); return chart; }
From source file:org.matsim.contrib.dvrp.util.chart.ScheduleCharts.java
public static JFreeChart chartSchedule(Collection<? extends Vehicle> vehicles, DescriptionCreator descriptionCreator, PaintSelector paintSelector) { // data//from w w w .j a v a2 s .com TaskSeriesCollection dataset = createScheduleDataset(vehicles, descriptionCreator); XYTaskDataset xyTaskDataset = new XYTaskDataset(dataset); // chart JFreeChart chart = ChartFactory.createXYBarChart("Schedules", "Time", false, "Vehicles", xyTaskDataset, PlotOrientation.HORIZONTAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // Y axis String[] series = new String[vehicles.size()]; int i = 0; for (Vehicle v : vehicles) { series[i++] = v.getId().toString(); } SymbolAxis symbolAxis = new SymbolAxis("Vehicles", series); symbolAxis.setGridBandsVisible(false); plot.setDomainAxis(symbolAxis); // X axis plot.setRangeAxis(new DateAxis("Time", TimeZone.getTimeZone("GMT"), Locale.getDefault())); // Renderer XYBarRenderer xyBarRenderer = new ChartTaskRenderer(dataset, paintSelector); xyBarRenderer.setUseYInterval(true); plot.setRenderer(xyBarRenderer); return chart; }
From source file:PerformanceGraph.java
/** * Plots the performance graph of the best fitness value so far versus the * number of function calls (NFC).//from w w w .j av a 2 s. c o m * * @param bestFitness A linked hashmap mapping the NFC to the best fitness value * found so far. * @param fitnessFunction The name of the fitness function, used for the title and the * name of the file that is saved, e.g. "De Jong". */ public static void plot(LinkedHashMap<Integer, Double> bestFitness, String fitnessFunction) { /* Create an XYSeries plot */ XYSeries series = new XYSeries("Best Fitness Value Vs. Number of Function Calls"); /* Add the NFC and best fitness value data to the series */ for (Integer NFC : bestFitness.keySet()) { /* Jfreechart crashes if double values are too large! */ if (bestFitness.get(NFC) <= 10E12) { series.add(NFC.doubleValue(), bestFitness.get(NFC).doubleValue()); } } /* Add the x,y series data to the dataset */ XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); /* Plot the data as an X,Y line chart */ JFreeChart chart = ChartFactory.createXYLineChart("Best Fitness Value Vs. Number of Function Calls", "Number of Function Calls (NFC)", "Best Fitness Value", dataset, PlotOrientation.VERTICAL, false, true, false); /* Configure the chart settings such as anti-aliasing, background colour */ chart.setAntiAlias(true); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); plot.setDomainGridlinePaint(Color.black); /* Set the domain range from 0 to NFC */ NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(0.0, ControlVariables.MAX_FUNCTION_CALLS.doubleValue()); /* Logarithmic range axis */ plot.setRangeAxis(new LogAxis()); /* Set the thickness and colour of the lines */ XYItemRenderer renderer = plot.getRenderer(); BasicStroke thickLine = new BasicStroke(3.0f); renderer.setSeriesStroke(0, thickLine); renderer.setPaint(Color.BLACK); /* Display the plot in a JFrame */ ChartFrame frame = new ChartFrame(fitnessFunction + " Best Fitness Value", chart); frame.setVisible(true); frame.setSize(1000, 600); /* Save the plot as an image named after fitness function try { ChartUtilities.saveChartAsJPEG(new File("plots/" + fitnessFunction + ".jpg"), chart, 1600, 900); } catch (IOException e) { e.printStackTrace(); }*/ }
From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java
private static JFreeChart createStackedXYAreaChart(TableXYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0);/*from w ww . j a v a 2 s . c o m*/ xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator); renderer.setOutline(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setRangeAxis(yAxis); // forces recalculation of the axis range JFreeChart chart = new JFreeChart("StackedXYArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); 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); return chart; }
From source file:org.jfree.chart.demo.CompassFormatDemo1.java
private static JFreeChart createChart() { XYDataset xydataset = createDirectionDataset(600); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", xydataset, true, true, false);//from w w w .j av a 2 s . c om XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.getDomainAxis().setLowerMargin(0.0D); xyplot.getDomainAxis().setUpperMargin(0.0D); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); TickUnits tickunits = new TickUnits(); tickunits.add(new NumberTickUnit(180D, new CompassFormat())); tickunits.add(new NumberTickUnit(90D, new CompassFormat())); tickunits.add(new NumberTickUnit(45D, new CompassFormat())); tickunits.add(new NumberTickUnit(22.5D, new CompassFormat())); numberaxis.setStandardTickUnits(tickunits); xyplot.setRangeAxis(numberaxis); XYAreaRenderer xyarearenderer = new XYAreaRenderer(); NumberAxis numberaxis1 = new NumberAxis("Force"); numberaxis1.setRange(0.0D, 12D); xyarearenderer.setSeriesPaint(0, new Color(0, 0, 255, 128)); xyplot.setDataset(1, createForceDataset(600)); xyplot.setRenderer(1, xyarearenderer); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); return jfreechart; }
From source file:de.aidger.view.utils.Charts.java
/** * Creates a xy area chart.//ww w . ja v a2 s . c o m * * @param title * the diagram title * @param dataset * the dataset. * @param width * the width of the chart as image * @param height * the height of the chart as image * @return the xy area chart as image */ public static ImageIcon createXYAreaChart(String title, XYDataset dataset, int width, int height) { JFreeChart chart = ChartFactory.createXYAreaChart(title, "", "", dataset, PlotOrientation.VERTICAL, false, false, false); Font titleFont = UIManager.getFont("TitledBorder.font"); chart.setBackgroundPaint(null); chart.getTitle().setFont(new Font(titleFont.getName(), titleFont.getStyle(), 14)); chart.getTitle().setPaint(UIManager.getColor("TitledBorder.titleColor")); chart.setBorderPaint(null); XYPlot plot = chart.getXYPlot(); plot.setInsets(new RectangleInsets(10, 1, 5, 1)); plot.setBackgroundPaint(null); plot.setOutlineVisible(false); plot.setNoDataMessage(_("No data to display.")); ValueAxis domainAxis = new DateAxis(); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setTickLabelFont(UIManager.getFont("RootPane.font")); ValueAxis rangeAxis = new NumberAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); plot.setDomainAxis(domainAxis); plot.setRangeAxis(rangeAxis); plot.setForegroundAlpha(0.5f); return new ImageIcon(chart.createBufferedImage(width, height)); }
From source file:ec.ui.view.AutoCorrelationsView.java
private static JFreeChart createAutoCorrelationsViewChart() { JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); result.setPadding(TsCharts.CHART_PADDING); XYPlot plot = result.getXYPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false);//from ww w .j a va 2s .co m renderer.setDrawBarOutline(true); renderer.setAutoPopulateSeriesPaint(false); renderer.setAutoPopulateSeriesOutlinePaint(false); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); NumberAxis domainAxis = new NumberAxis(); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); return result; }