List of usage examples for org.jfree.chart.plot XYPlot setDataset
public void setDataset(XYDataset dataset)
From source file:edu.pdi2.visual.PDI.java
private void onMouseAction(MouseEvent evt, Rectangle crop, boolean chart) { if (chart) {// w w w. j ava2s . com signature = bandsManager .getSignature(new Point(evt.getX() + crop.x + upperLeftX, evt.getY() + crop.y + upperLeftY)); XYSeries signature1 = new XYSeries("Signature"); for (int i = 0; i < signature.length; i++) { signature1.add(i, signature[i]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(signature1); XYPlot plot = (XYPlot) signatureG.getPlot(); plot.setDataset(dataset); } int x = evt.getX() + crop.x + upperLeftX; int y = evt.getY() + crop.y + upperLeftY; edu.pdi2.forms.Point point = new Point(x, y); double lat = et.getXi_(x, y); double lon = et.getYi_(x, y); posDialog.setLat(lat); posDialog.setLon(lon); jLat.setText("Lat: " + ToDegrees(lat / 10000)); jLong.setText("Long: " + ToDegrees(lon / 10000)); for (int i = 0; i < mesh.size(); i++) { Polygon p = (Polygon) mesh.get(i); // Vector gPoints = p.getGPoints(); if (p.isIn(point)) { p.changeColor(); ElasticTransform etP = p.getET(); lat = etP.getYi_(x, y); lon = etP.getXi_(x, y); posDialog.setLat(lat); posDialog.setLon(lon); jLat.setText("Lat: " + ToDegrees(lat)); jLong.setText("Long: " + ToDegrees(lon)); break; } } }
From source file:no.ntnu.mmfplanner.ui.graph.SaNpvChart.java
private void updateModel() { XYSeriesCollection dataset = new XYSeriesCollection(); XYPlot plot = ((XYPlot) getChart().getPlot()); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); // the x=0 line XYSeries line = new XYSeries(""); line.add(1.0, 0.0);/* www. j a v a 2 s .co m*/ line.add(project.getPeriods(), 0.0); dataset.addSeries(line); // adds the line plot for each mmf int[][] saNpvValues = project.getSaNpvTable(); for (int mmfI = 0; mmfI < saNpvValues.length; mmfI++) { Mmf mmf = project.get(mmfI); XYSeries values = new XYSeries(mmf.getId() + ": " + mmf.getName()); for (int period = 1; period <= saNpvValues[mmfI].length; period++) { values.add(period, saNpvValues[mmfI][period - 1]); } dataset.addSeries(values); renderer.setSeriesShapesVisible(mmfI + 1, false); renderer.setSeriesStroke(mmfI + 1, SERIES_STROKE); renderer.setSeriesPaint(mmfI + 1, CHART_COLOR[mmfI % CHART_COLOR.length]); } plot.setDataset(dataset); }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java
public JPanel calcAcAcidOctanol() throws Exception { double T = 293.15; setLayout(new BorderLayout()); COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound c1 = db.getComp("acetic-acid"); COSMOSACCompound c2 = db.getComp("1-octanol"); double[] cavityVolume = new double[2]; cavityVolume[0] = c1.Vcosmo;//from w w w . ja va 2 s. co m cavityVolume[1] = c2.Vcosmo; double[][] sigma = new double[2][]; sigma[0] = c1.sigma; sigma[1] = c2.sigma; SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c1.name.toLowerCase() + ".log"); SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c2.name.toLowerCase() + ".log"); sigma[0] = c1Sigma.getSigmaProfile(); sigma[1] = c2Sigma.getSigmaProfile(); COSMOSAC cosmosac = new COSMOSAC(); cosmosac.setParameters(cavityVolume, c1.charge, sigma); cosmosac.setIgnoreSG(true); cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2); cosmosac.setTemperature(T); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[] Psat = new double[2]; Psat[0] = 1600; Psat[1] = 10; double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot1; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot1 = (XYPlot) chart.getPlot(); plot1.getDomainAxis().setRange(new Range(0.0, 1.0)); plot1.setDataset(dataset); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp1 = new JPanel(new BorderLayout()); jp1.add(chartPanel); add(jp1, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp1; }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java
public JPanel calcMethanolOctanol() throws Exception { double T = 293.15; setLayout(new BorderLayout()); COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound c1 = db.getComp("methanol"); COSMOSACCompound c2 = db.getComp("1-octanol"); double[] cavityVolume = new double[2]; cavityVolume[0] = c1.Vcosmo;//from w w w. ja va 2 s . c o m cavityVolume[1] = c2.Vcosmo; double[][] sigma = new double[2][]; sigma[0] = c1.sigma; sigma[1] = c2.sigma; SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c1.name.toLowerCase() + ".log"); SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c2.name.toLowerCase() + ".log"); sigma[0] = c1Sigma.getSigmaProfile(); sigma[1] = c2Sigma.getSigmaProfile(); COSMOSAC cosmosac = new COSMOSAC(); cosmosac.setParameters(cavityVolume, c1.charge, sigma); cosmosac.setIgnoreSG(true); cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2); cosmosac.setTemperature(T); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[] Psat = new double[2]; Psat[0] = 350; Psat[1] = 470; double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot1; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot1 = (XYPlot) chart.getPlot(); plot1.getDomainAxis().setRange(new Range(0.0, 1.0)); plot1.setDataset(dataset); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp1 = new JPanel(new BorderLayout()); jp1.add(chartPanel); add(jp1, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp1; }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java
public JPanel calcEthanolWater() throws Exception { double T = 343.15; setLayout(new BorderLayout()); COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound c1 = db.getComp("ethanol"); COSMOSACCompound c2 = db.getComp("water"); double[] cavityVolume = new double[2]; cavityVolume[0] = c1.Vcosmo;//from w w w . ja va 2 s .c om cavityVolume[1] = c2.Vcosmo; double[][] sigma = new double[2][]; sigma[0] = c1.sigma; sigma[1] = c2.sigma; SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c1.name.toLowerCase() + ".log"); SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c2.name.toLowerCase() + ".log"); sigma[0] = c1Sigma.getSigmaProfile(); sigma[1] = c2Sigma.getSigmaProfile(); COSMOSAC cosmosac = new COSMOSAC(); cosmosac.setParameters(cavityVolume, c1.charge, sigma); cosmosac.setIgnoreSG(true); cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2); cosmosac.setTemperature(T); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[] Psat = new double[2]; Psat[0] = 72388; Psat[1] = 32760; double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot1; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot1 = (XYPlot) chart.getPlot(); plot1.getDomainAxis().setRange(new Range(0.0, 1.0)); plot1.setDataset(dataset); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp1 = new JPanel(new BorderLayout()); jp1.add(chartPanel); add(jp1, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp1; }
From source file:sim.app.sugarscape.Sugarscape.java
public void start() { super.start(); agents_grid.clear();/*from w w w . ja v a 2 s .c om*/ scape_grid.clear(); //scape_grid = new ObjectGrid2D(gridWidth, gridHeight); sim.app.sugarscape.Agent agent; /* If the season rate is very large, it will be summer for all foreseable simulation runs in the north and winter in the south. Growback rates for each are set as parameters and normally default to 1 */ north_season = SUMMER; south_season = WINTER; Steppable season_changer = new Steppable() { public void step(SimState state) { Sugarscape sugar = (Sugarscape) state; if (sugar.north_season == SUMMER) { sugar.north_season = WINTER; sugar.south_season = SUMMER; } else { sugar.north_season = SUMMER; sugar.south_season = WINTER; } } }; MultiStep season_multi = new MultiStep(season_changer, season_rate, true); schedule.scheduleRepeating(Schedule.EPOCH, 3, season_multi, 1); //change seasons last in order if (agents_file != null) { //config file for setting up agents spatial config try { InputStream is = Class.forName(sim.app.sugarscape.Sugarscape.class.getCanonicalName()) .getClassLoader().getResourceAsStream(agents_file); InputStreamReader ir = new InputStreamReader(is); BufferedReader br = new BufferedReader(ir); String line = br.readLine(); int y = 0; int affiliation; String affil_code; while (line != null) { int x = 0; int size = line.length(); while (x < size) { affil_code = line.substring(x, x + 1); affiliation = Integer.parseInt(affil_code); if (affiliation != 0) { agent = this.newAgent(); agents_grid.field[x][y] = agent; //,new Int2D(x,y)); agent.my_loc.x = x; agent.my_loc.y = y; } x++; } line = br.readLine(); y++; //System.out.println(line); } } catch (Exception e) { e.printStackTrace(); } } else { //otherwise distribute randomly in space for (int a = 0; a < numAgents; a++) { createNewAgent(); } } ArrayList rows = new ArrayList(50); for (int a = 0; a < resources; a++) { rows.clear(); try { InputStream is = Class.forName(sim.app.sugarscape.Sugarscape.class.getCanonicalName()) .getClassLoader().getResourceAsStream(terrain_files[a]); InputStreamReader ir = new InputStreamReader(is); BufferedReader br = new BufferedReader(ir); String line = br.readLine(); while (line != null) { rows.add(line); line = br.readLine(); } } catch (Exception e) { e.printStackTrace(); } int row_count = rows.size(); int capacity; String max; int equator = row_count / 2; int hemisphere = NORTH; Object[][] all_objs = scape_grid.field; //Object[][] all_pollut = pollution_grid.field; for (int y = 0; y < gridHeight; y++) { if (y >= equator) { hemisphere = SOUTH; } StringBuffer sb = new StringBuffer((String) rows.get(y)); int type; for (int x = 0; x < gridWidth; x++) { max = sb.substring(x, x + 1); capacity = Integer.parseInt(max); if (capacity > 4) { //terrain file has values of 0-4, and 0,5-8 type = SPICE; capacity = capacity - 4; } else { type = SUGAR; } if (all_objs[x][y] == null) { Scape site = new Scape(x, y, hemisphere, pollution_diffusion, this); site.setResource(type, capacity, 1, capacity); /* idealy the growback rate, third param, should not be constant */ all_objs[x][y] = site; } else { ((Scape) all_objs[x][y]).setResource(type, capacity, 1, capacity); } } } } this.initializeEnvironment(); //set up charts avg_agent_vision.clear(); lorenz_curve.clear(); gini_coeff.clear(); agents_series.clear(); blue_agents.clear(); red_agents.clear(); trade_series.clear(); if (stats_rate > 0) { Statistics stats = new Statistics(this, schedule, stats_out); MultiStep multi_lorenz = new MultiStep(stats, stats_rate, true); schedule.scheduleRepeating(Schedule.EPOCH, 4, multi_lorenz, 1); stats.step(this); } //calculate and output frequency count for metabolic 'bins' //that is the total metabolism for each each across the population Steppable metabolism_bins_updater = new Steppable() { Histogram h = new Histogram("Metabolism", "Vision", 1 + metabolic_sugar + metabolic_spice, 5); public void step(SimState state) { //agents_grid. Bag all = null; //agents_grid.getAllObjects(); int size = all.size(); int total = 0; Object[] all_obj = all.objs; h.zero(); for (int a = 0; a < size; a++) { Agent ag = (Agent) all_obj[a]; total = ag.metabolic_rate_spice + ag.metabolic_rate_sugar; h.bins[total] = h.bins[total] + 1; h.bins_assoc[total] = h.bins_assoc[total] + ag.vision; } h.render(); System.out.println(size + " = size, " + (state.schedule.time() + 1) + " = steps."); } }; if (print_metabolism_bins) { MultiStep multi_metabolism_bins = new MultiStep(metabolism_bins_updater, metabolism_bins_freq, true); schedule.scheduleRepeating(Schedule.EPOCH, 6, multi_metabolism_bins, 1); multi_metabolism_bins.step(this); } //TO DO: Restore this if (logger != null) { MultiStep multi_logger = null; //new MultiStep(logger, log_frequency, true); //use order 4 along with statistics steppable //System.out.println("Logging "+ logger.grids.size() + " grids."); schedule.scheduleRepeating(Schedule.EPOCH, 4, multi_logger, 1); //Thread t = new Thread(logger); //t.start(); } Steppable chart_updater = new Steppable() { private static final int BINS = 10; private float total; private float wealth_sugar_total; private double[] ages; public void step(SimState state) { Bag all = null; //agents_grid.getAllObjects(); int size = active_agents_count; double[] values = null; if (size != 0) { /* what if there are zero agents? */ values = new double[size]; } else { values = new double[1]; values[0] = 0; } total = 0; wealth_sugar_total = 0; if (age_chart_on) { ages = new double[size]; } Iterator<Agent> i = active_agents.iterator(); int a = 0; while (i.hasNext()) { Agent agent = i.next(); values[a] = agent.wealth_sugar; wealth_sugar_total = wealth_sugar_total + agent.wealth_sugar; if (age_chart_on) { ages[a] = agent.age; } a++; } if (age_chart_on) { age_hist_dataset = new HistogramDataset(); age_hist_dataset.addSeries(Double.toString(state.schedule.time()), ages, 10); XYPlot xy = ((Sugarscape) state).age_histo_chart.getXYPlot(); xy.setDataset(age_hist_dataset); } if (wealth_chart_on) { dataset = new HistogramDataset(); dataset.addSeries(Double.toString(state.schedule.time()), values, 10); XYPlot xy = ((Sugarscape) state).chart4.getXYPlot(); xy.setDataset(dataset); XYItemRenderer r = xy.getRenderer(); XYItemLabelGenerator xylg = new StandardXYItemLabelGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); r.setItemLabelGenerator(xylg); r.setItemLabelsVisible(true); } } }; // Schedule the agent to update the chart if (chart_display) { MultiStep multi_chart = new MultiStep(chart_updater, chart_rate, true); schedule.scheduleRepeating(Schedule.EPOCH, 6, multi_chart, 1); chart_updater.step(this); } }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java
public JPanel calcAcetoneWater() throws Exception { super.setTitle("P vs x1"); double T = 298.15; setLayout(new BorderLayout()); COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound c1 = db.getComp("ethyl-acetate"); COSMOSACCompound c2 = db.getComp("water"); double[] cavityVolume = new double[2]; cavityVolume[0] = c1.Vcosmo;// w w w. j a va 2s .co m cavityVolume[1] = c2.Vcosmo; double[][] sigma = new double[2][]; sigma[0] = c1.sigma; sigma[1] = c2.sigma; SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c1.name.toLowerCase() + ".log"); SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS, c2.name.toLowerCase() + ".log"); sigma[0] = c1Sigma.getSigmaProfile(); sigma[1] = c2Sigma.getSigmaProfile(); COSMOSAC cosmosac = new COSMOSAC(); cosmosac.setParameters(cavityVolume, c1.charge, sigma); cosmosac.setIgnoreSG(true); cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2); cosmosac.setTemperature(T); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[] Psat = new double[2]; Psat[0] = 13000; Psat[1] = 3000; double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot1; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot1 = (XYPlot) chart.getPlot(); plot1.getDomainAxis().setRange(new Range(0.0, 1.0)); plot1.setDataset(dataset); // XYSplineRenderer r = new XYSplineRenderer(); // BasicStroke stroke = new BasicStroke(2f); // r.setStroke(stroke); // plot1.setRenderer(r); // r.setBaseShapesVisible(false); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp1 = new JPanel(new BorderLayout()); jp1.add(chartPanel); add(jp1, BorderLayout.CENTER); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp1; }
From source file:edu.umn.ecology.populus.plot.BasicPlotInfo.java
public ChartTheme getJFreeChartTheme() { class PopChartTheme implements ChartTheme { private BasicPlotInfo bpiRef; public PopChartTheme(BasicPlotInfo bpi) { this.bpiRef = bpi; }// ww w .j ava 2 s . c o m public void apply(JFreeChart chart) { JFCXYAdapter jfca = new JFCXYAdapter(); XYPlot plot = chart.getXYPlot(); plot.setDataset(jfca); if (isLogPlot) { plot.setRangeAxis(new LogarithmicAxis("")); } if (isFrequencies) { ValueAxis va = plot.getRangeAxis(); if (va instanceof NumberAxis) { NumberAxis na = (NumberAxis) va; na.setTickUnit(new NumberTickUnit(0.1)); } else { Logging.log("Range Axis is not NumberAxis, why?", Logging.kWarn); } } if (xMinSet) plot.getDomainAxis().setLowerBound(xAxisMin); if (xMaxSet) plot.getDomainAxis().setUpperBound(xAxisMax); if (yMinSet) plot.getRangeAxis().setLowerBound(yAxisMin); if (yMaxSet) plot.getRangeAxis().setUpperBound(yAxisMax); //TODO - just use this renderer plot.setRenderer(new ChartRendererWithOrientatedShapes(bpiRef)); XYItemRenderer r = plot.getRenderer(); // AbstractXYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; for (int i = 0; i < getNumSeries(); i++) { //Set Line renderer.setSeriesPaint(i, getLineColor(i)); renderer.setSeriesStroke(i, getLineStroke(i)); //Set Symbol renderer.setSeriesFillPaint(i, getSymbolColor(i)); renderer.setSeriesOutlinePaint(i, getSymbolColor(i)); Shape shape = getSymbolShape(i); if (shape != null) { renderer.setSeriesShape(i, shape); renderer.setSeriesShapesFilled(i, isSymbolOpaque(i)); renderer.setUseFillPaint(true); renderer.setUseOutlinePaint(true); renderer.setSeriesShapesVisible(i, true); } } } else if (r instanceof XYBarRenderer) { XYBarRenderer barRenderer = (XYBarRenderer) r; barRenderer.setBarPainter(new StandardXYBarPainter()); } else { Logging.log("Unknown renderer type: " + r.getClass(), Logging.kWarn); } //inner labels, used in AIDS: Therapy plot.clearAnnotations(); Enumeration<InnerLabel> e = innerLabels.elements(); while (e.hasMoreElements()) { InnerLabel lab = (InnerLabel) e.nextElement(); Logging.log("Adding " + lab.caption + " at " + lab.x + ", " + lab.y); XYTextAnnotation annotation = new XYTextAnnotation(lab.caption, lab.x, lab.y); annotation.setTextAnchor(TextAnchor.BOTTOM_CENTER); annotation.setOutlineVisible(true); plot.addAnnotation(annotation); //I actually think the annotation above is ugly. We can use one of these instead in the future, maybe... /*PointerAnnotation may look cool... * That 2.0 is the angle, randomly picked * XYPointerAnnotation annotation = new XYPointerAnnotation(lab.caption, lab.x, lab.y, 2.0); */ /* ValueMarker marker = new ValueMarker(lab.x); marker.setLabel(lab.caption); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); plot.addDomainMarker(marker); */ } //This is set for GD: AMCM if (startGridded) { plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); } } } return new PopChartTheme(this); }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java
@SuppressWarnings("deprecation") public JPanel calcMethanolMethilAcetate() throws Exception { super.setTitle("P vs x1"); double T = 25; COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound comps[] = new COSMOSACCompound[2]; comps[0] = db.getComp("methanol"); comps[1] = db.getComp("methyl-acetate"); COSMOSAC cosmosac = new COSMOSAC(); cosmosac.setComponents(comps);/*from w w w .ja v a2 s .c o m*/ cosmosac.setTemperature(T + 273.15); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[][] parAntoine = new double[3][3]; parAntoine[0][0] = 16.5785; parAntoine[0][1] = 3638.27; parAntoine[0][2] = 239.500; parAntoine[1][0] = 14.2456; parAntoine[1][1] = 2662.78; parAntoine[1][2] = 219.690; double[] Psat = pSat(parAntoine, T); double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot2; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot2 = (XYPlot) chart.getPlot(); plot2.getDomainAxis().setRange(new Range(0.0, 1.0)); plot2.getRangeAxis().setRange(new Range(15.0, 30.0)); plot2.setDataset(dataset); XYSplineRenderer r = new XYSplineRenderer(); BasicStroke stroke = new BasicStroke(2f); r.setStroke(stroke); plot2.setRenderer(r); r.setBaseShapesVisible(false); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp = new JPanel(new BorderLayout()); jp.add(chartPanel, BorderLayout.CENTER); add(jp); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp; }
From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java
@SuppressWarnings("deprecation") public JPanel calcMethanolMethilAcetateMOPAC() throws Exception { super.setTitle("P vs x1"); double T = 25; COSMOSACDataBase db = COSMOSACDataBase.getInstance(); COSMOSACCompound comps[] = new COSMOSACCompound[2]; comps[0] = db.getComp("methanol"); comps[1] = db.getComp("methyl-acetate"); COSMOSAC cosmosac = new COSMOPAC(); cosmosac.setComponents(comps);/*from w w w . j a v a 2s . c om*/ cosmosac.setTemperature(T + 273.15); double[] x1 = new double[n]; double[] x2 = new double[n]; double[] gamma1 = new double[n]; double[] gamma2 = new double[n]; double[] z = new double[2]; double[] lnGamma = new double[2]; z[0] = 0.00; int j = 0; while (z[0] < 1.0001) { z[1] = 1 - z[0]; x1[j] = z[0]; x2[j] = z[1]; cosmosac.setComposition(z); cosmosac.activityCoefficient(lnGamma); gamma1[j] = Math.exp(lnGamma[0]); gamma2[j] = Math.exp(lnGamma[1]); z[0] += 0.05; j++; } double[][] parAntoine = new double[3][3]; parAntoine[0][0] = 16.5785; parAntoine[0][1] = 3638.27; parAntoine[0][2] = 239.500; parAntoine[1][0] = 14.2456; parAntoine[1][1] = 2662.78; parAntoine[1][2] = 219.690; double[] Psat = pSat(parAntoine, T); double[] P = calcPx(x1, x2, gamma1, gamma2, Psat); double[] y1 = calcY(x1, gamma1, Psat, P); XYPlot plot2; XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries liq = new XYSeries("liquid"); XYSeries vap = new XYSeries("vapor"); XYSeries raoult = new XYSeries("Raoult's Law"); for (int i = 0; i < n; i++) { liq.add(x1[i], P[i]); vap.add(y1[i], P[i]); } raoult.add(0, Psat[1]); raoult.add(1, Psat[0]); dataset.addSeries(liq); dataset.addSeries(vap); dataset.addSeries(raoult); JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null, PlotOrientation.VERTICAL, true, true, false); plot2 = (XYPlot) chart.getPlot(); plot2.getDomainAxis().setRange(new Range(0.0, 1.0)); plot2.getRangeAxis().setRange(new Range(15.0, 30.0)); plot2.setDataset(dataset); XYSplineRenderer r = new XYSplineRenderer(); BasicStroke stroke = new BasicStroke(2f); r.setStroke(stroke); plot2.setRenderer(r); r.setBaseShapesVisible(false); ChartPanel chartPanel = new ChartPanel(chart); JPanel jp = new JPanel(new BorderLayout()); jp.add(chartPanel, BorderLayout.CENTER); add(jp); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(400, 500); return jp; }