List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:be.ac.ua.comp.scarletnebula.gui.DecoratedGraph.java
/** * @see Graph//from ww w. ja va 2 s. co m */ @Override public ChartPanel getChartPanel() { final XYPlot plot = new XYPlot(dataset, domain, range, renderer); plot.setBackgroundPaint(Color.darkGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setInsets(new RectangleInsets(0, 0, 0, 0)); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); if (stream.getMax() != null) { log.info("Getting chart panel for stream with maximum."); range.setAutoRange(false); range.setTickUnit(new NumberTickUnit(stream.getMax() / 10, new DecimalFormat(), 1)); range.setRange(0, stream.getMax()); } else if (stream.getType() == Type.RELATIVE) { range.setAutoRange(false); range.setTickUnit(new NumberTickUnit(0.1, new DecimalFormat(), 1)); range.setRange(0, 1); } else { double sum = 0; final List<TimedDatapoint> datapoints = stream.getRecentlyProcessedDatapoints(); range.setTickUnit( new NumberTickUnit((int) (Utils.max(datapoints).getValue() / 5) + 1, new DecimalFormat(), 1)); } final JFreeChart chart = new JFreeChart(stream.getStreamname(), new Font("SansSerif", Font.PLAIN, 20), plot, true); chart.setBackgroundPaint(Color.white); chart.removeLegend(); final ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setBorder(BorderFactory // .createBevelBorder(BevelBorder.LOWERED)); return chartPanel; }
From source file:com.idealista.solrmeter.view.statistic.HistogramChartPanel.java
private Component createChartPanel() { XYBarDataset xyBarDataset = new XYBarDataset(xyDataset, BAR_WIDTH); NumberAxis xaxis = new NumberAxis(I18n.get("statistic.histogramChartPanel.time")); NumberAxis yaxis = new NumberAxis(I18n.get("statistic.histogramChartPanel.numberOfQueries")); xaxis.setStandardTickUnits(//www. ja v a2 s. c o m new ChartUtils.LowerBoundedTickUnitSource(xaxis.getStandardTickUnits(), LOWER_TICK_UNIT)); XYPlot plot = new XYPlot(xyBarDataset, xaxis, yaxis, new XYBarRenderer()); JFreeChart chart = new JFreeChart(I18n.get("statistic.histogramChartPanel.title"), null, plot, false); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBorder(CHART_BORDER); chartPanel.setMinimumDrawHeight(0); chartPanel.setMinimumDrawWidth(0); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); return chartPanel; }
From source file:org.kurento.test.latency.ChartWriter.java
public void drawChart(String filename, int width, int height) throws IOException { // Create plot NumberAxis xAxis = new NumberAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYSplineRenderer renderer = new XYSplineRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); // Create chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartUtilities.applyCurrentTheme(chart); ChartPanel chartPanel = new ChartPanel(chart, false); // Draw png// w w w.j a va 2 s .c o m BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics graphics = bi.getGraphics(); chartPanel.setBounds(0, 0, width, height); chartPanel.paint(graphics); ImageIO.write(bi, "png", new File(filename)); }
From source file:org.jfree.chart.demo.MemoryUsageDemo.java
public MemoryUsageDemo(int i) { super(new BorderLayout()); total = new TimeSeries("Total Memory"); total.setMaximumItemAge(i);/* ww w . ja v a 2 s . c om*/ free = new TimeSeries("Free Memory"); free.setMaximumItemAge(i); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(total); timeseriescollection.addSeries(free); DateAxis dateaxis = new DateAxis("Time"); NumberAxis numberaxis = new NumberAxis("Memory"); dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12)); dateaxis.setLabelFont(new Font("SansSerif", 0, 14)); numberaxis.setLabelFont(new Font("SansSerif", 0, 14)); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false); xylineandshaperenderer.setSeriesPaint(0, Color.red); xylineandshaperenderer.setSeriesPaint(1, Color.green); xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F, 0, 2)); xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(3F, 0, 2)); XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); dateaxis.setAutoRange(true); dateaxis.setLowerMargin(0.0D); dateaxis.setUpperMargin(0.0D); dateaxis.setTickLabelsVisible(true); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true); jfreechart.setBackgroundPaint(Color.white); ChartPanel chartpanel = new ChartPanel(jfreechart, true); chartpanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(chartpanel); }
From source file:ch.zhaw.ias.dito.ui.util.BlockPlotPanel.java
public BlockPlotPanel(Matrix m, double lowerBound, double upperBound) { super(new BorderLayout()); NumberAxis xAxis = new NumberAxis(); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xAxis.setLowerMargin(1.0);/*from w ww . j a va 2 s .co m*/ xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setLowerMargin(1.0); yAxis.setUpperMargin(0.0); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBaseToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { XYZDataset xyzDataset = (XYZDataset) dataset; double x = xyzDataset.getXValue(series, item); double y = xyzDataset.getYValue(series, item); double z = xyzDataset.getZValue(series, item); return ("X=" + x + ", Y=" + y + ", Z=" + z); } }); PaintScale scale = new ColorPaintScale(lowerBound, upperBound); renderer.setPaintScale(scale); ValueAxis axis = new NumberAxis(); axis.setLowerBound(scale.getLowerBound()); axis.setUpperBound(scale.getUpperBound()); PaintScaleLegend legend = new PaintScaleLegend(scale, axis); legend.setMargin(new RectangleInsets(10, 10, 10, 10)); legend.setPosition(RectangleEdge.RIGHT); MatrixXYDataset dataset = new MatrixXYDataset(m); plot = new XYPlot(dataset, xAxis, yAxis, renderer); chart = new JFreeChart(plot); chart.removeLegend(); chart.addSubtitle(legend); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setDisplayToolTips(true); this.add(chartPanel, BorderLayout.CENTER); }
From source file:org.jfree.chart.demo.SymbolicChartDemo1.java
/** * A demonstration application.//from w ww. ja v a 2 s . co m * * @param title * the frame title. */ public SymbolicChartDemo1(final String title) { super(title); // create a title... final XYDataset dataset = createDataset(); final ValueAxis domainAxis = new NumberAxis("X"); final SymbolicAxis symbolicAxis = new SymbolicAxis("Y", ((YisSymbolic) dataset).getYSymbolicValues()); final XYPlot plot = new XYPlot(dataset, domainAxis, symbolicAxis, null); final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, new SymbolicXYItemLabelGenerator()); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart(title, plot); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:graph.jfreecharts.GraphFunction.java
/** * A custom xyerror renderer because jfreecharts does not * have it supported in the api.//from w w w . ja va 2 s . c o m * @param title the graph title * @param xAxisLabel the xaxis title * @param yAxisLabel the yaxis title * @param dataset the xydataset * @param orientation the plot orientation * @param legend true to turn on legend * @param tooltips true to turn on tooltips (the pop up when right click) * @param urls // no idea what this is for * @return */ private static JFreeChart createXYIntervalChart(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); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setDrawXError(true); renderer.setDrawYError(true); xAxis.setNumberFormatOverride(new DecimalFormat("0.######E0")); yAxis.setNumberFormatOverride(new DecimalFormat("0.######E0")); xAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRangeIncludesZero(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); currentTheme.apply(chart); return chart; }
From source file:ste.travian.world.WorldChart.java
/** * Create the JFreeChart world chart/*from ww w . j a va2s . c o m*/ * * @param title world title * @param dataset world data set * */ private void createWorldPlot(String title, XYDataset dataset) { NumberAxis xAxis = new NumberAxis(LABEL_X_AXIS); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(LABEL_Y_AXIS); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); TileRenderer renderer = new TileRenderer(3, 3); renderer.setBaseToolTipGenerator(new TileToolTipGenerator()); plot.setRenderer(renderer); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java
/** * Creates a XY graph with symbolic value on X and Y axis. * //from w w w .j a v a 2 s .c om * @param title * the title. * @param xAxisLabel * the x axis label. * @param yAxisLabel * the y axis label. * @param data * the dataset. * @param legend * create a legend? * @return a chart. */ public static JFreeChart createXYSymbolicPlot(final String title, final String xAxisLabel, final String yAxisLabel, final XYDataset data, final boolean legend) { final SymbolicAxis xSymbolicAxis = new SymbolicAxis(xAxisLabel, ((XisSymbolic) data).getXSymbolicValues()); final SymbolicAxis ySymbolicAxis = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data).getYSymbolicValues()); final XYPlot plot = new XYPlot(data, xSymbolicAxis, ySymbolicAxis, null); final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, new SymbolicXYItemLabelGenerator()); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.jfree.chart.demo.TimePeriodValuesDemo2.java
/** * A demonstration application showing how to.... * * @param title the frame title.//www .ja v a2 s .c o m */ public TimePeriodValuesDemo2(final String title) { super(title); final XYDataset data1 = createDataset(); final XYItemRenderer renderer1 = new XYBarRenderer(); final DateAxis domainAxis = new DateAxis("Date"); final ValueAxis rangeAxis = new NumberAxis("Value"); final XYPlot plot = new XYPlot(data1, domainAxis, rangeAxis, renderer1); final JFreeChart chart = new JFreeChart("Time Period Values Demo", plot); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); }