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);