Multiple datasets with a line chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tktbus
Posts: 2
Joined: Tue Aug 14, 2007 7:58 pm

Multiple datasets with a line chart

Post by tktbus » Thu Dec 06, 2007 9:16 pm

I have created a line chart that has two datasets. One for 2006 and another for 2007 data. Month is on the x-axis and # documents is on the y-axis. 2006 has data for all 12 months. 2007 data does not have any data for December. However 2007 does not line up with the months on the bottom and stretches out to December.

What do I need to do to get the plot value to line up with the month without iterating through the data and adding zero if there isn't any data for that month?

My code is included. I am not sure how to add an image that is not deployed anywhere, but if I get a chance I will create a sample class and post.

Code: Select all

FacesContext context = getFacesContext();
		JFreeChart chart = ChartFactory.createLineChart(
				 "Sirs Written for " + getPreviousYear() + " and " + getCurrentYear(),   // chart title
		            "by Month",                      // domain axis label
		            "# Written",                   // range axis label
		            previousYearDataset,             // data
		            PlotOrientation.VERTICAL,        // orientation
		            true,                            // include legend
		            true,                            // tooltips
		            false                            // urls
		);
//		Here is the legend position... 
	    LegendTitle legend1 = chart.getLegend(0);
	    legend1.setPosition(RectangleEdge.RIGHT);
	    
	    CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setRangeGridlinesVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDataset(1, dataSet);
        // customize the range axis...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        // customize the renderer...
        LineAndShapeRenderer renderer 
                = (LineAndShapeRenderer) plot.getRenderer();
        renderer.setShapesVisible(true);
        renderer.setDrawOutlines(true);
        renderer.setUseFillPaint(true);
        renderer.setBaseFillPaint(Color.white);
        renderer.setSeriesStroke(0, new BasicStroke(3.0f));
        renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
        renderer.setSeriesStroke(1, new BasicStroke(3.0f));
        renderer.setSeriesOutlineStroke(1, new BasicStroke(2.0f));
       
        LineAndShapeRenderer aRenderer = new LineAndShapeRenderer();
        aRenderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator()); 
	    aRenderer.setBaseSeriesVisible(true); 
	    
	    plot.setRenderer(1, aRenderer);
	    
	    renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator()); 
	    renderer.setBaseSeriesVisible(true); 
	    plot.setRenderer(renderer);

Locked