List of usage examples for org.jfree.chart.plot XYPlot setRangeGridlinesVisible
public void setRangeGridlinesVisible(boolean visible)
From source file:asl.util.PlotMaker.java
public void plotSpecAmp2(double freq[], double[] amp1, double[] phase1, double[] amp2, double[] phase2, String plotTitle, String pngName) { /**//from w ww. j av a2 s . c o m final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR) ,station, channel, plotString); final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR) ,station, channel, plotString); **/ File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotSpecAmp: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return; } // Plot x-axis (frequency) range final double XMIN = .00009; final double XMAX = freq[freq.length - 1]; System.out.format("== plotSpecAmp2: nfreq=%d npts=%d pngName=%s\n", freq.length, amp2.length, pngName); final XYSeries series1 = new XYSeries("Amp_PZ"); final XYSeries series1b = new XYSeries("Amp_Cal"); final XYSeries series2 = new XYSeries("Phase_PZ"); final XYSeries series2b = new XYSeries("Phase_Cal"); double maxdB = 0.; for (int k = 0; k < freq.length; k++) { double dB = amp1[k]; //double dB = 20. * Math.log10( amp1[k] ); //series1.add( freq[k], dB ); //series1.add( freq[k], 20. * Math.log10( amp1[k] ) ); //series1b.add(freq[k], 20. * Math.log10( amp2[k] )); series1.add(freq[k], amp1[k]); series1b.add(freq[k], amp2[k]); series2.add(freq[k], phase1[k]); series2b.add(freq[k], phase2[k]); if (dB > maxdB) { maxdB = dB; } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); //renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); Paint[] paints = new Paint[] { Color.red, Color.blue }; renderer.setSeriesPaint(0, paints[0]); //renderer.setSeriesPaint(1, paints[1]); final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesPaint(0, paints[1]); renderer2.setSeriesShapesVisible(0, false); renderer2.setSeriesLinesVisible(0, true); // Stroke is part of Java Swing ... //renderer2.setBaseStroke( new Stroke( ... ) ); double ymax; if (maxdB < 10) { ymax = 10.; } else { ymax = maxdB + 2; ; } final NumberAxis verticalAxis = new NumberAxis("Spec Amp (dB)"); verticalAxis.setRange(new Range(-40, ymax)); verticalAxis.setTickUnit(new NumberTickUnit(5)); //final LogarithmicAxis verticalAxis = new LogarithmicAxis("Amplitude Response"); //verticalAxis.setRange( new Range(0.01 , 10) ); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Frequency (Hz)"); //horizontalAxis.setRange( new Range(0.0001 , 100.5) ); //horizontalAxis.setRange( new Range(0.00009 , 110) ); horizontalAxis.setRange(new Range(XMIN, XMAX)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); seriesCollection.addSeries(series1b); final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, null, verticalAxis, renderer); //final XYPlot xyplot = new XYPlot((XYDataset)seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final NumberAxis phaseAxis = new NumberAxis("Phase (Deg)"); phaseAxis.setRange(new Range(-180, 180)); phaseAxis.setTickUnit(new NumberTickUnit(30)); final XYSeriesCollection seriesCollection2 = new XYSeriesCollection(); seriesCollection2.addSeries(series2); seriesCollection2.addSeries(series2b); final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, phaseAxis, renderer2); //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL ); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.add(xyplot, 1); combinedPlot.add(xyplot2, 1); combinedPlot.setGap(15.); //final JFreeChart chart = new JFreeChart(xyplot); final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1000, 800); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:net.nosleep.superanalyzer.analysis.views.GrowthView.java
private void createChart() { _chart = ChartFactory.createXYAreaChart(Misc.getString("LIBRARY_GROWTH"), Misc.getString("DATE"), Misc.getString("SONGS_IN_LIBRARY"), _dataset, PlotOrientation.VERTICAL, false, // legend true, // tool tips false // URLs );/*from w ww. j a v a 2 s. c o m*/ XYPlot plot = (XYPlot) _chart.getPlot(); plot.setDomainPannable(true); ValueAxis domainAxis = new DateAxis(Misc.getString("TIME")); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); plot.setDomainAxis(domainAxis); plot.setForegroundAlpha(0.75f); XYItemRenderer renderer = plot.getRenderer(); renderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("#,##0.00"))); _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("LIBRARY_GROWTH_SUBTITLE"))); ChartUtilities.applyCurrentTheme(_chart); Misc.formatChart(plot); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); renderer.setSeriesPaint(0, Theme.getColorSet()[1]); }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Generates a Sparkline Bar Graph./*from ww w . j a v a2 s. c o m*/ * * @param def the key of the statistic object. * @return the generated chart. */ public JFreeChart generateSparklineBarGraph(String key, String color, Statistic[] def, long startTime, long endTime, int dataPoints) { Color backgroundColor = getBackgroundColor(); IntervalXYDataset dataset = (IntervalXYDataset) populateData(key, def, startTime, endTime, dataPoints); JFreeChart chart = ChartFactory.createXYBarChart(null, // chart title null, // domain axis label true, null, // range axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend false, // tooltips? false // URLs? ); chart.setBackgroundPaint(backgroundColor); chart.setBorderVisible(false); chart.setBorderPaint(null); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(backgroundColor); plot.setRangeGridlinesVisible(false); GraphDefinition graphDef = GraphDefinition.getDefinition(color); Color plotColor = graphDef.getInlineColor(0); plot.getRenderer().setSeriesPaint(0, plotColor); plot.getRenderer().setBaseItemLabelsVisible(false); plot.getRenderer().setBaseOutlinePaint(backgroundColor); plot.setOutlineStroke(null); plot.setDomainGridlinePaint(null); ValueAxis xAxis = chart.getXYPlot().getDomainAxis(); xAxis.setLabel(null); xAxis.setTickLabelsVisible(true); xAxis.setTickMarksVisible(true); xAxis.setAxisLineVisible(false); xAxis.setNegativeArrowVisible(false); xAxis.setPositiveArrowVisible(false); xAxis.setVisible(false); ValueAxis yAxis = chart.getXYPlot().getRangeAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setAxisLineVisible(false); yAxis.setNegativeArrowVisible(false); yAxis.setPositiveArrowVisible(false); yAxis.setVisible(false); return chart; }
From source file:adams.flow.sink.JFreeChartFileWriter.java
/** * Executes the flow item.//from w w w. j a va 2 s . c o m * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; SpreadSheet sheet; Dataset dataset; JFreeChart jfreechart; BufferedImage image; BufferedImageContainer cont; Shape shape; XYPlot plot; result = null; try { sheet = (SpreadSheet) m_InputToken.getPayload(); dataset = m_Dataset.generate(sheet); jfreechart = m_Chart.generate(dataset); shape = m_Shape.generate(); jfreechart.getPlot().setBackgroundPaint(Color.WHITE); if (jfreechart.getPlot() instanceof XYPlot) { plot = (XYPlot) jfreechart.getPlot(); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.GRAY); plot.getRenderer().setSeriesPaint(0, m_PlotColor); if (plot.getSeriesCount() > 1) plot.getRenderer().setSeriesPaint(1, m_DiagonalColor); if (shape != null) plot.getRenderer().setSeriesShape(0, shape); } image = jfreechart.createBufferedImage(m_Width, m_Height); cont = new BufferedImageContainer(); cont.setImage(image); m_Writer.write(m_OutputFile, cont); } catch (Exception e) { result = handleException("Failed to generate plot!", e); } return result; }
From source file:org.jstockchart.plot.TimeseriesPlot.java
private XYPlot createPricePlot() { Font axisFont = new Font("Arial", 0, 12); Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); PriceArea priceArea = timeseriesArea.getPriceArea(); Color averageColor = new Color(243, 182, 117); priceArea.setAverageColor(averageColor); priceArea.setPriceColor(Color.BLUE); TimeSeriesCollection priceDataset = new TimeSeriesCollection(); priceDataset.addSeries(dataset.getPriceTimeSeries().getTimeSeries()); if (priceArea.isAverageVisible()) { priceDataset.addSeries(dataset.getAverageTimeSeries().getTimeSeries()); }// w ww . j av a2 s . co m CentralValueAxis logicPriceAxis = priceArea.getLogicPriceAxis(); logicPriceAxis.setTickCount(7); CFXNumberAxis priceAxis = new CFXNumberAxis(logicPriceAxis.getLogicTicks()); priceAxis.setShowUD(true); priceAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); priceAxis.setTickMarksVisible(false); XYLineAndShapeRenderer priceRenderer = new XYLineAndShapeRenderer(true, false); priceAxis.setUpperBound(logicPriceAxis.getUpperBound()); priceAxis.setLowerBound(logicPriceAxis.getLowerBound()); priceAxis.setAxisLineVisible(false); priceAxis.setTickLabelFont(axisFont); priceRenderer.setSeriesPaint(0, priceArea.getPriceColor()); priceRenderer.setSeriesPaint(1, priceArea.getAverageColor()); CFXNumberAxis rateAxis = new CFXNumberAxis(logicPriceAxis.getRatelogicTicks()); rateAxis.setShowUD(true); rateAxis.setOpenPrice(logicPriceAxis.getCentralValue().doubleValue()); rateAxis.setTickMarksVisible(false); ; rateAxis.setTickLabelFont(axisFont); rateAxis.setAxisLineVisible(false); rateAxis.setUpperBound(logicPriceAxis.getUpperBound()); rateAxis.setLowerBound(logicPriceAxis.getLowerBound()); XYPlot plot = new XYPlot(priceDataset, null, priceAxis, priceRenderer); plot.setBackgroundPaint(priceArea.getBackgroudColor()); plot.setOrientation(priceArea.getOrientation()); plot.setRangeAxisLocation(priceArea.getPriceAxisLocation()); plot.setRangeMinorGridlinesVisible(false); Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f, new float[] { 1.0f, 1.0f }, 1.0f); Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 2.0f, 2.0f }, 1.0f); plot.setRangeGridlineStroke(gridLineStroke); plot.setDomainGridlineStroke(gridLineStroke); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setOutlineVisible(true); plot.setOutlineStroke(outLineStroke); plot.setOutlinePaint(Color.BLACK); if (priceArea.isRateVisible()) { plot.setRangeAxis(1, rateAxis); plot.setRangeAxisLocation(1, priceArea.getRateAxisLocation()); plot.setDataset(1, null); plot.mapDatasetToRangeAxis(1, 1); } if (priceArea.isMarkCentralValue()) { Number centralPrice = logicPriceAxis.getCentralValue(); if (centralPrice != null) { plot.addRangeMarker(new ValueMarker(centralPrice.doubleValue(), priceArea.getCentralPriceColor(), new BasicStroke())); } } return plot; }
From source file:financepro.XYLineChartExample.java
License:asdf
private JPanel createChartPanel() { // creates a line chart object // returns the chart panel String chartTitle = "Various Financial Ratios"; String xAxisLabel = "Years"; String yAxisLabel = "Ratio Values"; XYDataset dataset = createDataset(); JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer);/* w w w.j a v a 2s . c o m*/ renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesPaint(2, Color.YELLOW); renderer.setSeriesPaint(3, Color.CYAN); renderer.setSeriesPaint(4, Color.BLACK); renderer.setSeriesStroke(0, new BasicStroke(4.0f)); renderer.setSeriesStroke(1, new BasicStroke(4.0f)); renderer.setSeriesStroke(2, new BasicStroke(4.0f)); renderer.setSeriesStroke(3, new BasicStroke(4.0f)); renderer.setSeriesStroke(4, new BasicStroke(4.0f)); plot.setRenderer(renderer); plot.setOutlinePaint(Color.BLUE); plot.setOutlineStroke(new BasicStroke(4.0f)); plot.setBackgroundPaint(Color.DARK_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); return new ChartPanel(chart); }
From source file:ucar.unidata.idv.control.chart.PlotWrapper.java
/** * Utility to init xy plots/*from ww w.j av a 2 s.c o m*/ * * @param plot the plotx */ protected void initXYPlot(XYPlot plot) { plot.setBackgroundPaint(dataAreaColor); // plot.setAxisOffset(new RectangleInsets(6.0, 3.0, 3.0, 3.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setDomainGridlinesVisible(domainLineState.getVisible()); plot.setRangeGridlinesVisible(rangeLineState.getVisible()); plot.setDomainGridlinePaint(domainLineState.getColor()); plot.setRangeGridlinePaint(rangeLineState.getColor()); plot.setDomainGridlineStroke(domainLineState.getStroke()); plot.setRangeGridlineStroke(rangeLineState.getStroke()); }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Generates a SparkLine Time Area Chart. * @param key//from ww w . j a v a 2 s . co m * @param stats * @param startTime * @param endTime * @return chart */ private JFreeChart generateSparklineAreaChart(String key, String color, Statistic[] stats, long startTime, long endTime, int dataPoints) { Color backgroundColor = getBackgroundColor(); XYDataset dataset = populateData(key, stats, startTime, endTime, dataPoints); JFreeChart chart = ChartFactory.createXYAreaChart(null, // chart title null, // xaxis label null, // yaxis label dataset, // data PlotOrientation.VERTICAL, false, // include legend false, // tooltips? false // URLs? ); chart.setBackgroundPaint(backgroundColor); chart.setBorderVisible(false); chart.setBorderPaint(null); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(1.0f); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setBackgroundPaint(backgroundColor); plot.setRangeGridlinesVisible(false); GraphDefinition graphDef = GraphDefinition.getDefinition(color); Color plotColor = graphDef.getInlineColor(0); plot.getRenderer().setSeriesPaint(0, plotColor); plot.getRenderer().setBaseItemLabelsVisible(false); plot.getRenderer().setBaseOutlinePaint(backgroundColor); plot.setOutlineStroke(null); plot.setDomainGridlinePaint(null); NumberAxis xAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); xAxis.setLabel(null); xAxis.setTickLabelsVisible(true); xAxis.setTickMarksVisible(true); xAxis.setAxisLineVisible(false); xAxis.setNegativeArrowVisible(false); xAxis.setPositiveArrowVisible(false); xAxis.setVisible(false); NumberAxis yAxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickMarksVisible(false); yAxis.setAxisLineVisible(false); yAxis.setNegativeArrowVisible(false); yAxis.setPositiveArrowVisible(false); yAxis.setVisible(false); return chart; }
From source file:no.met.jtimeseries.chart.ChartPlotter.java
/** * Add arrow symobl to the chart. Specify height to follow value curve. * Plot in the middle of chart if height is null. * /* ww w. ja va 2s. c o m*/ * @param direction * The direction of arrow * @param height * The followed height * @param offset * The offset value to follow the height, value is between * [-1,1] */ public void addArrowDirectionPlot(NumberPhenomenon direction, NumberPhenomenon height, double offset, PlotStyle plotStyle) { XYArrowRenderer arrowRender = new XYArrowRenderer(); arrowRender.setSeriesVisibleInLegend(0, false); arrowRender.setSeriesPaint(0, plotStyle.getSeriesColor()); ArrowDataset dataset = Utility.toChartArrowDataset(direction, height, offset); XYPlot arrowPlot = new XYPlot(dataset, plot.getDomainAxis(0), plotStyle.getNumberAxis(), arrowRender); arrowPlot.setRangeGridlinesVisible(false); arrowPlot.setOutlineVisible(false); plot.mapDatasetToRangeAxis(plotIndex, rangeAxisIndex); plot.setDataset(plotIndex, dataset); plot.setRenderer(plotIndex, arrowRender); plotIndex++; rangeAxisIndex++; }
From source file:IHM.compargraph.java
/** * * @param title/*www. j a va 2 s. c om*/ * @param c1 * @param c2 * @param comp * */ public compargraph(String title, ArrayList<ReleveMeteo> c1, ArrayList<ReleveMeteo> c2, String comp) { super(title); t1 = c1; t2 = c2; c = comp; // jp = new JInternalFrame("courbes"); JFreeChart chart = createChart(createDataset()); ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(500, 300)); setContentPane(panel); // jp.add(panel, BorderLayout.EAST); // jp.setVisible(true); panel.setVisible(true); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GREEN); renderer.setSeriesPaint(2, Color.YELLOW); // sets thickness for series (using strokes) renderer.setSeriesStroke(0, new BasicStroke(4.0f)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); renderer.setSeriesStroke(2, new BasicStroke(2.0f)); plot.setRenderer(renderer); plot.setOutlinePaint(Color.BLUE); plot.setOutlineStroke(new BasicStroke(2.0f)); plot.setBackgroundPaint(Color.DARK_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); }