List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:Operacional.Janela2.java
private static JFreeChart createChart(IntervalXYDataset intervalxydataset) { JFreeChart jfreechart = ChartFactory.createXYBarChart("Dados Parquimetro", "Mes", true, "Dados", intervalxydataset, PlotOrientation.VERTICAL, true, false, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = jfreechart.getXYPlot(); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); StandardXYToolTipGenerator standardxytooltipgenerator = new StandardXYToolTipGenerator("{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0")); //xyitemrenderer.setToolTipGenerator(standardxytooltipgenerator); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setRangeGridlinePaint(Color.white); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); dateaxis.setLowerMargin(0.01D);//from ww w.j a v a 2 s . c o m dateaxis.setUpperMargin(0.01D); return jfreechart; }
From source file:org.matsim.contrib.socnetsim.usage.analysis.CourtesyHistogramListener.java
static JFreeChart getGraphic(final CourtesyHistogram.DataFrame dataFrame, int iteration, String actType) { final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries helloSeries = new XYSeries("hello", false, true); final XYSeries goodbyeSerie = new XYSeries("goodbye", false, true); final XYSeries togetherSerie = new XYSeries("pairs together", false, true); int together = 0; for (int i = 0; i < dataFrame.countsHello.length; i++) { together = together + dataFrame.countsHello[i] - dataFrame.countsGoodbye[i]; double hour = i * dataFrame.binSize / 60.0 / 60.0; helloSeries.add(hour, dataFrame.countsHello[i]); goodbyeSerie.add(hour, dataFrame.countsGoodbye[i]); togetherSerie.add(hour, together); }/*from w w w . j a v a2s . c o m*/ xyData.addSeries(helloSeries); xyData.addSeries(goodbyeSerie); xyData.addSeries(togetherSerie); final JFreeChart chart = ChartFactory.createXYStepChart( "Courtesy Statistics," + "actType " + actType + " it." + iteration, "time", "# persons", xyData, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("time")); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f)); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); plot.setDomainGridlinePaint(Color.gray); return chart; }
From source file:Methods.CalculusNewtonRaphson.java
public static ChartPanel createChartNewtonRapson(XYDataset datasetFunction) {// Method that populates and returns a Chart Pannel object, uses an entering paramether for the equation dataset and a global variable for the iteration points data set datasetPointsNewtonRapson();//from w w w. jav a 2s. c o m JFreeChart chart = ChartFactory.createXYLineChart("Equation Chart", "X Axys", "Y Axys", datasetFunction, PlotOrientation.VERTICAL, true, true, false);//creating a object table wich takes the methods arguments as a dataset XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();//declaring a renderer used to plot more than one datatset on the table plot.setDataset(1, datasetPoints); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(1, renderer); return new ChartPanel(chart); }
From source file:ch.zhaw.parallelComputing.view.Plotter.java
/** * Generates a plot for comparing to datasets * @param title the name of the plot// w ww. j a v a2 s. c o m * @param dataset1 the first data set for plotting * @param dataset2 the second data set for plotting * @return a chart object for displaying or saving as picture */ public static JFreeChart plot(String title, XYDataset dataset1, XYDataset dataset2) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title "Date", // x-axis label "Input Value", // y-axis label dataset1, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); XYPlot plot = chart.getXYPlot(); Axis axis1 = plot.getRangeAxis(0); axis1.setLabelPaint(Color.red); NumberAxis axis2 = new NumberAxis("Twitter"); axis2.setLabelPaint(Color.blue); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.blue); renderer.setBaseShapesVisible(false); plot.setRenderer(1, renderer); return chart; }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
private static ValueAxis setLowerBoundsZero(JFreeChart chart) { ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); rangeAxis.setLowerMargin(40);/*from w w w . j a v a 2 s . c o m*/ rangeAxis.setLowerBound(0.0); return rangeAxis; }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
public static ChartPanel buildChartPanelForAllAttributes(final Instances dataSet, final boolean multAxis, final int dateIdx, final Color color, final Collection<XYAnnotation> annotations) { final TimeSeriesCollection tsDataset = new TimeSeriesCollection(); final JFreeChart tsChart = ChartFactory.createTimeSeriesChart("", "Time", "Value", tsDataset, true, true, false);/*from w ww . ja v a 2s . c om*/ tsChart.getXYPlot().setBackgroundPaint(Color.WHITE); // optimized renderer to avoid to print all points tsChart.getXYPlot().setRenderer(new SamplingXYLineRenderer()); //tsChart.getXYPlot().setRenderer(new XYStepRenderer()); if (color == null) { for (int i = 0; i < dataSet.numAttributes() - 1; i++) { final String attrName = dataSet.attribute(i).name(); tsChart.getXYPlot().getRenderer().setSeriesPaint(i, ColorHelper.getColorForAString(attrName)); } } else { tsChart.getXYPlot().getRenderer().setSeriesPaint(0, color); } if (annotations != null) { for (final XYAnnotation aa : annotations) tsChart.getXYPlot().addAnnotation(aa); } if (multAxis) fillWithMultipleAxis(dataSet, dateIdx, tsDataset, tsChart); else fillWithSingleAxis(dataSet, dateIdx, tsDataset); final ChartPanel cp = new ChartPanel(tsChart, true); if (dataSet.numAttributes() <= 2) cp.setBorder(new TitledBorder(dataSet.attribute(0).name())); return cp; }
From source file:flow.visibility.pcap.FlowProcess.java
private static JFreeChart createChart(XYSeriesCollection dataset) { /** The function to create the chart */ JFreeChart Chart = ChartFactory.createHistogram("Number Packets of Flows", "Flow Number", "Number of Packets", dataset, PlotOrientation.VERTICAL, false, false, false); Chart.getXYPlot().setForegroundAlpha(0.75f); return Chart; }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
public static ChartPanel buildChartPanelForAllAttributesInterval(final Instances dataSet, final int dateIdx, final double deviation, final int deviatedAttrIdx) { final YIntervalSeriesCollection tsDataset = new YIntervalSeriesCollection(); final JFreeChart tsChart = ChartFactory.createTimeSeriesChart("", "Time", "Value", tsDataset, true, true, false);//w w w .ja va2 s .com tsChart.getXYPlot().setBackgroundPaint(Color.WHITE); double startgap0 = -1d; double endgap0 = -1d; try { java.util.List<double[]> gaps = WekaTimeSeriesUtil.findGaps(dataSet, deviatedAttrIdx); startgap0 = gaps.get(0)[2] + gaps.get(0)[3]; //System.out.println("start -> "+startgap0); endgap0 = gaps.get(1)[2] - 1; //System.out.println("end -> "+endgap0); } catch (Exception e) { e.printStackTrace(); } final double startgap = startgap0; final double endgap = endgap0; System.out.println("gap --> " + startgap + " " + endgap); tsChart.getXYPlot().setRenderer(/*deviatedAttrIdx,*/new DeviationRenderer(true, false) { /** */ private static final long serialVersionUID = 1234L; private boolean inRange(final int item) { return (item >= startgap && item <= endgap); } @Override public boolean getItemShapeVisible(int series, int item) { return false; } @Override public boolean getItemLineVisible(int series, int item) { return inRange(item); } }); for (int i = 0; i < dataSet.numAttributes() - 1; i++) { //final Color cc=ColorHelper.COLORBREWER_ALL_QUALITATIVE[i]; final Color cc = ColorHelper.getColorForAString(dataSet.attribute(i).name()); tsChart.getXYPlot().getRenderer().setSeriesPaint(i, cc); ((AbstractRenderer) tsChart.getXYPlot().getRenderer()).setSeriesFillPaint(i, cc.brighter()); } fillWithSingleAxisInterval(dataSet, dateIdx, tsDataset, deviation, deviatedAttrIdx); final ChartPanel cp = new ChartPanel(tsChart, true); if (dataSet.numAttributes() <= 2) cp.setBorder(new TitledBorder(dataSet.attribute(0).name())); return cp; }
From source file:com.joey.software.plottingToolkit.PlotingToolkit.java
public static JPanel getChartPanel(double[] xData, double[] yData, String title, String xlabel, String ylabel, double xmin, double xmax, double ymin, double ymax) { JFreeChart chart = getPlot(xData, yData, title, xlabel, ylabel); ChartPanel panel = new ChartPanel(chart); NumberAxis yAxis = (NumberAxis) chart.getXYPlot().getRangeAxis(); NumberAxis xAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); // xAxis.setLowerBound(xmin); // xAxis.setUpperBound(xmax); xAxis.setRange(xmin, xmax);//from w w w .ja v a 2 s. c o m yAxis.setRange(ymin, ymax); return panel; }
From source file:com.orange.atk.results.logger.documentGenerator.GraphGenerator.java
/** * This function creates the measurement graph by using the JFreeChart * library. The X axis of the graph is in minutes. * /* w w w .j a va2 s . com*/ * @param plotList * plotlist to save. Xvalues must be stored in milliseconds. * @param associatedName * Name of the list * @param folderWhereResultsAreSaved * folder where results are saved * @param yLabel * Name of the y label * @param pictureFile * name of the file * @param yDivisor * use to divide measurements stored in the plotlist by yDivisor */ public static void generateGraphWithJFreeChart(PlotList plotList, String associatedName, String folderWhereResultsAreSaved, String yLabel, String pictureFile, float yDivisor) { // Create a new XYSeries // XYSeries are used to represent couples of (x,y) values. XYSeries data = new XYSeries(associatedName); int size = plotList.getSize(); if (size == 0) { // no element in graphics, exit //Logger.getLogger(this.getClass() ).warn("Nothing in graph"); return; } // Find the initial value of the time // Due to the fact that getX(i) <= getX(i+1), // min({0<=i<size / getX(i)}) = getX(0) long initialValue = plotList.getX(0); XYSeriesCollection series = new XYSeriesCollection(data); if (!plotList.getunit().equals("")) yLabel += " (" + plotList.getunit() + ")"; // Create a new XY graph. //JFreeChart chart = ChartFactory.createXYLineChart("", "Time", yLabel, series, PlotOrientation.VERTICAL, true, true, false); JFreeChart chart = ChartFactory.createTimeSeriesChart("", "Time (min:sec)", yLabel, series, true, true, false); // Set the graph format XYPlot plot = chart.getXYPlot(); plot.setOrientation(PlotOrientation.VERTICAL); DateAxis axis = (DateAxis) plot.getDomainAxis(); //axis.setTickUnit(new DateTickUnit(DateTickUnit.SECOND, 10)); RelativeDateFormat rdf = new RelativeDateFormat(initialValue); rdf.setSecondFormatter(new DecimalFormat("00")); axis.setDateFormatOverride(rdf); // Fill the JFreeChart object which will be used to create the Graph for (int i = 0; i < size; i++) { // xvalue must be in double xval = ((Long) plotList.getX(i)).doubleValue(); float yval = plotList.getY(i).floatValue() / yDivisor; // Logger.getLogger(this.getClass() ).debug(associatedName + " [" + (((Long) // plotList.getX(i)).floatValue() - initialValue) // / XDIVISOR +"] "+ yval); data.add(xval, yval); } ValueAxis rangeAxis = plot.getRangeAxis(); Long min = plotList.getMin(); Long max = plotList.getMax(); double diff = (max - min) * 0.02; if (diff == 0) diff = max * 0.0001; rangeAxis.setLowerBound((min - diff) / yDivisor); rangeAxis.setUpperBound((max + diff) / yDivisor); // Logger.getLogger(this.getClass() ).debug("(" + (min / yDivisor) * 0.98 + " - " // + (min / yDivisor) * 0.98 + ")"); // Logger.getLogger(this.getClass() ).debug("Bound = " + rangeAxis.getLowerBound() + " - " // + rangeAxis.getUpperBound()); // Logger.getLogger(this.getClass() ).debug("Margin = " + rangeAxis.getLowerMargin() + " - " // + rangeAxis.getUpperMargin()); // Logger.getLogger(this.getClass() ).debug("NB AXIS = " + plot.getRangeAxisCount()); // save the chart in a picture file. BufferedImage bufImage = chart.createBufferedImage(640, 480); File fichier = new File(pictureFile); try { if (!ImageIO.write(bufImage, "png", fichier)) { return; } } catch (IOException e) { e.printStackTrace(); } }