Plot to be same size exactly like the Chart in my Servlet

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
serhan
Posts: 10
Joined: Tue Jul 05, 2005 9:03 am

Plot to be same size exactly like the Chart in my Servlet

Post by serhan » Tue Jul 05, 2005 9:10 am

Hi folks
I need urgent help...
When I'm darwing a chart in my servlet by this code:

Code: Select all

HttpSession session = req.getSession();
		int[][] arr = (int[][])session.getAttribute("cursors");
		
		OutputStream out = res.getOutputStream();
		
		XYSeries s1 = new XYSeries("Cursors");
		for(int i=0, j=0; i<arr.length; ++i) {
			s1.add(arr[i][j], arr[i][j+1]);
		}
	    
	    XYSeriesCollection dataset = new XYSeriesCollection();
	    dataset.addSeries(s1);
	    
	    JFreeChart chart = ChartFactory.createXYStepChart(null, 
				    									  "X", "Y", 
														  dataset,
														  PlotOrientation.VERTICAL,
														  false, 
														  false, 
														  false);
	    
	    
	        		
	    XYPlot plot = chart.getXYPlot();
		
		ValueAxis axis = plot.getRangeAxis();
		axis.setTickLabelsVisible(false);
		axis.setTickMarksVisible(false);
		axis.setLabel(null);
		axis.setLowerMargin(0.0);
		axis.setUpperMargin(0.0);
		
		ValueAxis axiz = plot.getDomainAxis();
		axiz.setLabel(null);
		axiz.setTickMarksVisible(false);
		axiz.setTickLabelsVisible(false);
		axiz.setLowerMargin(0.0);
		axiz.setUpperMargin(0.0);
		
		res.setContentType("image/png");
		ChartUtilities.writeChartAsPNG(out, chart, 500, 300);
the chart is drawn with margins, this mean the 500, 300 is the size of the plot and the chart is bigger, like this (look at the gray color around):

My question is , how can I make my plot the same size as the chart???

thanks

serhan
Posts: 10
Joined: Tue Jul 05, 2005 9:03 am

solved by...

Post by serhan » Tue Jul 05, 2005 9:56 am

plot.setInsets(new Insets(0, -1, 0, 0));
plot.setOutlinePaint(null);

Thanks anyway

Locked