List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:projects.hip.exec.HrDiagram.java
/** * Plot the HR diagram chart from the given data. * @param series//from ww w . j a va2 s . c o m * A {@link XYSeries} containing the HR diagram data. * @return * A {@link JFreeChart} containing the plot. */ private static JFreeChart getHrChart(XYSeries series) { XYSeriesCollection hrData = new XYSeriesCollection(); hrData.addSeries(series); // Set up the renderer XYLineAndShapeRenderer hrRenderer = new XYLineAndShapeRenderer(); hrRenderer.setSeriesLinesVisible(0, false); hrRenderer.setSeriesShapesVisible(0, true); hrRenderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1)); // Configure axes NumberAxis xAxis = new NumberAxis("B - V [mag]"); xAxis.setRange(-0.5, 2.25); NumberAxis yAxis = new NumberAxis("H [mag]"); yAxis.setInverted(true); yAxis.setRange(-5, 13); // Configure plot XYPlot xyplot = new XYPlot(hrData, xAxis, yAxis, hrRenderer); xyplot.setBackgroundPaint(Color.white); JFreeChart hrChart = new JFreeChart("HR diagram of Hipparcos stars", xyplot); hrChart.removeLegend(); hrChart.setBackgroundPaint(Color.white); return hrChart; }
From source file:jhplot.HChart.java
/** * Create HChart canvas with a several chart plots * // w w w.jav a 2s. c om * @param title * Title * @param xsize * size in x direction * @param ysize * size in y direction * @param n1 * number of plots/graphs in x * @param n2 * number of plots/graphs in y * @param set * set or not the graph */ public HChart(String title, int xsize, int ysize, int n1, int n2, boolean set) { super(title, xsize, ysize, n1, n2, set); cdatPie = new DefaultPieDataset[N1final][N2final]; cdatPie3D = new DefaultPieDataset[N1final][N2final]; cdatBar = new DefaultCategoryDataset[N1final][N2final]; cdatBar3D = new DefaultCategoryDataset[N1final][N2final]; cdatLine = new DefaultCategoryDataset[N1final][N2final]; cdatArea = new DefaultCategoryDataset[N1final][N2final]; cdatPolar = new XYSeriesCollection[N1final][N2final]; isLog = new boolean[2]; isLog[0] = false; isLog[1] = false; xAxis = new NumberAxis[N1final][N2final]; yAxis = new NumberAxis[N1final][N2final]; xyplot = new XYPlot[N1final][N2final]; type = new HashMap[N1final][N2final]; indexdat = new int[N1final][N2final]; rdat = new ArrayList[N1final][N2final]; axisPenwidth = 3.0f; XYBarRenderer defaultrender = new XYBarRenderer(0.2D); // IntervalXYDataset intervalxydataset = new IntervalXYDataset(); tickFont = new Font("Arial", Font.BOLD, 14); labelFont = new Font("Arial", Font.BOLD, 16); labelColor = Color.BLACK; tickColor = Color.BLACK; chart = new JFreeChart[N1final][N2final]; cp = new ChartPanel[N1final][N2final]; antiAlias = true; this.title = new String[N1final][N2final]; this.titleX = new String[N1final][N2final]; this.titleY = new String[N1final][N2final]; // build empty canvas for (int i2 = 0; i2 < N2final; i2++) { for (int i1 = 0; i1 < N1final; i1++) { this.title[i1][i2] = title; this.titleX[i1][i2] = "X"; this.titleY[i1][i2] = "Y"; rdat[i1][i2] = new ArrayList<AbstractRenderer>(); xAxis[i1][i2] = new NumberAxis(titleX[i1][i2]); xAxis[i1][i2].setTickLabelPaint(tickColor); xAxis[i1][i2].setTickLabelFont(tickFont); xAxis[i1][i2].setLabelPaint(labelColor); xAxis[i1][i2].setLabelFont(labelFont); xAxis[i1][i2].setAxisLineStroke(new BasicStroke(axisPenwidth)); xAxis[i1][i2].setAxisLinePaint(Color.black); type[i1][i2] = new HashMap<Integer, String>(); indexdat[i1][i2] = 0; yAxis[i1][i2] = new NumberAxis(titleX[i1][i2]); yAxis[i1][i2].setTickLabelPaint(tickColor); yAxis[i1][i2].setTickLabelFont(tickFont); yAxis[i1][i2].setLabelPaint(labelColor); yAxis[i1][i2].setLabelFont(labelFont); yAxis[i1][i2].setAxisLineStroke(new BasicStroke(axisPenwidth)); yAxis[i1][i2].setAxisLinePaint(Color.black); xyplot[i1][i2] = new XYPlot(null, (ValueAxis) xAxis[i1][i2], (ValueAxis) yAxis[i1][i2], defaultrender); // for outline xyplot[i1][i2].setOutlinePaint(Color.black); xyplot[i1][i2].setOutlineStroke(new BasicStroke(axisPenwidth)); xyplot[i1][i2].setOutlineVisible(true); xyplot[i1][i2].setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); xyplot[i1][i2].setOrientation(PlotOrientation.VERTICAL); chart[i1][i2] = new JFreeChart(this.title[i1][i2], JFreeChart.DEFAULT_TITLE_FONT, xyplot[i1][i2], true); chart[i1][i2].setAntiAlias(antiAlias); chart[i1][i2].setBorderPaint(DEFAULT_BG_COLOR); chart[i1][i2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[i1][i2].setBorderVisible(false); cp[i1][i2] = new ChartPanel(chart[i1][i2]); cp[i1][i2].setBackground(DEFAULT_BG_COLOR); cp[i1][i2].setLayout(new BorderLayout()); cp[i1][i2].setDomainZoomable(true); cp[i1][i2].setRangeZoomable(true); if (set) mainPanel.add(cp[i1][i2]); } } setTheme("LEGACY_THEME"); }
From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithHeatMap.java
public void setData(double[] xValues, double[] yValues, double[][] zValues) { this.xValues = xValues; this.yValues = yValues; this.zValues = zValues; double minZValue = Double.MAX_VALUE; double maxZValue = Double.MIN_VALUE; int width = xValues.length; int height = yValues.length; int numCells = width * height; _log.debug("Number of cells in heat map: " + numCells); if (zValues.length != width || zValues[0].length != height) throw new RuntimeException( "PanelWithHeatMap: wrong number of z values for x and y values (" + zValues.length + " vs. " + width + ", " + zValues[0].length + " vs. " + height + ", x/y first, z second)"); DefaultXYZDataset theDataset = new DefaultXYZDataset(); double[][] data = new double[3][numCells]; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { int cellIndex = (j * width) + i; data[0][cellIndex] = xValues[i]; data[1][cellIndex] = yValues[j]; data[2][cellIndex] = zValues[i][j]; //keep track of lowest/highest z values minZValue = Math.min(zValues[i][j], minZValue); maxZValue = Math.max(zValues[i][j], maxZValue); }//from w w w . j av a2 s . com } lowerZBound = Rounder.round(minZValue, 3); upperZBound = Rounder.round(maxZValue, 3); if (lowerZBound == upperZBound) upperZBound += .0001; _log.debug("low,high values: " + lowerZBound + ", " + upperZBound); theDataset.addSeries("Range: " + lowerZBound + "-" + upperZBound, data); dataset = theDataset; if (renderer == null) { renderer = new XYBlockRenderer(); } if (paintScale == null) { setPaintScale(createPaintScale(palette)); } //This is necessary to get everything to line up renderer.setBlockAnchor(RectangleAnchor.BOTTOM); if (getPlot() != null) { ((XYPlot) getPlot()).setDataset(dataset); ((XYPlot) getPlot()).setRenderer(renderer); invalidate(); return; } XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(dataSetName, JFreeChart.DEFAULT_TITLE_FONT, plot, true); // chart.addLegend(new LegendTitle(renderer)); // PaintScaleLegend legend = new PaintScaleLegend(paintScale, xAxis); // chart.addLegend(legend); // LegendItemCollection c1 = new LegendItemCollection(); // // LegendItem item1 = new LegendItem("Label", "Description", // "ToolTip", "URL", true, // new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red, // true, Color.blue, new BasicStroke(1.2f), true, // new Line2D.Double(1.0, 2.0, 3.0, 4.0), // new BasicStroke(2.1f), Color.green); // LegendItem item2 = new LegendItem("Label", "Description", // "ToolTip", "URL", true, // new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), // true, Color.red, true, Color.blue, new BasicStroke(1.2f), true, // new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), // Color.green); // c1.add(item1); // // chart.getLegend().setSources(new LegendItemSource[]{renderer}); init(chart); }
From source file:edu.scripps.fl.curves.plot.CurvePlot.java
public void init() { dataset = new YIntervalSeriesCollection(); LogAxis xAxis = new LogAxis(xAxisLabel) { @Override//w w w . j a v a2s. co m public NumberFormat getNumberFormatOverride() { return nf; } protected String createTickLabel(double value) { return getNumberFormatOverride().format(value); } }; xAxis.setTickUnit(new NumberTickUnit(1.0, nf)); xAxis.setTickMarksVisible(true); // xAxis.setTickLabelFont(font); // now set in separate method NumberAxis yAxis = new NumberAxis(yAxisLabel); // yAxis.setRange(-20, 120); // yAxis.setTickLabelFont(font); yAxis.setTickUnit(new NumberTickUnit(25)); plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeMinorGridlinesVisible(true); // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); MyXYErrorRenderer renderer = new MyXYErrorRenderer(); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.WHITE); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.WHITE); plot.setDrawingSupplier(new CurvePlotDrawingSupplier()); }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createScatterChart(XYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); }/* w ww .jav a2 s. com*/ XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart("Scatter Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); 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); yAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
private static JFreeChart createCustomXYStepChart(TimePeriodValuesCollection prices) { DateAxis xAxis = new DateAxis(null); NumberAxis yAxis = new NumberAxis("price"); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); XYPlot plot = new XYPlot(prices, xAxis, yAxis, null); plot.setRenderer(new XYStepRenderer(null, null)); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:net.sf.maltcms.common.charts.api.XYChartBuilder.java
/** * * @return//from ww w . j av a2 s . c om */ public XYChartBuilder plot() { notNull(dataset, "Dataset must not be null!"); notNull(domainAxis, "Domain axis must not be null!"); notNull(rangeAxis, "Range axis must not be null!"); notNull(renderer, "Renderer must not be null!"); notNull(tooltipGenerator, "Tooltip generator must not be null!"); XYPlot xyplot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); this.plot = xyplot; renderer.setBaseToolTipGenerator(tooltipGenerator); if (datasetSeriesColorMap == null) { ChartCustomizer.setSeriesColors(xyplot, 0.9f); } else { setDatasetSeriesColorMap(renderer, datasetSeriesColorMap); } return this; }
From source file:crossspectrumapp.CrossSpectrumApp.java
private void plotData(double[] frequency, double[] power, double[] phase, String title, String subTitleText1, String subTitleText2) throws WebUtilException { XYSeries asdSeries = new XYSeries("asd"); XYSeries phiSeries = new XYSeries("phase"); for (int i = 1; i < frequency.length; i++) { double f = frequency[i]; double pwr = power[i]; double phi = phase[i]; asdSeries.add(f, pwr);// w w w.j a v a 2 s .com phiSeries.add(f, phi); } XYSeriesCollection asdCollection = new XYSeriesCollection(); asdCollection.addSeries(asdSeries); XYSeriesCollection phiCollection = new XYSeriesCollection(); phiCollection.addSeries(phiSeries); // create the chart XYItemRenderer asdRenderer = new StandardXYItemRenderer(); LogAxis asdAxis = new LogAxis("ASD counts/ \u221AHz"); XYPlot asdSubplot = new XYPlot(asdCollection, null, asdAxis, asdRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYItemRenderer phiRenderer = new StandardXYItemRenderer(); NumberAxis phiAxis = new NumberAxis("Phase degrees"); XYPlot phiSubplot = new XYPlot(phiCollection, null, phiAxis, phiRenderer); asdSubplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new LogAxis("Frequency (Hz)")); plot.setGap(10.0); // add the subplots... plot.add(asdSubplot, 2); plot.add(phiSubplot, 1); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); Title subTitle = new TextTitle(subTitleText1); chart.addSubtitle(subTitle); subTitle = new TextTitle(subTitleText2); chart.addSubtitle(subTitle); ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); panel.setPreferredSize(new java.awt.Dimension(cscl.getOutX(), cscl.getOutY())); FileOutputStream fos = null; try { fos = new FileOutputStream(cscl.getOfileName()); ChartUtilities.writeChartAsPNG(fos, chart, cscl.getOutX(), cscl.getOutY()); fos.close(); fos = null; } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } } }
From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java
private static JFreeChart createTimeSeriesChart() { XYDataset dataset1 = createDataset1(); //DomainAxis// w w w . j a va 2s.c o m DateAxis timeAxis = new DateAxis(""); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); //RangeAxis NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); // override default NumberAxis valueAxis2 = new NumberAxis(""); valueAxis2.setAutoRangeIncludesZero(false); // override default // valueAxis.setDefaultAutoRange(new Range(100, 1150)); //Renderer XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); XYDataset dataset2 = createDataset2(); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); //Plot XYPlot plot = new XYPlot(dataset1, timeAxis, valueAxis, null); plot.setRenderer(renderer); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.setRangeAxis(1, valueAxis2); plot.mapDatasetToRangeAxis(1, 1); plot.setBackgroundPaint(plotBackgroundPaint); 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); // plot.setRangePannable(true); //chart JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); valueAxis.setAutoRange(false); timeAxis.setAutoRange(false); return chart; }
From source file:org.gumtree.vis.awt.PlotFactory.java
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings.// ww w .j a v a2 s. co m * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ protected static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } // NumberAxis xAxis = new NumberAxis(xAxisLabel); LogarithmizableAxis xAxis = new LogarithmizableAxis(xAxisLabel); boolean isLogX = false; try { isLogX = Boolean.valueOf(System.getProperty(LOGX_PROPERTY)); } catch (Exception e) { } xAxis.setLogarithmic(isLogX); // xAxis.setAutoRangeIncludesZero(false); xAxis.setAllowNegativesFlag(true); xAxis.setLowerMargin(0.02); xAxis.setUpperMargin(0.02); // NumberAxis yAxis = new NumberAxis(yAxisLabel); LogarithmizableAxis yAxis = new LogarithmizableAxis(yAxisLabel); boolean isLogY = false; try { isLogY = Boolean.valueOf(System.getProperty(LOGY_PROPERTY)); } catch (Exception e) { } yAxis.setLogarithmic(isLogY); yAxis.setAllowNegativesFlag(true); yAxis.setAutoRangeNextLogFlag(false); yAxis.setLowerMargin(0.02); yAxis.setUpperMargin(0.02); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseLinesVisible(true); renderer.setBaseShapesVisible(false); renderer.setDrawYError(true); // XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chartTheme.apply(chart); return chart; }