Ciao a tutti,
ho un problema coi colori di un grafico e non essendo molto pratica di java non so più dove sbattere la testa.
In pratica sono riuscita a trovare in rete, e poi modificare un pò, una classe che stampi un grafico in formato pdf. Ciò che mi serve adesso è poter assegnare dall'esterno il colore del plot (se fosse possibile vorrei capire anche come si cambia lo stile: tratteggiato, linea continua...), magari quanbdo richiamo la classe. Si può fare? Grazie mille a chi mi risponderà

Il codice è questo:

codice:
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.DefaultFontMapper;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;

public class PdfPlot {

	XYSeriesCollection dataset = new XYSeriesCollection();
	String ID;
	private double xInf, xSup;

	public PdfPlot(String ID, double xInf, double xSup) {
		this.ID = ID;
		this.xInf = xInf;
		this.xSup = xSup;
	}

	public void addPlot(double[] xPlot, double[] yPlot, String title) {

		XYSeries series = new XYSeries(title);

		for (int k = 0; k < xPlot.length; k++) {
			if (xPlot[k] > xInf && xPlot[k] < xSup) {
				series.add(xPlot[k], yPlot[k]);
			}
		}

		dataset.addSeries(series);
	}

	
	public void makePlot() {

		int width = 900;
		int height = 400;

		Document document = new Document(new Rectangle(width, height));
		try {

			// create the chart...
			final JFreeChart chart = ChartFactory.createXYLineChart(ID, // title
					"Wavelength", // x axis label
					"Flux", // y axis label
					dataset, // data
					PlotOrientation.VERTICAL, // plot oientation
					true, // include legend
					true, // tooltips
					false // urls
					);

			// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
			chart.setBackgroundPaint(Color.white);

			// get a reference to the plot for further customisation...
			final XYPlot plot = chart.getXYPlot();
			plot.setBackgroundPaint(Color.white);
		
			
			plot.setDomainGridlinePaint(Color.white);
			plot.setRangeGridlinePaint(Color.white);

			final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
			// renderer.setSeriesLinesVisible(0, true);
			renderer.setLinesVisible(true);
			renderer.setShapesVisible(false);
			// renderer.setSeriesShapesVisible(0, false);
			// renderer.setSeriesShapesVisible(1, false);
			plot.setRenderer(renderer);

			// change the auto tick unit selection to integer units only...
			final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
			rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
			// OPTIONAL CUSTOMISATION COMPLETED.

			
			// print pdf
			
			PdfWriter writer = PdfWriter.getInstance(document,
					new FileOutputStream("/home/"+ ID+".pdf"));

			document.open();
			PdfContentByte cb = writer.getDirectContent();
			PdfTemplate tp = cb.createTemplate(width, height);
			Graphics2D g2d = tp.createGraphics(width, height,
					new DefaultFontMapper());
			Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
			chart.draw(g2d, r2d);
			g2d.dispose();
			cb.addTemplate(tp, 0, 0);

		} catch (DocumentException de) {
			de.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		document.close();

	}

}