List of usage examples for org.jfree.data.xy XYSeries setKey
public void setKey(Comparable key)
VetoableChangeEvent
(with the property name "Key") to all registered listeners. From source file:e3fraud.gui.GraphingTool.java
public static JFreeChart generateGraph(E3Model model, Resource need, int startValue, int endValue, boolean expected) { //Get list of actors Set<Resource> actors = model.getActors(); //generate a series Map<Resource, XYSeries> actorSeriesMap = model.getTotalForActors(need, startValue, endValue, expected); //for each actor XYSeriesCollection line_chart_dataset = new XYSeriesCollection(); for (Resource actor : actors) { //add it's series to the chart XYSeries series = actorSeriesMap.get(actor); line_chart_dataset.addSeries(series); double slope; if (series.getItemCount() > 1) { slope = (series.getY(0).doubleValue() - series.getY(1).doubleValue()) / (series.getX(0).doubleValue() - series.getX(1).doubleValue()); } else {//from w w w .j a va 2 s.co m slope = 0; } DecimalFormat df = new DecimalFormat("#.##"); series.setKey(series.getKey() + "\nAvg.\t = \t" + df.format(model.getLastKnownAverages().get(actor)) + "\nSlope\t = \t" + df.format(slope)); } /* Step -2:Define the JFreeChart object to create line chart */ JFreeChart lineChartObject; if (expected) { lineChartObject = ChartFactory.createScatterPlot( "(Ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); } else { lineChartObject = ChartFactory.createScatterPlot( "(Non-ideal) Profit Vs Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Occurences of \"" + need.getProperty(E3value.e3_has_name).getString() + " \"", "Profit (in Euro)", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); } return lineChartObject; }
From source file:gda.util.SavePNGPlot.java
/** * //from ww w .j av a 2 s . c o m * @param imageFile * @param scan * @param width * @param height * @param chartTitle * @throws IOException */ public static void save(String imageFile, ScanFileHolder scan, int width, int height, String chartTitle) throws IOException { final XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series; IDataset x_axis = scan.getAxis(0); String[] headings = scan.getHeadings(); String yAxisName; if (headings.length == 2) yAxisName = headings[1]; else yAxisName = "various"; for (int seriesNum = 1; seriesNum < headings.length; seriesNum++) { series = new XYSeries(""); for (int point = 0, max = x_axis.getSize(); point < max - 1; point++) series.add(x_axis.getDouble(point), scan.getAxis(seriesNum).getDouble(point)); series.setKey(headings[seriesNum]); dataset.addSeries(series); } final JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart // title headings[0], // x axis label yAxisName, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend false, // tool tips false // url's ); ChartUtilities.saveChartAsPNG(new File(imageFile), chart, width, height); }
From source file:celeste.Celeste.java
public void pintarTrayectoriaPlaneta(int n_plat) { XYSeriesCollection coleccion = new XYSeriesCollection(); String name = planetas.get(n_plat)[0]; double a = Double.parseDouble(planetas.get(n_plat)[1]); double epsilon = Double.parseDouble(planetas.get(n_plat)[2]); double p = Double.parseDouble(planetas.get(n_plat)[3]); Planeta planeta = new Planeta(a, epsilon, p); XYSeries serie = planeta.generarPosiciones(); serie.setKey(name); coleccion.addSeries(serie);//from ww w. j a v a 2s .com generarGrafica(coleccion, false); }
From source file:celeste.Celeste.java
public void pintarTodosTrayectorias() { XYSeriesCollection coleccion = new XYSeriesCollection(); for (int i = 0; i < planetas.size(); i++) { String name = planetas.get(i)[0]; double a = Double.parseDouble(planetas.get(i)[1]); double epsilon = Double.parseDouble(planetas.get(i)[2]); double p = Double.parseDouble(planetas.get(i)[3]); Planeta planeta = new Planeta(a, epsilon, p); XYSeries serie = planeta.generarPosiciones(); serie.setKey(name); coleccion.addSeries(serie);//from w ww .ja va2 s . c o m } generarGrafica(coleccion, false); }
From source file:celeste.Celeste.java
public void todasPosiciones(double t) { XYSeriesCollection coleccion = new XYSeriesCollection(); for (int i = 0; i < planetas.size(); i++) { String name = planetas.get(i)[0]; double a = Double.parseDouble(planetas.get(i)[1]); double epsilon = Double.parseDouble(planetas.get(i)[2]); double p = Double.parseDouble(planetas.get(i)[3]); Planeta planeta = new Planeta(a, epsilon, p); XYSeries serie2 = planeta.generarPosiciones(); serie2.setKey(name); Vector pos = planeta.posicion(t); XYSeries serie = new XYSeries(name + " en t"); serie.add(pos.getX1(), pos.getX2()); coleccion.addSeries(serie2);//from w ww . ja v a 2s. co m coleccion.addSeries(serie); } generarGrafica(coleccion, true); }
From source file:celeste.Celeste.java
public void pintarPlaneta(int n_plat, double t) { XYSeriesCollection coleccion = new XYSeriesCollection(); String name = planetas.get(n_plat)[0]; double a = Double.parseDouble(planetas.get(n_plat)[1]); double epsilon = Double.parseDouble(planetas.get(n_plat)[2]); double p = Double.parseDouble(planetas.get(n_plat)[3]); Planeta planeta = new Planeta(a, epsilon, p); XYSeries serie = planeta.generarPosiciones(); XYSeries serie2 = new XYSeries("posicion", false); serie.setKey(name); serie2.add(planeta.posicion(t).getX1(), planeta.posicion(t).getX2()); coleccion.addSeries(serie);//from w ww .jav a 2 s . c o m coleccion.addSeries(serie2); generarGrafica(coleccion, true); }
From source file:edu.gmu.cs.sim.util.media.chart.TimeSeriesChartGenerator.java
/** Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i> event if/when the series is deleted from the chart by the user. The series should have a key in the form of a String. Returns the series attributes. */ public SeriesAttributes addSeries(final XYSeries series, final SeriesChangeListener stopper) { XYSeriesCollection xysc = (XYSeriesCollection) getSeriesDataset(); int i = xysc.getSeriesCount(); series.setKey(new ChartGenerator.UniqueString(series.getKey())); xysc.addSeries(series);/*from w ww . j a va2 s.c om*/ TimeSeriesAttributes csa = new TimeSeriesAttributes(this, series, i, stopper); seriesAttributes.add(csa); revalidate(); return csa; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.DoseResponseController.java
/** * Create a dose-response chart containing experimental data, simulated data * and an annotated R value.//from w w w . j a v a2 s.c om * * @param dataToPlot The experimental data on which the fit was performed * @param analysisGroup The analysis group * @param normalized Whether the responses are normalized * @return */ public JFreeChart createDoseResponseChart(List<DoseResponsePair> dataToPlot, DoseResponseAnalysisGroup analysisGroup, boolean normalized) { // setup scatter data of experimental concentrations/slopes, renderer and axis XYSeriesCollection experimentalData = new XYSeriesCollection(); XYSeries scatterXYSeries = JFreeChartUtils.generateXYSeries(AnalysisUtils.generateXValues(dataToPlot), AnalysisUtils.generateYValues(dataToPlot)); scatterXYSeries.setKey("Experimental data"); experimentalData.addSeries(scatterXYSeries); // compute how far the simulated data and axes should range: from the lowest and highest dose continue half of the range between these two List<Double> extremes = new ArrayList<>(); Double range = Math.abs(scatterXYSeries.getMaxX() - scatterXYSeries.getMinX()); extremes.add(scatterXYSeries.getMinX() - (range / 2)); extremes.add(scatterXYSeries.getMaxX() + (range / 2)); // Create the simulated line data, renderer, and axis XYSeriesCollection fitting = new XYSeriesCollection(); // create xy series of simulated data from the parameters from the fitting SigmoidFittingResultsHolder resultsHolder = analysisGroup.getDoseResponseAnalysisResults() .getFittingResults(normalized); XYSeries fittingData = simulateData(resultsHolder, extremes); fittingData.setKey("Fitting"); fitting.addSeries(fittingData); XYPlot plot = JFreeChartUtils.setupDoseResponseDatasets(experimentalData, fitting, getPlotAxesNames(normalized), extremes); // show the r squared value, put the value at a certain place between the min and max dose double xPlace = extremes.get(1) - range; double yPlace = scatterXYSeries.getMinY() + ((scatterXYSeries.getMaxY() - scatterXYSeries.getMinY()) / 4); plot.addAnnotation(new XYTextAnnotation( "R2=" + AnalysisUtils.roundThreeDecimals(AnalysisUtils.computeRSquared(dataToPlot, resultsHolder)), xPlace, yPlace)); // Create the chart with the plot and no legend JFreeChart chart = new JFreeChart("Title", JFreeChart.DEFAULT_TITLE_FONT, plot, false); String title = ""; if (normalized) { title = "Normalized fitting"; } else { title = "Initial fitting"; } JFreeChartUtils.setupDoseResponseChart(chart, title); return chart; }
From source file:com.bwc.ora.models.Lrp.java
public XYSeries getLrpDataSeries() { XYSeries lrp = new XYSeries(getName() + " LRP"); lrp.setKey(getName()); int[] intensityValues = smoothIntensityValues(getIntensityValues()); for (int i = 0; i < intensityValues.length; i++) { lrp.add(i + y, intensityValues[i]); }/*from w w w . j av a2 s. c om*/ return lrp; }
From source file:oct.analysis.application.OCTSelection.java
public final XYSeries getLrpSeriesFromOCT(BufferedImage oct) { XYSeries lrp = new XYSeries(selectionName + " LRP"); lrp.setKey(selectionName); int leftEdge = getSelectionLeftEdgeCoordinate(); double value = -1; //iterate over each row of pixels in the selection area and calculate average pixel intensity for (int y = yPositionOnOct + height - 1; y >= yPositionOnOct; y--) { int yVal = y; //calculate average pixel grayscale intensity double curPixelIntensity = Arrays.stream(oct.getRGB(leftEdge, yVal, width, 1, null, 0, width)) .map(Util::calculateGrayScaleValue).average().getAsDouble(); //smooth the LRP to provide a higher quality LRP signal if (value <= -1) { //initialize the first value for the smoothing filter value = curPixelIntensity;/*from w w w.j a v a 2 s.com*/ } else { //smooth the LRP signal value += ((curPixelIntensity - value) / selMngr.getLrpSmoothingFactor()); } //add LRP value to return series lrp.add(oct.getHeight() - y, value); } return lrp; }