Blank vertical lines in StackedArea

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
fbossolani
Posts: 1
Joined: Tue Sep 26, 2017 9:07 pm
antibot: No, of course not.

Blank vertical lines in StackedArea

Post by fbossolani » Tue Sep 26, 2017 9:15 pm

I found a few posts with solutions here:
viewtopic.php?f=3&t=16218&p=46400&hilit ... nes#p46400
viewtopic.php?f=3&t=115913&p=175199&hil ... ap#p175199

I tried those solutions and I the problem still there. Basically I tried to set setRoundXCoordinates to true and extends StackedXYAreaRenderer2.

My problem:
Image

My code:

Code: Select all

public class grafico_overlaid_scriptlet_stackedarea extends JRDefaultScriptlet
{  


	 
    public grafico_overlaid_scriptlet_stackedarea()
    {
        
    }

    private static Connection connection = null;
    private static String query;
    TimeTableXYDataset dataset = new TimeTableXYDataset();
    
    public static void setConnection(Connection conn)
    {
        connection = conn;
    }

    
    public static void setQuery(String valor)
    {
        query = valor;
    }
    

    public void preencherColecao()
    {
    	dataset = new TimeTableXYDataset();
    	
    	try
        {
            Statement stm = connection.createStatement();
            ResultSet rsLinha = stm.executeQuery(query);
            
            while (rsLinha.next()){
            	dataset.add(new Day(rsLinha.getDate("data")), rsLinha.getDouble("valor"), rsLinha.getString("categoria"));
            }    
            rsLinha.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    	/*
        dataset.add(new Day(14, 2, 2007), 87, "Series 1");
        dataset.add(new Day(15, 2, 2008), 67, "Series 1");
        dataset.add(new Day(16, 2, 2009), 78, "Series 1");
        dataset.add(new Day(17, 2, 2010), 55, "Series 1");
        dataset.add(new Day(18, 2, 2011), 58, "Series 1");
        dataset.add(new Day(19, 2, 2012), 60, "Series 1");

        dataset.add(new Day(14, 2, 2007), 45, "Series 2");
        dataset.add(new Day(15, 2, 2008), 67, "Series 2");
        dataset.add(new Day(16, 2, 2009), 61, "Series 2");
        dataset.add(new Day(17, 2, 2010), 58, "Series 2");
        dataset.add(new Day(18, 2, 2011), 73, "Series 2");
        dataset.add(new Day(19, 2, 2012), 64, "Series 2");*/
    }

    

    public void afterReportInit()
        throws JRScriptletException
    {
      
    	preencherColecao();
    	//Criando o ring
    	createChart();    	
    }
    
    private void createChart(){
    	try {
    		JFreeChart chart = ChartFactory.createStackedXYAreaChart(
    	            null,  // chart title
    	            null,                       // domain axis label
    	            null,                       // range axis label
    	            dataset,                         // data
    	            PlotOrientation.VERTICAL,        // the plot orientation
    	            true,                            // legend
    	            true,                            // tooltips
    	            false                            // urls
    	        );
    			chart.removeLegend();
    			
    			chart.setBackgroundPaint(new Color(255,255,255));
    			
    			XYPlot plot = (XYPlot) chart.getPlot();
    	        DateAxis dateAxis = new DateAxis("");
    	        plot.setDomainAxis(dateAxis);
    	        dateAxis.setLowerMargin(0.0);
    	        dateAxis.setUpperMargin(0.0);
    	        
    	        StackedXYAreaRenderer2 stackedxyarearenderer = (StackedXYAreaRenderer2) plot.getRenderer();   
    	        stackedxyarearenderer.setRoundXCoordinates(true);
    	        stackedxyarearenderer.setAutoPopulateSeriesShape(false);
    	        stackedxyarearenderer.setSeriesPaint(0, new Color(179,200,193));
    	        stackedxyarearenderer.setSeriesPaint(1, new Color(0,71,49));
    	        stackedxyarearenderer.setBaseLegendShape(new Rectangle(4, 3, 2, 1));
    	        plot.setRenderer(0, stackedxyarearenderer);

    	        LegendTitle lt = new LegendTitle(plot);
    	        Font font = new Font("Zurich LtCn BT", 0, 8);        
    	        Color cor = new Color(0,0,0);
		        //Legendas
		        try
		        {
		        	lt.setItemFont(font);
		            lt.setItemPaint(cor);
		        }
		        catch(Exception e)
		        {
		            e.printStackTrace();
		        }
		        lt.setVerticalAlignment(VerticalAlignment.CENTER);
		        lt.setPosition(RectangleEdge.BOTTOM);
		        lt.setBorder(1, 1, 1, 1);
		        lt.setPadding(2, 2, 2, 2);

		        chart.addSubtitle(lt);
    	        
		        dateAxis.setTickLabelFont(font);    	        
		        dateAxis.setTickLabelPaint(cor);
		        
		        plot.getRangeAxis().setTickLabelFont(font);
		        plot.getRangeAxis().setTickLabelPaint(cor);
		        plot.getRangeAxis().setRange(plot.getRangeAxis().getRange().getLowerBound()*1.10, plot.getRangeAxis().getRange().getUpperBound()*1.10);
    	        
		        
    	        //ChartUtilities.applyCurrentTheme(chart);
    	        
    	        BufferedImage img = new BufferedImage(260, 180, BufferedImage.TYPE_INT_ARGB);
    	    	Graphics2D g = img.createGraphics();
    	    	chart.draw(g, new Rectangle2D.Double(0, 0, 260, 180));
    	    	g.dispose();
    		
    	
    	    	setVariableValue("Chart", new JCommonDrawableRenderer(chart));
		} catch (JRScriptletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}    	
    }
    
    public Color convertToColor(String valor)
    {
        String rgb[] = valor.split(",");
        int r = Integer.parseInt(rgb[0]);
        int g = Integer.parseInt(rgb[1]);
        int b = Integer.parseInt(rgb[2]);
        Color c = new Color(r, g, b);
        return c;
    }
    
    public class Atributo{
    	
    	public Atributo(String t, Color c){
    		texto = t;
    		rgb = c;
    	}
    	public String texto = "";
    	public Color rgb	= null;    	
    }

    
}
I'm trying others ways to fix but I get stucked. Any helps or light will be glad :)

Locked