List of usage examples for org.jfree.chart.plot XYPlot getRenderer
public XYItemRenderer getRenderer()
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
private static void decorateCategoryPlot(JFreeChart chart) { XYPlot plot = chart.getXYPlot(); XYItemRenderer render = plot.getRenderer(); ValueAxis domainAxis = plot.getDomainAxis(); ValueAxis valueAxis = plot.getRangeAxis(); Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE); //$NON-NLS-1$ render.setBaseItemLabelFont(font);//from www. j a v a2 s .c o m font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE); //$NON-NLS-1$ domainAxis.setLabelFont(font); font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE); //$NON-NLS-1$ valueAxis.setLabelFont(font); font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE); //$NON-NLS-1$ domainAxis.setTickLabelFont(font); valueAxis.setTickLabelFont(font); font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE); //$NON-NLS-1$ LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setItemFont(font); } font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE); //$NON-NLS-1$ TextTitle title = chart.getTitle(); if (title != null) { title.setFont(font); } font = null; if (render instanceof BarRenderer) { int rowCount = chart.getCategoryPlot().getDataset().getRowCount(); domainAxis.setUpperMargin(0.1); // domainAxis.setMaximumCategoryLabelLines(10); ((BarRenderer) render).setItemMargin(-0.40 * rowCount); } // set color int rowCount = chart.getXYPlot().getDataset().getSeriesCount(); for (int i = 0; i < rowCount; i++) { plot.getRenderer().setSeriesPaint(i, Color.RED); } }
From source file:org.micromanager.CRISP.CRISPFrame.java
/** * Create a frame with a plot of the data given in XYSeries *///from ww w.j av a 2s . c o m public static void plotData(String title, XYSeries data, String xTitle, String yTitle, int xLocation, int yLocation) { // JFreeChart code XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(data); JFreeChart chart = ChartFactory.createScatterPlot(title, // Title xTitle, // x-axis Label yTitle, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesFillPaint(0, Color.white); renderer.setSeriesLinesVisible(0, true); Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f); renderer.setSeriesShape(0, circle, false); renderer.setUseFillPaint(true); ChartFrame graphFrame = new ChartFrame(title, chart); graphFrame.getChartPanel().setMouseWheelEnabled(true); graphFrame.pack(); graphFrame.setLocation(xLocation, yLocation); graphFrame.setVisible(true); }
From source file:org.talend.dataprofiler.chart.util.TopChartFactory.java
/** * Method "createBubbleChart".//from w w w . j a v a 2 s .c o m * * @param indic the indicator * @param numericColumn the analyzed numeric column * @return the bubble chart */ public static JFreeChart createBubbleChart(String chartName, Object dataset, Map<String, ValueAggregator> xyzDatasets) { final Map<String, ValueAggregator> xyzDatasetsFinal = xyzDatasets; JFreeChart chart = TopChartFactory.createBubbleChart(chartName, Messages.getString("TopChartFactory.average"), Messages.getString("TopChartFactory.count"), //$NON-NLS-1$//$NON-NLS-2$ (DefaultXYZDataset) dataset, PlotOrientation.HORIZONTAL, true, true, true); final XYPlot plot = (XYPlot) chart.getPlot(); final XYItemRenderer renderer = plot.getRenderer(); renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator() { private static final long serialVersionUID = 1L; /* * (non-Javadoc) * * @see org.jfree.chart.labels.StandardXYZToolTipGenerator#createItemArray(org.jfree.data.xy.XYZDataset, * int, int) */ @Override protected Object[] createItemArray(XYZDataset dset, int series, int item) { final Comparable<?> seriesKey = dset.getSeriesKey(series); final String seriesK = String.valueOf(seriesKey); String label = seriesK; if (xyzDatasetsFinal != null) { ValueAggregator valueAggregator = xyzDatasetsFinal.get(seriesKey); label = valueAggregator.getLabels(seriesK).get(item); } final Object[] itemArray = super.createItemArray(dset, series, item); itemArray[0] = label;// label; itemArray[1] = "avg=" + itemArray[1]; //$NON-NLS-1$ itemArray[2] = "record count=" + itemArray[2]; //$NON-NLS-1$ itemArray[3] = "null count=" + itemArray[3]; //$NON-NLS-1$ return itemArray; } }); 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; }/*from w ww . j a va2s. c om*/ 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.esa.snap.rcp.statistics.StatisticsPanel.java
private static ChartPanel getHistogramPlotPanel(XIntervalSeriesCollection dataset, String xAxisLabel, String yAxisLabel, Color color) { JFreeChart chart = ChartFactory.createHistogram(null, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, false, // Legend? true, // tooltips false // url );//w w w. ja va2 s . c o m final XYPlot xyPlot = chart.getXYPlot(); //xyPlot.setForegroundAlpha(0.85f); xyPlot.setNoDataMessage("No data"); xyPlot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); final XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); renderer.setSeriesPaint(0, color); StandardXYBarPainter painter = new StandardXYBarPainter(); renderer.setBarPainter(painter); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(300, 200)); // chartPanel.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return chartPanel; }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart1.java
public static JFreeChart createChart2(ArrayList<DataItems> _nor_model, ArrayList<DataItems> _abnor_model, DataItems nor, DataItems abnor, Map<String, ArrayList<LinePos>> mapAB, String chartname, String protocol1, String protocol2) { XYDataset xydataset = createNormalDataset(nor, protocol1); JFreeChart jfreechart = ChartFactory.createXYLineChart(chartname, "", "", xydataset); jfreechart.getLegend().setVisible(false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); // ??/* w w w . j av a 2 s . co m*/ xylineandshaperenderer.setSeriesLinesVisible(0, true); xylineandshaperenderer.setBaseShapesVisible(false); xylineandshaperenderer.setSeriesShape(0, double1); xylineandshaperenderer.setSeriesPaint(0, Color.blue); xylineandshaperenderer.setSeriesFillPaint(0, Color.blue); xylineandshaperenderer.setSeriesOutlinePaint(0, Color.blue); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F)); // ? // xylineandshaperenderer.setBaseItemLabelGenerator(new // StandardXYItemLabelGenerator()); // xylineandshaperenderer.setBaseItemLabelsVisible(true); int datasetcount0 = xyplot.getDatasetCount(); XYDataset xydataset1 = createNormalDataset(abnor, protocol2); // xydataset1. XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); int datasetcount = xyplot.getDatasetCount(); xyplot.setDataset(datasetcount, xydataset1); xyplot.setRenderer(datasetcount, xylineandshaperenderer1); // ??? xylineandshaperenderer1.setBaseShapesVisible(false); // ?? xylineandshaperenderer1.setSeriesLinesVisible(0, true); xylineandshaperenderer1.setSeriesShape(0, double1); // xylineandshaperenderer1.setSeriesPaint(0, Color.green); xylineandshaperenderer1.setSeriesFillPaint(0, Color.green); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer1.setUseFillPaint(true); xylineandshaperenderer1.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F)); // //? /* * for (int i = 0; i < _nor_model.size(); i++) { XYDataset xydataset2 = * createmodeDataset(_nor_model.get(i), "_nor_model" + i); * XYLineAndShapeRenderer xylineandshaperenderer2 = new * XYLineAndShapeRenderer(); xyplot.setDataset(i + 2, xydataset2); * xyplot.setRenderer(2 + i, xylineandshaperenderer2); // ??? * xylineandshaperenderer2.setBaseShapesVisible(false); // ?? * xylineandshaperenderer2.setSeriesLinesVisible(0, true); * xylineandshaperenderer2.setSeriesShape(0, double1); // * xylineandshaperenderer2.setSeriesPaint(0, Color.red); * xylineandshaperenderer2.setSeriesFillPaint(0, Color.red); * xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.red); * xylineandshaperenderer2.setUseFillPaint(true); * xylineandshaperenderer2 .setBaseItemLabelGenerator(new * StandardXYItemLabelGenerator()); * xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(2.5F)); * * } for (int i = 0; i < _abnor_model.size(); i++) { XYDataset * xydataset3 = createmodeDataset(_abnor_model.get(i), "_abnor_model" + * i); XYLineAndShapeRenderer xylineandshaperenderer3 = new * XYLineAndShapeRenderer(); xyplot.setDataset(i + 2 + * _nor_model.size(), xydataset3); xyplot.setRenderer(i + 2 + * _nor_model.size(), xylineandshaperenderer3); // ??? * xylineandshaperenderer3.setBaseShapesVisible(false); // ?? * xylineandshaperenderer3.setSeriesLinesVisible(0, true); * xylineandshaperenderer3.setSeriesShape(0, double1); // * xylineandshaperenderer3.setSeriesPaint(0, Color.red); * xylineandshaperenderer3.setSeriesFillPaint(0, Color.red); * xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.red); * xylineandshaperenderer3.setUseFillPaint(true); * xylineandshaperenderer3 .setBaseItemLabelGenerator(new * StandardXYItemLabelGenerator()); * xylineandshaperenderer3.setSeriesStroke(0, new BasicStroke(2.5F)); * * } */ // ?? // // ///////////////////////////////// // ? XYDataset xydataset4 = createLineDataset(nor, abnor, mapAB, xyplot); // ??y=1 ValueMarker valuemarker = new ValueMarker(1); // valuemarker.setLabelOffsetType(LengthAdjustmentType.EXPAND); valuemarker.setPaint(Color.black); // ? valuemarker.setStroke(new BasicStroke(1.0F)); // // valuemarker.setLabel(""); //? valuemarker.setLabelFont(new Font("SansSerif", 0, 11)); // ? valuemarker.setLabelPaint(Color.red); valuemarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); valuemarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); xyplot.addRangeMarker(valuemarker); // // //jfreechart.getLegend().setVisible(true); return jfreechart; }
From source file:org.xapagy.ui.tempdyn.GraphEvolution.java
/** * Creates a chart the style we like./* w ww . ja v a 2 s.c o m*/ * * @param chart */ public static void setChartProperties(JFreeChart chart, List<SimpleEntry<Color, Stroke>> lineStyles) { // set the background and title font chart.setBackgroundPaint(Color.white); chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 14)); // set the background and the grid all white XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setBackgroundPaint(Color.white); // now plot.setOutlineStroke(null); XYItemRenderer rend = plot.getRenderer(); Stroke stroke = new BasicStroke(2.0f); rend.setBaseStroke(stroke); // rend.setDrawSeriesLineAsPath(true); // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, // BasicStroke.JOIN_ROUND, 10, new float[] {10, 10}, 0); // strokes.add(stroke); // stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, // BasicStroke.JOIN_ROUND, 10, new float[] {2, 4}, 0); // strokes.add(stroke); int seriesCount = plot.getSeriesCount(); for (int i = 0; i != seriesCount; i++) { SimpleEntry<Color, Stroke> lineStyle = lineStyles.get(i % lineStyles.size()); rend.setSeriesStroke(i, lineStyle.getValue()); rend.setSeriesPaint(i, lineStyle.getKey()); } }
From source file:grisu.frontend.view.swing.files.preview.fileViewers.JobStatusGridFileViewer.java
private static ChartPanel createChart(String title, String y_axis, XYDataset dataset, boolean createLegend) { final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "Date", // x-axis label y_axis, // y-axis label dataset, // data createLegend, // create legend? true, // generate tooltips? false // generate URLs? );// www . ja v a2 s.c o m chart.setBackgroundPaint(Color.white); final XYPlot plot = (XYPlot) chart.getPlot(); 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); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); final XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd.MM. HH:mm")); return new ChartPanel(chart); }
From source file:ec.ui.view.res.ResidualsView.java
private static JFreeChart buildResidualViewChart() { JFreeChart result = ChartFactory.createXYBarChart("Full residuals", "", false, "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); XYPlot plot = result.getXYPlot(); DateAxis domainAxis = new DateAxis(); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setLowerMargin(0);/* w w w. ja v a2 s . c o m*/ domainAxis.setUpperMargin(0); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelInsets(new RectangleInsets(10, 5, 10, 2)); rangeAxis.setLowerMargin(0.02); rangeAxis.setUpperMargin(0.02); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); renderer.setDrawBarOutline(true); renderer.setAutoPopulateSeriesPaint(false); renderer.setAutoPopulateSeriesOutlinePaint(false); return result; }
From source file:ioheater.ui.IOHeaterUI.java
/** * Creates a chart.// w w w. j a v a2s.co m * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Temperature Trend", // title "Time (m:s)", // x-axis label "Temperature (C)", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); 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); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("H:mm:ss")); return chart; }