List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:org.yccheok.jstock.gui.charting.DynamicChart.java
public void showNewJDialog(java.awt.Frame parent, String title) { TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.price); JFreeChart freeChart = ChartFactory.createTimeSeriesChart(title, GUIBundle.getString("DynamicChart_Date"), GUIBundle.getString("DynamicChart_Price"), dataset, true, true, false); freeChart.setAntiAlias(true);/*from w w w .ja v a 2s. c o m*/ XYPlot plot = freeChart.getXYPlot(); NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis(); DecimalFormat format = new DecimalFormat("00.00"); rangeAxis1.setNumberFormatOverride(format); XYItemRenderer renderer1 = plot.getRenderer(); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#"))); org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart); ChartPanel _chartPanel = new ChartPanel(freeChart, true, true, true, true, true); JDialog dialog = new JDialog(parent, title, false); dialog.getContentPane().add(_chartPanel, java.awt.BorderLayout.CENTER); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); final java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); dialog.setBounds((screenSize.width - 750) >> 1, (screenSize.height - 600) >> 1, 750, 600); dialog.setVisible(true); }
From source file:org.jfree.chart.demo.YIntervalChartDemo.java
/** * Creates a new chart./* w w w .j ava 2 s .c o m*/ * * @param dataset the dataset. * * @return The chart. */ private JFreeChart createChart(final IntervalXYDataset dataset) { final JFreeChart chart = ChartFactory.createScatterPlot("Y Interval Chart Demo", // chart title "X", // domain axis label "Y", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new YIntervalRenderer()); return chart; }
From source file:edu.emory.library.tast.database.graphs.GraphTypeScatter.java
public JFreeChart createChart(Object[] data) { CategoryTableXYDataset dataset = new CategoryTableXYDataset(); JFreeChart chart = ChartFactory.createScatterPlot(null, getSelectedIndependentVariable().getLabel(), TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true, false);/*from w w w .j a v a2 s . co m*/ //getSelectedIndependentVariable().getFormat(); XYPlot plot = chart.getXYPlot(); ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride(new DecimalFormat("0")); chart.setBackgroundPaint(Color.white); List allDataSeries = getDataSeries(); for (int j = 0; j < allDataSeries.size(); j++) { DataSeries dataSearies = (DataSeries) allDataSeries.get(j); String dataSeriesLabel = dataSearies.formatForDisplay(); for (int i = 0; i < data.length; i++) { Object[] row = (Object[]) data[i]; Number x = (Number) row[0]; Number y = (Number) row[j + 1]; if (x != null && y != null) dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel); } } return chart; }
From source file:org.jfree.chart.demo.BubblyBubblesDemo.java
/** * A demonstration application showing a bubble chart using matrix series. * * @param title the frame title./*from w w w. ja v a 2 s . c o m*/ */ public BubblyBubblesDemo(final String title) { super(title); this.series = createInitialSeries(); final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.series); final JFreeChart chart = ChartFactory.createBubbleChart(TITLE, "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final XYPlot plot = chart.getXYPlot(); plot.setForegroundAlpha(0.5f); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setLowerBound(-0.5); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); // rangeAxis.setInverted(true); // uncoment to reproduce a bug in jFreeChart rangeAxis.setLowerBound(-0.5); final ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setVerticalZoom(true); // chartPanel.setHorizontalZoom(true); setContentPane(chartPanel); }
From source file:com.anji.floatingeye.FloatingEyeDisplay.java
private void init(Java2DSurface surface, FloatingEye anEye) { eye = anEye;// w ww . ja v a 2 s . c o m // this frame has 3 sections - status, surface canvas, and eye canvas addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); dispose(); } }); GridLayout mainLayout = new GridLayout(2, 1); mainLayout.setHgap(10); mainLayout.setVgap(10); getContentPane().setLayout(mainLayout); GridLayout topPanelLayout = new GridLayout(2, 1); topPanelLayout.setHgap(10); topPanelLayout.setVgap(10); Panel topPanel = new Panel(topPanelLayout); GridLayout bottomPanelLayout = new GridLayout(1, 2); bottomPanelLayout.setHgap(10); bottomPanelLayout.setVgap(10); Panel bottomPanel = new Panel(bottomPanelLayout); // 1 - status area statusArea = new TextArea("", 1, 1, TextArea.SCROLLBARS_VERTICAL_ONLY); statusArea.setEditable(false); statusArea.setFont(new Font("Dialog", Font.PLAIN, 10)); statusArea.setSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2)); // 2 - affinity history chart XYSeriesCollection seriesCollection = new XYSeriesCollection(affinitySeries); JFreeChart chart = ChartFactory.createXYLineChart("affinity history", "step", "affinity", seriesCollection, PlotOrientation.VERTICAL, false, false, false); ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); rangeAxis.setAutoRange(false); rangeAxis.setRange(0d, 1d); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(IMG_WIDTH * 2, IMG_HEIGHT / 2)); // 3 - surface canvas surfaceCanvas = new SurfaceCanvas(surface, eye, IMG_WIDTH, IMG_HEIGHT); surfaceCanvas.setBackground(Color.WHITE); // 4 - eye canvas eyeCanvas = new EyeCanvas(eye, IMG_WIDTH, IMG_HEIGHT); eyeCanvas.setBackground(Color.WHITE); topPanel.add(statusArea); topPanel.add(chartPanel); bottomPanel.add(surfaceCanvas); bottomPanel.add(eyeCanvas); getContentPane().add(topPanel); getContentPane().add(bottomPanel); pack(); }
From source file:org.dkpro.tc.ml.report.util.ScatterplotRenderer.java
@Override public void write(OutputStream aStream) throws IOException { JFreeChart chart = ChartFactory.createXYLineChart("Scatterplot", "Gold", "Prediction", aDataset, PlotOrientation.VERTICAL, false, false, false); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotHeight(2);/*ww w . j av a 2s .c o m*/ renderer.setDotWidth(2); double padding = (max - min) / 10; chart.getXYPlot().setRenderer(renderer); chart.getXYPlot().getRangeAxis().setRange(min - padding, max + padding); chart.getXYPlot().getDomainAxis().setRange(min - padding, max + padding); ChartUtil.writeChartAsPDF(aStream, chart, 400, 400); }
From source file:net.footballpredictions.footballstats.swing.GoalsGraph.java
/** * Plot goals scored and conceded against number of matches played. *//* ww w .j a va 2 s. c o m*/ public void updateGraph(String teamName, LeagueSeason data) { XYSeriesCollection dataSet = new XYSeriesCollection(); XYSeries forSeries = new XYSeries(teamName + ' ' + messageResources.getString("graphs.scored")); XYSeries againstSeries = new XYSeries(teamName + ' ' + messageResources.getString("graphs.conceded")); int[][] goals = data.getTeam(teamName).getGoalsData(); for (int i = 0; i < goals.length; i++) { forSeries.add(i, goals[i][0]); againstSeries.add(i, goals[i][1]); } dataSet.addSeries(forSeries); dataSet.addSeries(againstSeries); JFreeChart chart = ChartFactory.createXYLineChart(null, // Title messageResources.getString("graphs.matches"), messageResources.getString("combo.GraphType.GOALS"), dataSet, PlotOrientation.VERTICAL, true, // Legend. false, // Tooltips. false); // URLs. chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int max = Math.max(goals[goals.length - 1][0], goals[goals.length - 1][1]); chart.getXYPlot().getRangeAxis().setRange(0, max + 1); XYDifferenceRenderer renderer = new XYDifferenceRenderer(); renderer.setSeriesPaint(0, Colours.POSITIVE); // Green. renderer.setPositivePaint(Colours.POSITIVE_FILL); // Translucent green. renderer.setSeriesPaint(1, Colours.NEGATIVE); // Red. renderer.setNegativePaint(Colours.NEGATIVE_FILL); // Translucent red. chart.getXYPlot().setRenderer(renderer); setChart(chart); }
From source file:org.jfree.chart.demo.BubblyBubblesDemo2.java
/** * A demonstration application showing a bubble chart using matrix series. * * @param title the frame title.//from ww w . j av a 2 s .co m */ public BubblyBubblesDemo2(final String title) { super(title); this.series = createInitialSeries(); final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.series); final JFreeChart chart = ChartFactory.createBubbleChart(TITLE, "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.yellow)); final XYPlot plot = chart.getXYPlot(); plot.setForegroundAlpha(0.5f); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setLowerBound(-0.5); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLowerBound(-0.5); final ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setVerticalZoom(true); // chartPanel.setHorizontalZoom(true); setContentPane(chartPanel); }
From source file:ch.zhaw.init.walj.projectmanagement.util.chart.LineChart.java
/** * creates a line chart with all booked hours of a specific employee * @param employeeID ID of the employee for which a chart should be created *///from ww w. ja va2 s .c o m public void createChart(int employeeID) { // get dataset XYSeriesCollection dataset; dataset = createDataset(employeeID); // create chart JFreeChart xylineChart = ChartFactory.createXYLineChart("", "Month", "Hours", dataset, PlotOrientation.VERTICAL, true, true, false); // set color of chart XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, new Color(0, 101, 166)); renderer.setSeriesPaint(1, new Color(0, 62, 102)); plot.setRenderer(renderer); // set size of the chart and save it as JPEG int width = 1200; int height = 600; File lineChart = new File( path + "/Charts/EffortProject" + project.getID() + "_Employee" + employeeID + ".jpg"); try { ChartUtilities.saveChartAsJPEG(lineChart, xylineChart, width, height); } catch (IOException e) { e.printStackTrace(); } }
From source file:playground.artemc.socialCost.MeanTravelTimeWriter.java
/** * @return a graphic showing the number of agents in the evacuated area *//* ww w . ja v a 2 s .c o m*/ private JFreeChart getGraphic(String modeName, double data[]) { final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries dataSerie = new XYSeries("mean trip travel time", false, true); for (int i = 0; i < data.length; i++) { dataSerie.add(i, data[i]); } xyData.addSeries(dataSerie); // final JFreeChart chart = ChartFactory.createXYStepChart( final JFreeChart chart = ChartFactory.createXYLineChart("mean travel time, " + modeName, "iteration", "travel time", 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")); return chart; }