List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:org.jfree.chart.demo.MultipleAxisDemo3.java
/** * Creates the demo chart.//from w ww. j a v a2 s . co 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 3", "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); plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); // DOMAIN AXIS 3 final NumberAxis xAxis3 = new NumberAxis("Domain Axis 3"); xAxis2.setAutoRangeIncludesZero(false); plot.setDomainAxis(2, xAxis3); plot.setDomainAxisLocation(2, AxisLocation.BOTTOM_OR_LEFT); // 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:com.intel.stl.ui.monitor.view.PSEventsCardView.java
/** * Description:/* w ww . jav a2 s. c o m*/ * * @param dataset * @param colors */ public void setTrendDataset(TableXYDataset dataset, Color[] colors) { JFreeChart chart = ComponentFactory.createStackedXYBarChart(dataset, "", STLConstants.K0035_TIME.getValue(), STLConstants.K0055_NUM_NODES.getValue(), false); XYItemRenderer xyitemrenderer = chart.getXYPlot().getRenderer(); for (int i = 0; i < colors.length; i++) { xyitemrenderer.setSeriesPaint(i, colors[i]); } barPanel.setChart(chart); }
From source file:net.footballpredictions.footballstats.swing.PointsGraph.java
/** * Plot points earned against number of matches played. *///from www .jav a2s. co m public void updateGraph(Object[] teams, LeagueSeason data) { assert teams.length > 0 : "Must be at least one team selected."; XYSeriesCollection dataSet = new XYSeriesCollection(); int max = 0; for (Object team : teams) { String teamName = (String) team; XYSeries pointsSeries = new XYSeries(teamName); int[] points = data.getTeam(teamName).getPointsData(data.getMetaData().getPointsForWin(), data.getMetaData().getPointsForDraw()); for (int i = 0; i < points.length; i++) { pointsSeries.add(i, points[i]); } max = Math.max(max, points[points.length - 1]); dataSet.addSeries(pointsSeries); } JFreeChart chart = ChartFactory.createXYLineChart(null, // Title messageResources.getString("graphs.matches"), messageResources.getString("combo.GraphType.POINTS"), dataSet, PlotOrientation.VERTICAL, true, // Legend. false, // Tooltips. false); // URLs. chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chart.getXYPlot().getRangeAxis().setRange(0, max + 1); setChart(chart); }
From source file:org.limy.eclipse.qalab.task.DistanceGraphTask.java
/** * @param dataset //from w w w . j av a2s .c o m * @throws IOException * */ private void drawGraph(XYDataset dataset) throws IOException { JFreeChart chart = ChartFactory.createScatterPlot("Distance from the Main Sequence", "Instability", "Abstractness", dataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = chart.getXYPlot(); plot.getRenderer().addAnnotation( new XYLineAnnotation(-0.1, 1.1, 1.1, -0.1, new BasicStroke(2), new Color(50, 220, 50)), Layer.BACKGROUND); plot.getRenderer().setShape(new Ellipse2D.Double(-4, -4, 8, 8)); plot.getRenderer().setPaint(new Color(0xec, 0x76, 0x37)); plot.getDomainAxis().setRangeWithMargins(0, 1); plot.getRangeAxis().setRangeWithMargins(0, 1); chart.getTitle().setPaint(Color.BLUE); plot.setDomainCrosshairVisible(true); plot.setDomainCrosshairPaint(Color.GRAY); plot.setRangeCrosshairVisible(true); plot.setRangeCrosshairPaint(Color.GRAY); LimyGraphUtils.writeImagePng(chart, out, 400, 380); }
From source file:chart.JChartSegment.java
/** * Creates a sample chart./*from w w w. j a v a2 s. com*/ * * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final XYDataset dataset, List<NSubsequence> subsequence) { final JFreeChart chart = ChartFactory.createXYLineChart("Test", "Time", "Value", dataset, PlotOrientation.VERTICAL, false, false, false); chart.setBackgroundPaint(Color.WHITE); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); MyRender renderer = new MyRender(dataset, subsequence); plot.setRenderer(renderer); renderer.setSeriesShapesVisible(0, false); chart.setBackgroundPaint(Color.white); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setAutoRangeIncludesZero(false); return chart; }
From source file:ip.ui.plot.PlotGenerator.java
public void generateErrorChart(List<Double> errors, String plotFileName) throws IOException { XYSeries data = new XYSeries("Errors"); for (int i = 1; i <= errors.size(); ++i) { data.add(i, errors.get(i - 1));//from ww w . ja v a2 s . c o m } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(data); JFreeChart chart = ChartFactory.createXYLineChart("Squared error", "Epoch number", "Squared Error", dataset, PlotOrientation.VERTICAL, false, true, true); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); chart.getXYPlot().setRenderer(renderer); File XYChart = new File(plotFileName); ChartUtilities.saveChartAsJPEG(XYChart, chart, chartWidth, chartHeight); }
From source file:net.sf.jasperreports.customizers.shape.LegendShapeCustomizer.java
@Override public void customize(JFreeChart jfc, JRChart jrc) { Plot plot = jfc.getPlot();/* w ww. j ava2 s . c om*/ ItemsCounter itemsCounter = new LegendItemsCounter(plot); SeriesNameProvider seriesNameProvider = null; Object renderer = null; if (plot instanceof XYPlot) { XYPlot xyPlot = jfc.getXYPlot(); renderer = xyPlot.getRenderer(); seriesNameProvider = new XYPlotSeriesNameProvider(xyPlot); } else if (plot instanceof CategoryPlot) { CategoryPlot categoryPlot = jfc.getCategoryPlot(); renderer = categoryPlot.getRenderer(); seriesNameProvider = new CategorySeriesNameProvider(categoryPlot); } Integer legendItemIndex = CustomizerUtil.resolveIndex(this, itemsCounter, seriesNameProvider); if (legendItemIndex != null && renderer instanceof AbstractRenderer) { ShapeSetter shapeSetter = new AbstractRendererLegendShapeSetter((AbstractRenderer) renderer); if (legendItemIndex == -1) { updateItems(itemsCounter, shapeSetter); } else { updateItem(itemsCounter, shapeSetter, legendItemIndex); } } }
From source file:org.jfree.chart.demo.XYBarChartDemo.java
/** * Constructs the demo application.//from www. j a v a2s . com * * @param title the frame title. */ public XYBarChartDemo(final String title) { super(title); final TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1(); data.setDomainIsPointsInTime(false); final JFreeChart chart = ChartFactory.createXYBarChart(title, "X", true, "Y", data, PlotOrientation.VERTICAL, true, false, false); // then customise it a little... chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.blue)); final XYItemRenderer renderer = chart.getXYPlot().getRenderer(); final StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator("{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); final XYPlot plot = chart.getXYPlot(); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.DynamicDataDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w ww . j a va2 s. c om */ 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.squale.squaleweb.util.graph.HistoMaker.java
/** * This method create the JFreechart chart * //from w ww . j a v a 2 s . co m * @param maxAxisToday Does the max for the date axis should be set to today ? * @return A JFreeChart chart */ public JFreeChart getChart(boolean maxAxisToday) { JFreeChart retChart = super.getChart(); if (null == retChart) { retChart = ChartFactory.createTimeSeriesChart(mTitle, mXLabel, mYLabel, mDataSet, mShowLegend, false, false); XYPlot plot = retChart.getXYPlot(); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); plot.setRenderer(xylineandshaperenderer); SimpleDateFormat sdf = new SimpleDateFormat(mDateFormat); DateAxis axis = (DateAxis) plot.getDomainAxis(); if (maxAxisToday) { axis.setMaximumDate(new Date()); } axis.setDateFormatOverride(sdf); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setAutoRangeMinimumSize(2.0); super.setChart(retChart); } return retChart; }