List of usage examples for org.jfree.data.xy XYSeriesCollection addSeries
public void addSeries(XYSeries series)
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of a Comparative Response Model * Histogram.//from w w w. j a v a2 s .c om * * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param dataBefore * The array of values before the response. * @param dataAfter * The array of values after the response. * @return a chart panel with the graphical representation. */ public static ChartPanel createResponseHistogram(String title, String x, String y, double[] dataBefore, double[] dataAfter) { XYSeries series1 = new XYSeries("Basic Pricing Scheme"); for (int i = 0; i < dataBefore.length; i++) { series1.add(i, dataBefore[i]); } XYSeries series2 = new XYSeries("New Pricing Scheme"); for (int i = 0; i < dataAfter.length; i++) { series2.add(i, dataAfter[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls); XYPlot xyplot = (XYPlot) chart.getPlot(); xyplot.setDomainPannable(true); xyplot.setRangePannable(true); xyplot.setForegroundAlpha(0.85F); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); // domainAxis.setRange(0.0, 1440.0); domainAxis.setTickUnit(new NumberTickUnit(10)); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setTickUnit(new NumberTickUnit(0.1)); return new ChartPanel(chart); }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of two Area Diagrams. * // w w w . j a v a 2 s . c o m * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param doubles * The array of values of the first array. * * @return a chart panel with the graphical representation. */ public static ChartPanel createExpectedPowerChart(String title, String x, String y, double[] data) { JFreeChart chart = null; XYSeries series1 = new XYSeries("Expected Power"); for (int i = 0; i < data.length; i++) { series1.add(i, data[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, 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); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setVerticalTickLabels(true); domainAxis.setRange(0.0, 1440.0); domainAxis.setTickUnit(new NumberTickUnit(100)); return new ChartPanel(chart); }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for the visualization of a Gaussian Mixture * Distribution./*w ww . ja v a 2 s. c o m*/ * * @param title * The title of the chart. * @param x * The unit on the X axis of the chart. * @param y * The unit on the Y axis of the chart. * @param data * The array of values. * @return a chart panel with the graphical representation. */ public static ChartPanel createMixtureDistribution(String title, String x, String y, double[] data) { XYSeries series1 = new XYSeries("First"); for (int i = 0; i < data.length; i++) { series1.add(i, data[i]); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, dataset, orientation, show, toolTips, urls); XYPlot xyplot = (XYPlot) chart.getPlot(); xyplot.setDomainPannable(true); xyplot.setRangePannable(true); xyplot.setForegroundAlpha(0.85F); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); if (data.length != 1440) domainAxis.setTickUnit(new NumberTickUnit(data.length / 10)); else domainAxis.setTickUnit(new NumberTickUnit(100)); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return new ChartPanel(chart); }
From source file:eu.cassandra.training.utils.ChartUtils.java
/** * This function is used for parsing and presenting the basic and the new * pricing schema.//w w w . ja va 2 s . c om * * @param basic * The basic pricing schema * @param after * The new pricing schema * * @return a chart panel with the * graphical representation. */ public static ChartPanel parsePricingScheme(String basic, String after) { double[] data = Utils.parseScheme(basic); double[] data2 = Utils.parseScheme(after); XYSeries series1 = new XYSeries("Basic Pricing Scheme"); for (int i = 0; i < data.length; i++) { series1.add(i, data[i]); } XYSeries series2 = new XYSeries("New Pricing Scheme"); for (int i = 0; i < data2.length; i++) { series2.add(i, data2[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = false; boolean urls = false; JFreeChart chart = ChartFactory.createXYLineChart("Pricing Schemes", "Minute of Day", "Euros/kWh", dataset, orientation, show, toolTips, urls); XYPlot xyplot = (XYPlot) chart.getPlot(); xyplot.setDomainPannable(true); xyplot.setRangePannable(true); xyplot.setForegroundAlpha(0.85F); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); domainAxis.setTickUnit(new NumberTickUnit(100)); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return new ChartPanel(chart); }
From source file:stratego.neural.net.SimulatedAnnealing.java
private static void plotDataSet(List<NamedDataSet> ArraySetList, String name, String xAxis, String yAxis, boolean legend) throws IOException { String plot_title = name;/*from ww w.j av a2 s . c om*/ XYSeriesCollection plotData = new XYSeriesCollection(); for (NamedDataSet ns : ArraySetList) { XYSeries series = new XYSeries(ns.getName()); double[] data = ns.getArray(); for (int i = 0; i < data.length; i++) { series.add((double) i, data[i]); } plotData.addSeries(series); } String title = plot_title; String xAxisLabel = xAxis; String yAxisLabel = yAxis; PlotOrientation orientation = PlotOrientation.VERTICAL; //boolean legend = true; // might wanna set this to true at some point, but research the library boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, plotData, orientation, legend, tooltips, urls); JPanel panel = new ChartPanel(chart); JFrame f = new JFrame(); f.add(panel); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.pack(); f.setTitle(plot_title); f.setVisible(true); // ChartUtilities.saveChartAsJPEG(new File("src/Graphs/test_graph_1.JPEG"),chart,1280,1024); }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Build new scatter plot from numbers array using a default title and xLabel. * String dataName will be used for yLabel. * Appearance can be changed later with the other methods of ChartsUtils. * @param numbers Numbers for the scatter plot * @param dataName Name of the numbers data * @param useLines Indicates if lines have to be drawn instead of shapes * @param useLinearRegression Indicates if the scatter plot has to have linear regreesion line drawn * @return Scatter plot for the data and appearance options *///from www .j av a2 s .c o m public static JFreeChart buildScatterPlot(final Number[] numbers, final String dataName, final boolean useLines, final boolean useLinearRegression) { if (numbers == null || numbers.length == 0) { return null; } XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataName); for (int i = 0; i < numbers.length; i++) { series.add(i, numbers[i]); } dataset.addSeries(series); JFreeChart scatterPlot = buildScatterPlot(dataset, getMessage("ChartsUtils.report.scatter-plot.title"), getMessage("ChartsUtils.report.scatter-plot.xLabel"), dataName, useLines, useLinearRegression); return scatterPlot; }
From source file:osh.comdriver.simulation.cruisecontrol.ScheduleDrawer.java
/** * Creates a chart.//from w ww .j a va 2s . c o m * * @param dataset1 a dataset. * @return A chart. */ private static JFreeChart createChart(XYDataset dataset1, //power XYDataset dataset2, //costs XYDataset dataset3, long time) { JFreeChart chart = ChartFactory.createTimeSeriesChart("schedule", // title "time", // x-axis label "power", // y-axis label dataset1, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis1 = new NumberAxis("power"); NumberAxis axis2 = new NumberAxis("costs"); axis1.setAutoRangeIncludesZero(true); axis1.setUpperBound(5000); axis1.setLowerBound(-5000); axis2.setAutoRangeIncludesZero(true); axis2.setUpperBound(50); axis2.setLowerBound(0); plot.setRangeAxis(0, axis1); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.mapDatasetToRangeAxis(1, 1); plot.setDataset(2, dataset3); plot.mapDatasetToRangeAxis(2, 0); 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); //TODO: SHADOWS OFF final StandardXYItemRenderer r1 = new StandardXYItemRenderer(); final StandardXYItemRenderer r2 = new StandardXYItemRenderer(); final StandardXYItemRenderer r3 = new StandardXYItemRenderer(); final StandardXYItemRenderer r4 = new StandardXYItemRenderer(); plot.setRenderer(0, r1); plot.setRenderer(1, r2); plot.setRenderer(2, r3); plot.setRenderer(3, r4); int numberOfSeries = 0; numberOfSeries += dataset1.getSeriesCount(); numberOfSeries += dataset2.getSeriesCount(); numberOfSeries += dataset3.getSeriesCount(); Color[] color = new Color[numberOfSeries]; for (int i = 0; i < numberOfSeries / 2; i++) { color[i] = Color.getHSBColor(i * 1.0f / (numberOfSeries / 2), 1.0f, 1.0f); } int i = 0; for (int j = 0; j < dataset1.getSeriesCount() / 2; j++) { float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null); plot.getRendererForDataset(dataset1).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f)); plot.getRendererForDataset(dataset1).setSeriesPaint(2 * j + 1, Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f)); i++; } for (int j = 0; j < dataset2.getSeriesCount() / 2; j++) { float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null); plot.getRendererForDataset(dataset2).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f)); plot.getRendererForDataset(dataset2).setSeriesPaint(2 * j + 1, Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f)); i++; } for (int j = 0; j < dataset3.getSeriesCount() / 2; j++) { float[] rgbcolor = Color.RGBtoHSB(color[i].getRed(), color[i].getGreen(), color[i].getBlue(), null); plot.getRendererForDataset(dataset3).setSeriesPaint(2 * j, Color.getHSBColor(rgbcolor[0], 1.0f, 1.0f)); plot.getRendererForDataset(dataset3).setSeriesPaint(2 * j + 1, Color.getHSBColor(rgbcolor[0], 1.0f, 0.6f)); i++; } // NOW line double upperBound = plot.getRangeAxis(1).getUpperBound(); double lowerBound = plot.getRangeAxis(1).getLowerBound(); XYSeries nowLine = new XYSeries("now"); nowLine.add(time * 1000, lowerBound); nowLine.add(time * 1000, upperBound); XYSeriesCollection nowColl = new XYSeriesCollection(); //power axis nowColl.addSeries(nowLine); XYDataset nowSet = nowColl; plot.setDataset(3, nowSet); plot.mapDatasetToRangeAxis(3, 1); plot.getRendererForDataset(nowSet).setSeriesPaint(0, Color.DARK_GRAY); plot.getRendererForDataset(nowSet).setSeriesStroke(0, (Stroke) new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); plot.setDomainAxis(new DateAxis()); plot.getDomainAxis().setAutoRange(false); long begin = (time / 86400) * 86400 * 1000; //beginning of day long end = begin + 86400 * 2 * 1000; plot.getDomainAxis().setRange(begin, end); return chart; }
From source file:flusim.XY_Plotter.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset./*w w w .ja v a 2s . c om*/ */ private static XYDataset createDataset(java.util.List[] data, String[] desc) { //data is an arraylist of arraylists int count = data.length; XYSeriesCollection dataset = new XYSeriesCollection(); for (int i = 0; i < count; i++) { XYSeries xys = new XYSeries(desc[i]); java.util.List Data = data[i]; int elements = Data.size(); for (int j = 0; j < elements; j++) { double[] timepoint = (double[]) Data.get(j); xys.add(timepoint[0], timepoint[1]); } dataset.addSeries(xys); } return dataset; }
From source file:mt.LengthDistribution.java
public static void GetLengthDistributionArray(ArrayList<File> AllMovies, double[] calibration) { ArrayList<Double> maxlist = new ArrayList<Double>(); for (int i = 0; i < AllMovies.size(); ++i) { double maxlength = LengthDistribution.Lengthdistro(AllMovies.get(i)); if (maxlength != Double.NaN && maxlength > 0) maxlist.add(maxlength);//from ww w . j a va2 s .c o m } Collections.sort(maxlist); int min = 0; int max = (int) Math.round(maxlist.get(maxlist.size() - 1)) + 1; XYSeries counterseries = new XYSeries("MT length distribution"); XYSeries Logcounterseries = new XYSeries("MT Log length distribution"); final ArrayList<Point> points = new ArrayList<Point>(); for (int length = 0; length < max; ++length) { HashMap<Integer, Integer> frameseed = new HashMap<Integer, Integer>(); int count = 0; for (int i = 0; i < AllMovies.size(); ++i) { File file = AllMovies.get(i); double currentlength = LengthDistribution.Lengthdistro(file); ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file); if (currentlength > length) { for (int index = 0; index < currentobject.size(); ++index) { ArrayList<Integer> seedlist = new ArrayList<Integer>(); if (currentobject.get(index).length >= length) { seedlist.add(currentobject.get(index).seedID); if (frameseed.get(currentobject.get(index).Framenumber) != null && frameseed.get(currentobject.get(index).Framenumber) != Double.NaN) { int currentcount = frameseed.get(currentobject.get(index).Framenumber); frameseed.put(currentobject.get(index).Framenumber, seedlist.size() + currentcount); } else if (currentobject.get(index) != null) frameseed.put(currentobject.get(index).Framenumber, seedlist.size()); } } } } // Get maxima length, count int maxvalue = Integer.MIN_VALUE; for (int key : frameseed.keySet()) { int Count = frameseed.get(key); if (Count >= maxvalue) maxvalue = Count; } if (maxvalue != Integer.MIN_VALUE) { counterseries.add(length, maxvalue); if (maxvalue > 0) { Logcounterseries.add((length), Math.log(maxvalue)); points.add(new Point(new double[] { length, Math.log(maxvalue) })); } } } final XYSeriesCollection dataset = new XYSeriesCollection(); final XYSeriesCollection nofitdataset = new XYSeriesCollection(); dataset.addSeries(counterseries); nofitdataset.addSeries(counterseries); final XYSeriesCollection Logdataset = new XYSeriesCollection(); Logdataset.addSeries(Logcounterseries); final JFreeChart chart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", dataset); final JFreeChart nofitchart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", nofitdataset); // Fitting line to log of the length distribution interpolation.Polynomial poly = new interpolation.Polynomial(1); try { poly.fitFunction(points); } catch (NotEnoughDataPointsException e) { // TODO Auto-generated catch block e.printStackTrace(); } DisplayPoints.display(nofitchart, new Dimension(800, 500)); dataset.addSeries(Tracking.drawexpFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Exponential fit")); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setMaximumFractionDigits(3); TextTitle legendText = new TextTitle("Mean Length" + " : " + nf.format(-1.0 / poly.getCoefficients(1)) + " " + "Standard Deviation" + " : " + nf.format(poly.SSE)); legendText.setPosition(RectangleEdge.RIGHT); DisplayPoints.display(chart, new Dimension(800, 500)); chart.addSubtitle(legendText); final JFreeChart logchart = ChartFactory.createScatterPlot("MT Log length distribution", "Number of MT", "Length (micrometer)", Logdataset); // DisplayPoints.display(logchart, new Dimension(800, 500)); for (int i = 1; i >= 0; --i) System.out.println(poly.getCoefficients(i) + " " + "x" + " X to the power of " + i); // Logdataset.addSeries(Tracking.drawFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Straight line fit")); WriteLengthdistroFile(AllMovies, counterseries, 0); }
From source file:mt.LengthDistribution.java
public static void GetLengthDistributionArrayatTime(ArrayList<File> AllMovies, double[] calibration, final int framenumber) { ArrayList<Double> maxlist = new ArrayList<Double>(); for (int i = 0; i < AllMovies.size(); ++i) { ArrayList<Pair<Integer, Double>> lengthlist = LengthDistribution.LengthdistroatTime(AllMovies.get(i), framenumber);/*from ww w . j a v a2 s .c o m*/ for (int index = 0; index < lengthlist.size(); ++index) { if (lengthlist.get(index).getB() != Double.NaN && lengthlist.get(index).getB() > 0) maxlist.add(lengthlist.get(index).getB()); } } Collections.sort(maxlist); int min = 0; int max = 0; if (maxlist.size() > 0) max = (int) Math.round(maxlist.get(maxlist.size() - 1)) + 1; XYSeries counterseries = new XYSeries("MT length distribution"); XYSeries Logcounterseries = new XYSeries("MT Log length distribution"); final ArrayList<Point> points = new ArrayList<Point>(); for (int length = 0; length < max; ++length) { HashMap<Integer, Integer> frameseed = new HashMap<Integer, Integer>(); int count = 0; for (int i = 0; i < AllMovies.size(); ++i) { File file = AllMovies.get(i); ArrayList<FLSobject> currentobject = Tracking.loadMTStat(file); if (currentobject != null) for (int index = 0; index < currentobject.size(); ++index) { ArrayList<Integer> seedlist = new ArrayList<Integer>(); if (currentobject.get(index).length >= length && currentobject.get(index).Framenumber == framenumber) { seedlist.add(currentobject.get(index).seedID); if (frameseed.get(currentobject.get(index).Framenumber) != null && frameseed.get(currentobject.get(index).Framenumber) != Double.NaN) { int currentcount = frameseed.get(currentobject.get(index).Framenumber); frameseed.put(currentobject.get(index).Framenumber, seedlist.size() + currentcount); } else if (currentobject.get(index) != null) frameseed.put(currentobject.get(index).Framenumber, seedlist.size()); } } } // Get maxima length, count int maxvalue = Integer.MIN_VALUE; for (int key : frameseed.keySet()) { int Count = frameseed.get(key); if (Count >= maxvalue) maxvalue = Count; } if (maxvalue != Integer.MIN_VALUE) { counterseries.add(length, maxvalue); if (maxvalue > 0) { System.out.println("Max " + maxvalue); Logcounterseries.add((length), Math.log(maxvalue)); points.add(new Point(new double[] { length, Math.log(maxvalue) })); } } } final XYSeriesCollection dataset = new XYSeriesCollection(); final XYSeriesCollection nofitdataset = new XYSeriesCollection(); dataset.addSeries(counterseries); nofitdataset.addSeries(counterseries); final XYSeriesCollection Logdataset = new XYSeriesCollection(); Logdataset.addSeries(Logcounterseries); final JFreeChart chart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", dataset); final JFreeChart nofitchart = ChartFactory.createScatterPlot("MT length distribution", "Number of MT", "Length (micrometer)", nofitdataset); // Fitting line to log of the length distribution interpolation.Polynomial poly = new interpolation.Polynomial(1); try { poly.fitFunction(points); } catch (NotEnoughDataPointsException e) { } DisplayPoints.display(nofitchart, new Dimension(800, 500)); dataset.addSeries(Tracking.drawexpFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Exponential fit")); NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH); nf.setMaximumFractionDigits(3); TextTitle legendText = new TextTitle("Mean Length" + " : " + nf.format(-1.0 / poly.getCoefficients(1)) + " " + "Standard Deviation" + " : " + nf.format(poly.SSE)); legendText.setPosition(RectangleEdge.RIGHT); DisplayPoints.display(chart, new Dimension(800, 500)); chart.addSubtitle(legendText); System.out.println("Series count" + dataset.getSeriesCount()); final JFreeChart logchart = ChartFactory.createScatterPlot("MT Log length distribution", "Length (micrometer)", "Number of MT", Logdataset); // DisplayPoints.display(logchart, new Dimension(800, 500)); for (int i = 1; i >= 0; --i) System.out.println(poly.getCoefficients(i) + " " + "x" + " X to the power of " + i); // Logdataset.addSeries(Tracking.drawFunction(poly, counterseries.getMinX(), counterseries.getMaxX(), 0.5, "Straight line fit")); WriteLengthdistroFile(AllMovies, counterseries, framenumber); }