List of usage examples for org.jfree.chart.plot XYPlot setRangeAxisLocation
public void setRangeAxisLocation(int index, AxisLocation location)
From source file:com.jaspersoft.studio.jasper.ChartConverter.java
/** * // ww w . jav a 2s . co m */ private Renderable getRenderer(ReportConverter reportConverter, JRChart chart) { JasperReportsConfiguration jContext = (JasperReportsConfiguration) reportConverter .getJasperReportsContext(); String renderType = null; Rectangle2D rectangle = null; ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(jContext.getClassLoader()); if (dataset != null && jfreeChart != null) dataset.removeChangeListener(jfreeChart.getPlot()); renderType = chart.getRenderType();// FIXMETHEME try reuse this sequence if (renderType == null) { renderType = JRPropertiesUtil.getInstance(jContext).getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_RENDER_TYPE); } String themeName = chart.getTheme(); if (themeName == null) { themeName = JRPropertiesUtil.getInstance(jContext).getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_THEME); } ChartTheme theme = ChartUtil.getInstance(jContext).getTheme(themeName); if (theme instanceof SimpleChartTheme) { SimpleChartTheme sct = (SimpleChartTheme) theme; sct.getChartSettings() .setBackgroundImage(getCachedImageProvider(sct.getChartSettings().getBackgroundImage())); sct.getPlotSettings() .setBackgroundImage(getCachedImageProvider(sct.getPlotSettings().getBackgroundImage())); } ChartContext chartContext = null; // Object cc = jContext.getMap().get(chart); // if (cc != null && cc instanceof ChartContext) // chartContext = (ChartContext) cc; // else { chartContext = new ConvertChartContext(chart, jContext); try { jfreeChart = theme.createChart(chartContext); dataset = chartContext.getDataset(); if (jfreeChart == null && chart.getChartType() == JRChart.CHART_TYPE_MULTI_AXIS) { List<JRChartAxis> axis = ((JRDesignMultiAxisPlot) chart.getPlot()).getAxes(); Plot mainPlot = null; int axisNumber = 0; for (JRChartAxis ax : axis) { JRChart chartAxis = ((JRDesignChartAxis) ax).getChart(); if (jfreeChart == null) { jfreeChart = getJFreeChart(reportConverter, chartAxis); mainPlot = jfreeChart.getPlot(); if (mainPlot instanceof CategoryPlot) ((CategoryPlot) mainPlot).setRangeAxisLocation(0, getChartAxisLocation(ax)); else if (mainPlot instanceof XYPlot) ((XYPlot) mainPlot).setRangeAxisLocation(0, getChartAxisLocation(ax)); } else { axisNumber++; JFreeChart axisChart = getJFreeChart(reportConverter, chartAxis); if (mainPlot instanceof CategoryPlot) { CategoryPlot mainCatPlot = (CategoryPlot) mainPlot; if (!(axisChart.getPlot() instanceof CategoryPlot)) continue; // Get the axis and add it to the multi axis chart plot CategoryPlot axisPlot = (CategoryPlot) axisChart.getPlot(); mainCatPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis()); mainCatPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(ax)); // Add the data set and map it to the recently added axis mainCatPlot.setDataset(axisNumber, axisPlot.getDataset()); mainCatPlot.mapDatasetToRangeAxis(axisNumber, axisNumber); // Set the renderer to use to draw the dataset. mainCatPlot.setRenderer(axisNumber, axisPlot.getRenderer()); // Handle any color series for this chart configureAxisSeriesColors(axisPlot.getRenderer(), chartAxis.getPlot()); } else if (mainPlot instanceof XYPlot) { XYPlot mainXyPlot = (XYPlot) mainPlot; if (!(axisChart.getPlot() instanceof XYPlot)) continue; // Get the axis and add it to the multi axis chart plot XYPlot axisPlot = (XYPlot) axisChart.getPlot(); mainXyPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis()); mainXyPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(ax)); // Add the data set and map it to the recently added axis mainXyPlot.setDataset(axisNumber, axisPlot.getDataset()); mainXyPlot.mapDatasetToRangeAxis(axisNumber, axisNumber); // Set the renderer to use to draw the dataset. mainXyPlot.setRenderer(axisNumber, axisPlot.getRenderer()); // Handle any color series for this chart configureAxisSeriesColors(axisPlot.getRenderer(), chartAxis.getPlot()); } } } } } catch (JRException e) { throw new JRRuntimeException(e); } rectangle = new Rectangle2D.Double(0, 0, chart.getWidth(), chart.getHeight()); } finally { Thread.currentThread().setContextClassLoader(oldLoader); } return ChartUtil.getInstance(jContext).getChartRenderableFactory(renderType).getRenderable(jContext, jfreeChart, null, rectangle); }
From source file:sim.app.sugarscape.Charts.java
JFreeChart createGiniChart() { JFreeChart chart3 = ChartFactory.createXYLineChart("Lorenz Curve", "Population Percentage", "Percentage of Total Wealth", new XYSeriesCollection(model.lorenz_curve), PlotOrientation.VERTICAL, true, true, false);//from w ww . j ava2 s. c o m XYPlot plot = chart3.getXYPlot(); ValueAxis yAxis = plot.getRangeAxis(); //xAxis.setFixedDimension(100); yAxis.setFixedDimension(1.0); //yAxis.setRange(0,1); ValueAxis xAxis = plot.getDomainAxis(); xAxis.setFixedDimension(50); //StandardXYItemRenderer XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.black); NumberAxis axis2 = new NumberAxis("Average Agent Vision"); //axis2.setAutoRangeIncludesZero(false); axis2.setRange(0, 12); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision); //plot.setDataset(1, vision); return chart3; }
From source file:org.graphstream.algorithm.measure.ChartMinMaxAverageSeriesMeasure.java
public JFreeChart createChart(PlotParameters params) throws PlotException { XYSeriesCollection minMax = new XYSeriesCollection(); XYSeriesCollection avgCol = new XYSeriesCollection(); XYPlot plot; XYBarRenderer r = new XYBarRenderer(); r.setBarPainter(new StandardXYBarPainter()); r.setMargin(0.35);/*from w w w.j av a2s . c o m*/ minMax.addSeries(min); avgCol.addSeries(series); minMax.addSeries(max); JFreeChart chart = ChartFactory.createXYLineChart(params.title, params.xAxisLabel, params.yAxisLabel, avgCol, params.orientation, params.showLegend, true, false); plot = ((XYPlot) chart.getPlot()); plot.setDataset(1, minMax); plot.setRenderer(1, r); if (separateMinMaxAxis) { NumberAxis minMaxAxis = new NumberAxis("min/max"); plot.setRangeAxis(1, minMaxAxis); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.mapDatasetToRangeAxis(1, 1); } return chart; }
From source file:org.jfree.chart.demo.MultipleAxisDemo2.java
/** * Creates the demo chart.//from w w w. j av a 2 s . c o m * * @return The chart. */ private JFreeChart createChart() { final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 2", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // DOMAIN AXIS 2 final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(1, xAxis2); // RANGE AXIS 2 final NumberAxis yAxis2 = new NumberAxis("Range Axis 2"); plot.setRangeAxis(1, yAxis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToDomainAxis(1, 1); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:org.jfree.chart.demo.MultipleAxisDemo1.java
/** * Creates the demo chart.//from w ww . j a va 2 s .c o m * * @return The chart. */ private JFreeChart createChart() { final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Time of Day", "Primary Range Axis", dataset1, true, true, false); chart.setBackgroundPaint(Color.white); chart.addSubtitle(new TextTitle("Four datasets and four range axes.")); final XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer(); renderer.setPaint(Color.black); // AXIS 2 final NumberAxis axis2 = new NumberAxis("Range Axis 2"); axis2.setAutoRangeIncludesZero(false); axis2.setLabelPaint(Color.red); axis2.setTickLabelPaint(Color.red); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.red); plot.setRenderer(1, renderer2); // AXIS 3 final NumberAxis axis3 = new NumberAxis("Range Axis 3"); axis3.setLabelPaint(Color.blue); axis3.setTickLabelPaint(Color.blue); plot.setRangeAxis(2, axis3); final XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 2); XYItemRenderer renderer3 = new StandardXYItemRenderer(); renderer3.setSeriesPaint(0, Color.blue); plot.setRenderer(2, renderer3); // AXIS 4 final NumberAxis axis4 = new NumberAxis("Range Axis 4"); axis4.setLabelPaint(Color.green); axis4.setTickLabelPaint(Color.green); plot.setRangeAxis(3, axis4); final XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200); plot.setDataset(3, dataset4); plot.mapDatasetToRangeAxis(3, 3); XYItemRenderer renderer4 = new StandardXYItemRenderer(); renderer4.setSeriesPaint(0, Color.green); plot.setRenderer(3, renderer4); return chart; }
From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java
@Override protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) { XYDatasetWrapper mainDataset = datasetWrappers[0]; JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time", mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // all adjustments for first/main dataset plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum()); plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum()); // some additional "design" stuff for the plot plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor()); plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke())); for (int i = 1; i < datasetWrappers.length; i++) { XYDatasetWrapper wrapper = datasetWrappers[i]; plot.setDataset(i, wrapper.getDataset()); chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName()); NumberAxis axis = new NumberAxis(wrapper.getSeriesName()); plot.setRangeAxis(i, axis);/* w w w .ja va2 s . c o m*/ plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0); plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0); // map the second dataset to the second axis plot.mapDatasetToRangeAxis(i, i); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke())); plot.setRenderer(i, renderer); plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor()); } // change the background and gridline colors plot.setBackgroundPaint(Color.white); plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // format the date axis DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm")); axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1)); axis.setVerticalTickLabels(true); return chart; }
From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomSimplePlot.java
@Override protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) { XYDatasetWrapper mainDataset = datasetWrappers[0]; JFreeChart chart = ChartFactory.createXYLineChart(mainDataset.getSeriesName(), "Index", mainDataset.getSeriesName(), mainDataset.getDataset(), PlotOrientation.VERTICAL, true, false, false);//from w w w . j av a2s .c o m XYPlot plot = (XYPlot) chart.getPlot(); // all adjustments for first/main dataset plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum()); plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum()); // some additional "design" stuff for the plot plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor()); plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke())); for (int i = 1; i < datasetWrappers.length; i++) { XYDatasetWrapper wrapper = datasetWrappers[i]; plot.setDataset(i, wrapper.getDataset()); chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName()); NumberAxis axis = new NumberAxis(wrapper.getSeriesName()); plot.setRangeAxis(i, axis); plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0); plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0); // map the second dataset to the second axis plot.mapDatasetToRangeAxis(i, i); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke())); plot.setRenderer(i, renderer); plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor()); } // change the background and gridline colors plot.setBackgroundPaint(Color.white); plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); return chart; }
From source file:uk.co.moonsit.sockets.GraphClient.java
private void setAxes(XYPlot plot, int[] axesIndex) { for (int i = 0; i < datasets.length; i++) { plot.setRangeAxis(axesIndex[i] - 1, getTheRangeAxis(axesIndex[i] - 1)); AxisLocation axloc;//from www. j a v a 2 s .co m if (i % 2 == 0) { axloc = AxisLocation.BOTTOM_OR_LEFT; //System.out.print("L "); } else { axloc = AxisLocation.BOTTOM_OR_RIGHT; //System.out.print("R "); } plot.setRangeAxisLocation(i, axloc); plot.setDataset(i, datasets[i]); //System.out.println(i + " " + (axesIndex[i] - 1)); plot.mapDatasetToRangeAxis(i, axesIndex[i] - 1); final StandardXYItemRenderer renderer = new StandardXYItemRenderer(); //renderer2.setSeriesPaint(0, Color.black); plot.setRenderer(i, renderer); } }
From source file:ucar.unidata.idv.control.chart.ChartHolder.java
/** * add data set/*from ww w . j ava2 s .c o m*/ * * @param dataset dataset * @param rangeAxis axis * @param renderer renderer * @param side which side */ protected void add(XYDataset dataset, ValueAxis rangeAxis, XYItemRenderer renderer, AxisLocation side) { synchronized (chartManager.getMutex()) { XYPlot xyPlot = (XYPlot) plot; xyPlot.setRangeAxis(paramCount, rangeAxis, false); xyPlot.setDataset(paramCount, dataset); xyPlot.mapDatasetToRangeAxis(paramCount, paramCount); xyPlot.setRenderer(paramCount, renderer); if (side != null) { xyPlot.setRangeAxisLocation(paramCount, side); } paramCount++; } }
From source file:com.seagate.kinetic.monitor.view.KineticSpecifiedNodeView.java
private void createStatChart() { TimeSeriesCollection putOpsTsc = new TimeSeriesCollection(putOpsTs); TimeSeriesCollection putTrgTsc = new TimeSeriesCollection(putTrgTs); TimeSeriesCollection getOpsTsc = new TimeSeriesCollection(getOpsTs); TimeSeriesCollection getTrgTsc = new TimeSeriesCollection(getTrgTs); TimeSeriesCollection deleteOpsTsc = new TimeSeriesCollection(deleteOpsTs); TimeSeriesCollection deleteTrgTsc = new TimeSeriesCollection(deleteTrgTs); statChart = ChartFactory.createTimeSeriesChart("", "Time", "put kvop/s", putOpsTsc, true, true, false); XYPlot xyplot = (XYPlot) statChart.getPlot(); xyplot.setOrientation(PlotOrientation.VERTICAL); xyplot.setDomainPannable(true);//w w w . j a va 2 s .co m xyplot.setRangePannable(true); ValueAxis yAxis = xyplot.getDomainAxis(); yAxis.setAutoRange(true); yAxis.setFixedAutoRange(60000.0); NumberAxis numberaxis1 = new NumberAxis("get kvop/s"); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, getOpsTsc); xyplot.mapDatasetToRangeAxis(1, 1); StandardXYItemRenderer standardxyitemrenderer1 = new StandardXYItemRenderer(); xyplot.setRenderer(1, standardxyitemrenderer1); NumberAxis numberaxis2 = new NumberAxis("delete kvop/s"); numberaxis2.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(2, numberaxis2); xyplot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); xyplot.setDataset(2, deleteOpsTsc); xyplot.mapDatasetToRangeAxis(2, 2); StandardXYItemRenderer standardxyitemrenderer2 = new StandardXYItemRenderer(); xyplot.setRenderer(2, standardxyitemrenderer2); NumberAxis numberaxis3 = new NumberAxis("put MB/s"); xyplot.setRangeAxis(3, numberaxis3); xyplot.setDataset(3, putTrgTsc); xyplot.mapDatasetToRangeAxis(3, 3); StandardXYItemRenderer standardxyitemrenderer3 = new StandardXYItemRenderer(); xyplot.setRenderer(3, standardxyitemrenderer3); NumberAxis numberaxis4 = new NumberAxis("get MB/s"); numberaxis4.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(4, numberaxis4); xyplot.setRangeAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT); xyplot.setDataset(4, getTrgTsc); xyplot.mapDatasetToRangeAxis(4, 4); StandardXYItemRenderer standardxyitemrenderer4 = new StandardXYItemRenderer(); xyplot.setRenderer(4, standardxyitemrenderer4); NumberAxis numberaxis5 = new NumberAxis("delete MB/s"); xyplot.setRangeAxis(5, numberaxis5); xyplot.setDataset(5, deleteTrgTsc); xyplot.mapDatasetToRangeAxis(5, 5); StandardXYItemRenderer standardxyitemrenderer5 = new StandardXYItemRenderer(); xyplot.setRenderer(5, standardxyitemrenderer5); ChartUtilities.applyCurrentTheme(statChart); xyplot.getRenderer().setSeriesPaint(0, Color.black); standardxyitemrenderer1.setSeriesPaint(0, Color.red); numberaxis1.setLabelPaint(Color.red); numberaxis1.setTickLabelPaint(Color.red); standardxyitemrenderer2.setSeriesPaint(0, Color.green); numberaxis2.setLabelPaint(Color.green); numberaxis2.setTickLabelPaint(Color.green); standardxyitemrenderer3.setSeriesPaint(0, Color.orange); numberaxis3.setLabelPaint(Color.orange); numberaxis3.setTickLabelPaint(Color.orange); standardxyitemrenderer4.setSeriesPaint(0, Color.blue); numberaxis4.setLabelPaint(Color.blue); numberaxis4.setTickLabelPaint(Color.blue); standardxyitemrenderer5.setSeriesPaint(0, Color.cyan); numberaxis5.setLabelPaint(Color.cyan); numberaxis5.setTickLabelPaint(Color.cyan); final JPanel main = new JPanel(new BorderLayout()); final JPanel optionsPanel = new JPanel(); String[] options = { SYSTEM_TOTAL_IOPS_AND_THROUGHPUT_STATISTICS }; this.orientationComboBox = new JComboBox<String>(options); this.orientationComboBox.setSize(600, 50); this.orientationComboBox.addActionListener(this); optionsPanel.add(this.orientationComboBox); chartPanel = new ChartPanel(statChart); chartPanel.setMouseWheelEnabled(false); chartPanel.setPreferredSize(new Dimension(900, 450)); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(true); main.add(optionsPanel, BorderLayout.NORTH); main.add(this.chartPanel); setContentPane(main); }