List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:TradeMonitorGui.java
private XYPlot createChartFrame(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Average Stock Price over 1 minute", "Time", "Price in USD", dataset, true, true, false); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(new Color(245, 245, 245)); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); final JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("Trade Monitor"); frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT); frame.setLayout(new BorderLayout()); frame.add(new ChartPanel(chart)); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { avgPrices.removeEntryListener(listenerId); }/*from ww w . j ava 2s.co m*/ }); frame.setVisible(true); return plot; }
From source file:pl.poid.bzdp.zadanieObrazy.ImageHistogram.java
private JFreeChart createChart(final XYSeriesCollection dataset, Color c) { final JFreeChart chart = ChartFactory.createXYBarChart("Histogram", "Brightness", false, "Values", dataset, PlotOrientation.VERTICAL, true, true, false); XYItemRenderer renderer = chart.getXYPlot().getRenderer(); renderer.setSeriesPaint(0, c);/*from w w w . j a va 2s .co m*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); return chart; }
From source file:net.sf.dynamicreports.test.jasper.chart.XyBlockChartTest.java
@Override public void test() { super.test(); numberOfPagesTest(1);/*from w ww .j a v a 2s.c o m*/ JFreeChart chart = getChart("summary.chart1", 0); XYItemRenderer renderer = chart.getXYPlot().getRenderer(); Assert.assertEquals("renderer", XYBlockRenderer.class, renderer.getClass()); Assert.assertEquals("block width", 1.1, ((XYBlockRenderer) renderer).getBlockWidth()); Assert.assertEquals("block height", 0.9, ((XYBlockRenderer) renderer).getBlockHeight()); Assert.assertEquals("block anchor", org.jfree.ui.RectangleAnchor.BOTTOM_LEFT, ((XYBlockRenderer) renderer).getBlockAnchor()); Assert.assertEquals("paintScale", LookupPaintScale.class, ((XYBlockRenderer) renderer).getPaintScale().getClass()); LookupPaintScale paintScale = (LookupPaintScale) ((XYBlockRenderer) renderer).getPaintScale(); Assert.assertEquals("paintScale default lower bound", 0.1, paintScale.getLowerBound()); Assert.assertEquals("paintScale default upper bound", 5d, paintScale.getUpperBound()); Assert.assertEquals("paintScale default paint", Color.WHITE, paintScale.getDefaultPaint()); Assert.assertEquals("paintScale paint 1", Color.RED, paintScale.getPaint(1)); Assert.assertEquals("paintScale paint 2", Color.GREEN, paintScale.getPaint(2)); Assert.assertEquals("paintScale paint 3", Color.BLUE, paintScale.getPaint(3)); LegendItemCollection legendItems = chart.getXYPlot().getLegendItems(); Assert.assertEquals("legend item 1 label", "1", legendItems.get(0).getLabel()); Assert.assertEquals("legend item 1 paint", Color.RED, legendItems.get(0).getFillPaint()); Assert.assertEquals("legend item 2 label", "2", legendItems.get(1).getLabel()); Assert.assertEquals("legend item 2 paint", Color.GREEN, legendItems.get(1).getFillPaint()); Assert.assertEquals("legend item 3 label", "3", legendItems.get(2).getLabel()); Assert.assertEquals("legend item 3 paint", Color.BLUE, legendItems.get(2).getFillPaint()); xyzChartDataTest(chart, 0, "serie0", new Number[][] { { 1d, 2d, 0d }, { 2d, 3d, 1d }, { 3d, 4d, 2d }, { 4d, 5d, 3d } }); chart = getChart("summary.chart2", 0); Axis axis = chart.getXYPlot().getDomainAxis(); Assert.assertEquals("category label", "category", axis.getLabel()); Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint()); Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont()); Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint()); Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont()); Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint()); chart = getChart("summary.chart3", 0); axis = chart.getXYPlot().getRangeAxis(); Assert.assertEquals("value label", "value", axis.getLabel()); Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint()); Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont()); Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint()); Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont()); Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10)); Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint()); }
From source file:org.projectforge.charting.XYChartBuilder.java
public XYChartBuilder(final JFreeChart chart) { this.chart = chart; plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setOutlineVisible(false);//from w w w .j a va 2s .co m }
From source file:edu.utexas.ece.pharos.proteus3.sensors.CompassChartGUI.java
/** * Creates a new demo.//from www . ja v a2s .com * * @param title the frame title. */ public CompassChartGUI(final String title) { super(title); final XYDataset dataset = createDataset(); final JFreeChart chart = createChart(dataset); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60); // 60 seconds final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); // new Thread(new ChartUpdater(chart.getXYPlot())).start(); }
From source file:net.sourceforge.processdash.ev.ui.chart.EVXYChartPanel.java
private void adjustStyle(int width) { int style;/*w w w .j av a2s .c o m*/ if (width > medium_window_width) style = FULL; else if (width > short_window_width) style = MED; else style = SHORT; JFreeChart chart = getChart(); chart.removeLegend(); if (style == FULL) chart.addLegend(legend); adjustAxis(chart.getXYPlot().getRangeAxis(), style != FULL, yLabel); adjustAxis(chart.getXYPlot().getDomainAxis(), style == SHORT, xLabel); }
From source file:old.MonitoringChart.java
private JFreeChart createChart(String title, final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart(title, "Time", "Usage in %", dataset, true, true, false);/*from ww w . j ava2 s.c o m*/ final XYPlot plot = result.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(60000.0); // 60 seconds axis = plot.getRangeAxis(); axis.setRange(0.0, 100.0); return result; }
From source file:org.webcat.grader.graphs.SubmissionCountChart.java
@Override protected JFreeChart generateChart(WCChartTheme chartTheme) { JFreeChart chart = super.generateChart(chartTheme); NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:dbseer.gui.chart.DBSeerChartFactory.java
public static JFreeChart createXYLinePredictionChart(PredictionCenter center) throws Exception { StatisticalPackageRunner runner = DBSeerGUI.runner; String title = runner.getVariableString("title"); Object[] legends = (Object[]) runner.getVariableCell("legends"); Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata"); Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata"); String xLabel = runner.getVariableString("Xlabel"); String yLabel = runner.getVariableString("Ylabel"); XYSeriesCollection dataSet = new XYSeriesCollection(); int numLegends = legends.length; int numXCellArray = xCellArray.length; int numYCellArray = yCellArray.length; int dataCount = 0; if (numXCellArray != numYCellArray) { JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.", "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE); System.out.println(numXCellArray + " : " + numYCellArray); return null; }// www . j a v a 2 s. c o m final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0) .getTransactionTypeNames(); for (int i = 0; i < numLegends; ++i) { String legend = (String) legends[i]; for (int j = 0; j < transactionNames.size(); ++j) { if (legend.contains("Type " + (j + 1))) { legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j)); break; } } } for (int j = 0; j < transactionNames.size(); ++j) { if (xLabel.contains("Type " + (j + 1))) { xLabel = xLabel.replace("Type " + (j + 1), transactionNames.get(j)); break; } } for (int j = 0; j < transactionNames.size(); ++j) { if (yLabel.contains("Type " + (j + 1))) { yLabel = yLabel.replace("Type " + (j + 1), transactionNames.get(j)); break; } } for (int i = 0; i < numYCellArray; ++i) { double[] xArray = (double[]) xCellArray[i]; runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});"); runner.eval("yArray = Ydata{" + (i + 1) + "};"); double[] yArraySize = runner.getVariableDouble("yArraySize"); double[] yArray = runner.getVariableDouble("yArray"); int xLength = xArray.length; int row = (int) yArraySize[0]; int col = (int) yArraySize[1]; for (int c = 0; c < col; ++c) { XYSeries series; int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount; String legend = (String) legends[legendIdx]; if (numLegends == 0) { series = new XYSeries("Data " + dataCount + 1); } else if (dataCount >= numLegends) { series = new XYSeries(legend + (dataCount + 1)); } else { series = new XYSeries(legend); } for (int r = 0; r < row; ++r) { int xRow = (r >= xLength) ? xLength - 1 : r; double yValue = yArray[r + c * row]; // remove negatives & NaN & infs. if (yValue < 0 || yValue == Double.NaN || yValue == Double.POSITIVE_INFINITY || yValue == Double.NEGATIVE_INFINITY) { yValue = 0.0; } series.add(xArray[xRow], yValue); } dataSet.addSeries(series); ++dataCount; } } JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataSet); // change 'predicted' data to have dotted lines. BasicStroke dashStroke = toStroke(STYLE_DASH); BasicStroke dotStroke = toStroke(STYLE_DOT); BasicStroke lineStroke = toStroke(STYLE_LINE); for (int i = 0; i < dataSet.getSeriesCount(); ++i) { String legend = (String) dataSet.getSeriesKey(i); XYPlot plot = chart.getXYPlot(); XYItemRenderer renderer = plot.getRenderer(); if (legend.contains("predicted") || legend.contains("Predicted")) { renderer.setSeriesStroke(i, dotStroke); } else { renderer.setSeriesStroke(i, lineStroke); } } return chart; }
From source file:org.jfree.chart.demo.TimeSeriesDemo4.java
/** * A demonstration application showing a quarterly time series containing a null value. * * @param title the frame title./*from w w w .j ava2 s . co m*/ */ public TimeSeriesDemo4(final String title) { super(title); final TimeSeries series = new TimeSeries("Random Data", Hour.class); final Day today = new Day(); series.add(new Hour(1, today), 500.2); series.add(new Hour(2, today), 694.1); series.add(new Hour(3, today), 734.4); series.add(new Hour(4, today), 453.2); series.add(new Hour(7, today), 500.2); series.add(new Hour(8, today), null); series.add(new Hour(12, today), 734.4); series.add(new Hour(16, today), 453.2); final TimeSeriesCollection dataset = new TimeSeriesCollection(series); // create a title with Unicode characters (currency symbols in this case)... final String chartTitle = "\u20A2\u20A2\u20A3\u20A4\u20A5\u20A6\u20A7\u20A8\u20A9\u20AA"; final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Time", "Value", dataset, true, true, false); final XYPlot plot = chart.getXYPlot(); // plot.setInsets(new Insets(0, 0, 0, 20)); final Marker marker = new ValueMarker(700.0); marker.setPaint(Color.blue); marker.setAlpha(0.8f); plot.addRangeMarker(marker); plot.setBackgroundPaint(null); plot.setBackgroundImage(JFreeChart.INFO.getLogo()); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer r = (StandardXYItemRenderer) renderer; r.setPlotShapes(true); r.setShapesFilled(true); } final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); }