Example usage for org.jfree.chart.plot CategoryPlot setRangeAxis

List of usage examples for org.jfree.chart.plot CategoryPlot setRangeAxis

Introduction

In this page you can find the example usage for org.jfree.chart.plot CategoryPlot setRangeAxis.

Prototype

public void setRangeAxis(ValueAxis axis) 

Source Link

Document

Sets the range axis for the plot and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:org.fhaes.jsea.JSEABarChart.java

/**
 * Creates a demo chart.//from   w w  w .ja  v  a 2 s  .c  om
 * 
 * @return A chart.
 */
@SuppressWarnings("deprecation")
public static JFreeChart createChart(String title, double[] meanByWindow, int lengthOfWindow,
        int yearsPriorOfEvent, int yearsAfterEvent, double[][] leftEndPointSim, double[][] rightEndPointSim,
        String outputFilePrefix, int alphaLevel, int segmentIndex) {

    JSEABarChart.meanByWindow = meanByWindow;
    JSEABarChart.lengthOfWindow = lengthOfWindow;
    JSEABarChart.yearsPriorOfEvent = yearsPriorOfEvent;
    JSEABarChart.leftEndPointSim = leftEndPointSim;
    JSEABarChart.rightEndPointSim = rightEndPointSim;
    JSEABarChart.alphaLevel = alphaLevel;

    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(0, createDataset());
    plot.setOrientation(PlotOrientation.VERTICAL);

    CustomBarRenderer renderer = new CustomBarRenderer(createPaint(lengthOfWindow, Color.gray));
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(false);
    renderer.setOutlinePaint(Color.yellow);
    renderer.setOutlineStroke(new BasicStroke(1.1f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setRenderer(0, renderer);
    Color allcolors[] = { Color.red, Color.green, Color.blue };

    System.out.println("here is the alphlevel " + alphaLevel);
    // for (int k = 0; k <= 5; k++) {
    // if (k <= 2) {
    // / plot.setDataset(k + 1, createEndDataset(k, true));
    // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k], k));
    // } else {
    // plot.setDataset(k + 1, createEndDataset(k - 3, false));
    // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k - 3], k - 3));
    // }
    // }
    // for (int k = 0; k <1; k++) {
    // if (k <= 2) {
    plot.setDataset(1, createEndDataset(alphaLevel, true));
    plot.setRenderer(1, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel));
    // } else {
    plot.setDataset(4, createEndDataset(alphaLevel, false));
    plot.setRenderer(4, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel));
    // }
    // }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainAxis(new CategoryAxis("LAG"));

    plot.addRangeMarker(new ValueMarker(0));

    plot.setRangeAxis(new NumberAxis(outputFilePrefix));
    plot.setRangeGridlinesVisible(true);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(title);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.OverlaidStackedBarLine.java

public JFreeChart createChart(DatasetMap datasets) {

    // create the first renderer...

    CategoryPlot plot = new CategoryPlot();
    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    NumberAxis rangeAxis = new NumberAxis(getValueLabel());
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis//w ww  .  ja va  2s. c om
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setNumberFormatOverride(nf);
    plot.setRangeAxis(rangeAxis);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    CategoryAxis domainAxis = new CategoryAxis(getCategoryLabel());
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    plot.setDomainAxis(domainAxis);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    DefaultCategoryDataset datasetBar = (DefaultCategoryDataset) datasets.getDatasets().get("stackedbar");

    //I create one bar renderer and one line

    MyStandardCategoryItemLabelGenerator generator = null;
    if (additionalLabels) {
        generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance());
    }

    if (useBars) {
        CategoryItemRenderer barRenderer = new StackedBarRenderer();

        if (maxBarWidth != null) {
            ((BarRenderer) barRenderer).setMaximumBarWidth(maxBarWidth.doubleValue());
        }

        if (additionalLabels) {
            barRenderer.setBaseItemLabelGenerator(generator);
            double orient = (-Math.PI / 2.0);
            if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
                orient = 0.0;
            }
            barRenderer.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            barRenderer.setBaseItemLabelPaint(styleValueLabels.getColor());
            barRenderer.setBaseItemLabelsVisible(true);
            barRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            barRenderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));

        }

        if (colorMap != null) {
            for (Iterator iterator = datasetBar.getRowKeys().iterator(); iterator.hasNext();) {
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;
                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetBar.getRowIndex(labelName);
                } else
                    index = datasetBar.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    barRenderer.setSeriesPaint(index, color);
                }
            }
        }
        // add tooltip if enabled
        if (enableToolTips) {
            MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                    seriesTooltip, categoriesTooltip, seriesCaptions);
            barRenderer.setToolTipGenerator(generatorToolTip);
        }

        //defines url for drill
        boolean document_composition = false;
        if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
            document_composition = true;

        logger.debug("Calling Url Generation");

        MyCategoryUrlGenerator mycatUrl = null;
        if (super.rootUrl != null) {
            logger.debug("Set MycatUrl");
            mycatUrl = new MyCategoryUrlGenerator(super.rootUrl);

            mycatUrl.setDocument_composition(document_composition);
            mycatUrl.setCategoryUrlLabel(super.categoryUrlName);
            mycatUrl.setSerieUrlLabel(super.serieUrlname);
            mycatUrl.setDrillDocTitle(drillDocTitle);
            mycatUrl.setTarget(target);
        }
        if (mycatUrl != null) {
            barRenderer.setItemURLGenerator(mycatUrl);
        }

        plot.setDataset(1, datasetBar);
        plot.setRenderer(1, barRenderer);

    }

    if (useLines) {

        LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
        //lineRenderer.setShapesFilled(false);
        lineRenderer.setShapesFilled(true);
        if (additionalLabels) {
            lineRenderer.setBaseItemLabelGenerator(generator);
            lineRenderer.setBaseItemLabelFont(
                    new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
            lineRenderer.setBaseItemLabelPaint(defaultLabelsStyle.getColor());
            lineRenderer.setBaseItemLabelsVisible(true);
        }

        DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasets.getDatasets().get("line");

        if (enableToolTips) {
            MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                    seriesTooltip, categoriesTooltip, seriesCaptions);
            lineRenderer.setToolTipGenerator(generatorToolTip);
        }

        if (colorMap != null) {
            for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLine.getRowIndex(labelName);
                } else
                    index = datasetLine.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer.setSeriesPaint(index, color);
                }
            }
        }
        plot.setDataset(0, datasetLine);
        plot.setRenderer(0, lineRenderer);
    }

    if (secondAxis) {
        NumberAxis na = new NumberAxis(secondAxisLabel);
        na.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
        na.setLabelPaint(styleXaxesLabels.getColor());
        na.setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
        na.setTickLabelPaint(styleXaxesLabels.getColor());
        na.setUpperMargin(0.10);
        if (rangeIntegerValues == true) {
            na.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        }
        na.setNumberFormatOverride(nf);
        plot.setRangeAxis(1, na);
        plot.mapDatasetToRangeAxis(0, 1);
    }

    //plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    chart.setBackgroundPaint(Color.white);

    if (legend == true)
        drawLegend(chart);
    return chart;

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java

protected void configureLogarithmicAxis(final CategoryPlot plot) {
    if (isLogarithmicAxis()) {
        final LogarithmicAxis logarithmicAxis;
        if (isHumanReadableLogarithmicFormat()) {
            plot.getRenderer().setBaseItemLabelGenerator(new LogCategoryItemLabelGenerator());
            logarithmicAxis = new ScalingLogarithmicAxis(getValueAxisLabel());
            logarithmicAxis.setStrictValuesFlag(false);
        } else {/*from  w  ww .ja  va2s . c o  m*/
            logarithmicAxis = new LogarithmicAxis(getValueAxisLabel());
            logarithmicAxis.setStrictValuesFlag(false);
        }

        plot.setRangeAxis(logarithmicAxis);
    }
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

protected void setChartAxes(JFreeChart chart, UIChart comp) {
    UIAxis xAxis = comp.getxAxis();/*w  ww  .j  av a2 s . c om*/
    UIAxis yAxis = comp.getyAxis();
    String xAxisLabel = comp.getxAxisLabel();
    String yAxisLabel = comp.getyAxisLabel();

    Plot plot = chart.getPlot();
    Axis domainAxis = null;
    Axis rangeAxis = null;

    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        if (yAxis != null && yAxis.isLogarithmic())
            categoryPlot.setRangeAxis(new LogarithmicAxis(null));

        domainAxis = categoryPlot.getDomainAxis();
        rangeAxis = categoryPlot.getRangeAxis();

        if (xAxis != null) {
            Boolean drawGridLine = xAxis.getDrawGridLine();
            if (drawGridLine != null) {
                categoryPlot.setDomainGridlinesVisible(drawGridLine);
            }
            Paint gridLineColor = xAxis.getGridLineColor();
            if (gridLineColor != null) {
                categoryPlot.setDomainGridlinePaint(gridLineColor);
            }
        }

        if (yAxis != null) {
            Boolean drawGridLine = yAxis.getDrawGridLine();
            if (drawGridLine != null) {
                categoryPlot.setRangeGridlinesVisible(drawGridLine);
            }
            Paint gridLineColor = yAxis.getGridLineColor();
            if (gridLineColor != null) {
                categoryPlot.setRangeGridlinePaint(gridLineColor);
            }
        }
    } else if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        if (xAxis != null && xAxis.isLogarithmic())
            xyPlot.setDomainAxis(new LogarithmicAxis(null));
        if (yAxis != null && yAxis.isLogarithmic())
            xyPlot.setRangeAxis(new LogarithmicAxis(null));

        domainAxis = xyPlot.getDomainAxis();
        rangeAxis = xyPlot.getRangeAxis();

        if (xAxis != null) {
            Boolean drawGridLine = xAxis.getDrawGridLine();
            if (drawGridLine != null) {
                xyPlot.setDomainGridlinesVisible(drawGridLine);
            }
            Paint gridLineColor = xAxis.getGridLineColor();
            if (gridLineColor != null) {
                xyPlot.setDomainGridlinePaint(gridLineColor);
            }
            Boolean drawBaseLine = xAxis.getDrawBaseLine();
            if (drawBaseLine != null) {
                xyPlot.setDomainZeroBaselineVisible(drawBaseLine);
            }
            Paint baseLineColor = xAxis.getBaseLineColor();
            if (baseLineColor != null) {
                xyPlot.setDomainZeroBaselinePaint(baseLineColor);
            }
        }

        if (yAxis != null) {
            Boolean drawGridLine = yAxis.getDrawGridLine();
            if (drawGridLine != null) {
                xyPlot.setRangeGridlinesVisible(drawGridLine);
            }
            Paint gridLineColor = yAxis.getGridLineColor();
            if (gridLineColor != null) {
                xyPlot.setRangeGridlinePaint(gridLineColor);
            }
            Boolean drawBaseLine = yAxis.getDrawBaseLine();
            if (drawBaseLine != null) {
                xyPlot.setRangeZeroBaselineVisible(drawBaseLine);
            }
            Paint baseLineColor = yAxis.getBaseLineColor();
            if (baseLineColor != null) {
                xyPlot.setRangeZeroBaselinePaint(baseLineColor);
            }
        }
    }

    if (domainAxis != null) {
        if (xAxisLabel != null)
            domainAxis.setLabel(xAxisLabel);
        if (xAxis != null)
            setAxisStyles(domainAxis, xAxis);
    }
    if (rangeAxis != null) {
        if (yAxisLabel != null)
            rangeAxis.setLabel(yAxisLabel);
        if (yAxis != null)
            setAxisStyles(rangeAxis, yAxis);
    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.CombinedCategoryBar.java

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");

    // recover the datasets
    DefaultCategoryDataset datasetBarFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-bar");
    DefaultCategoryDataset datasetBarSecondAxis = (DefaultCategoryDataset) datasets.getDatasets().get("2-bar");
    DefaultCategoryDataset datasetLineFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-line");
    DefaultCategoryDataset datasetLineSecondAxis = (DefaultCategoryDataset) datasets.getDatasets()
            .get("2-line");

    // create the two subplots
    CategoryPlot subPlot1 = new CategoryPlot();
    CategoryPlot subPlot2 = new CategoryPlot();
    CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

    subPlot1.setDataset(0, datasetBarFirstAxis);
    subPlot2.setDataset(0, datasetBarSecondAxis);

    subPlot1.setDataset(1, datasetLineFirstAxis);
    subPlot2.setDataset(1, datasetLineSecondAxis);

    // localize numbers on y axis
    NumberFormat nf = (NumberFormat) NumberFormat.getNumberInstance(locale);

    // Range Axis 1
    NumberAxis rangeAxis = new NumberAxis(getValueLabel());
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis// w w  w .  ja v  a2s . com
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setUpperMargin(0.10);
    rangeAxis.setNumberFormatOverride(nf);
    subPlot1.setRangeAxis(rangeAxis);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    // Range Axis 2
    NumberAxis rangeAxis2 = new NumberAxis(secondAxisLabel);
    rangeAxis2.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis2.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis2.setUpperMargin(0.10);
    rangeAxis2.setNumberFormatOverride(nf);
    subPlot2.setRangeAxis(rangeAxis2);
    if (rangeIntegerValues == true) {
        rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    // Category Axis
    CategoryAxis domainAxis = new CategoryAxis(getCategoryLabel());
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    domainAxis.setUpperMargin(0.10);
    plot.setDomainAxis(domainAxis);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    // Add subplots to main plot
    plot.add(subPlot1, 1);
    plot.add(subPlot2, 2);

    MyStandardCategoryItemLabelGenerator generator = null;

    // value labels and additional values are mutually exclusive
    if (showValueLabels == true)
        additionalLabels = false;

    if (additionalLabels) {
        generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance());
    }

    //      Create Renderers!
    CategoryItemRenderer barRenderer1 = new BarRenderer();
    CategoryItemRenderer barRenderer2 = new BarRenderer();
    LineAndShapeRenderer lineRenderer1 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null;
    LineAndShapeRenderer lineRenderer2 = (useLinesRenderers == true) ? new LineAndShapeRenderer() : null;

    subPlot1.setRenderer(0, barRenderer1);
    subPlot2.setRenderer(0, barRenderer2);

    if (useLinesRenderers == true) {
        subPlot1.setRenderer(1, lineRenderer1);
        subPlot2.setRenderer(1, lineRenderer2);

        // no shapes for line_no_shapes  series
        for (Iterator iterator = lineNoShapeSeries1.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that
            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineFirstAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer1.setSeriesShapesVisible(index, false);
            }
        }
        for (Iterator iterator = lineNoShapeSeries2.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that

            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineSecondAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer2.setSeriesShapesVisible(index, false);
            }
        }

    }

    // add tooltip if enabled
    if (enableToolTips) {
        MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                seriesTooltip, categoriesTooltip, seriesCaptions);
        barRenderer1.setToolTipGenerator(generatorToolTip);
        barRenderer2.setToolTipGenerator(generatorToolTip);
        if (useLinesRenderers) {
            lineRenderer1.setToolTipGenerator(generatorToolTip);
            lineRenderer2.setToolTipGenerator(generatorToolTip);
        }
    }

    subPlot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    subPlot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // COnfigure renderers: I do in extensive way so will be easier to add customization in the future

    if (maxBarWidth != null) {
        ((BarRenderer) barRenderer1).setMaximumBarWidth(maxBarWidth.doubleValue());
        ((BarRenderer) barRenderer2).setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    // Values or addition Labels for first BAR Renderer
    if (showValueLabels) {
        barRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        barRenderer1.setBaseItemLabelsVisible(true);
        barRenderer1.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        barRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());

        barRenderer1.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer1.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        barRenderer2.setBaseItemLabelsVisible(true);
        barRenderer2.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        barRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());

        barRenderer2.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        barRenderer2.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

    } else if (additionalLabels) {
        barRenderer1.setBaseItemLabelGenerator(generator);
        barRenderer2.setBaseItemLabelGenerator(generator);

        double orient = (-Math.PI / 2.0);
        if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
            orient = 0.0;
        }

        barRenderer1.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer1.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer2.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        barRenderer2.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

    }

    // Values or addition Labels for line Renderers if requested
    if (useLinesRenderers == true) {
        if (showValueLabels) {
            lineRenderer1.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer1.setBaseItemLabelsVisible(true);
            lineRenderer1.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            lineRenderer1.setBaseItemLabelPaint(styleValueLabels.getColor());
            lineRenderer1.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer1.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer2.setBaseItemLabelsVisible(true);
            lineRenderer2.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            lineRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());
            lineRenderer2.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            lineRenderer2.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

        } else if (additionalLabels) {
            lineRenderer1.setBaseItemLabelGenerator(generator);
            lineRenderer2.setBaseItemLabelGenerator(generator);
            double orient = (-Math.PI / 2.0);
            if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
                orient = 0.0;
            }
            lineRenderer1.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer1.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            lineRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));

        }
    }

    // Bar Dataset Colors!
    if (colorMap != null) {
        int idx = -1;
        for (Iterator iterator = datasetBarFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
            idx++;
            String serName = (String) iterator.next();
            String labelName = "";
            int index = -1;

            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serName;
                serName = (String) seriesCaptions.get(serName);
                index = datasetBarFirstAxis.getRowIndex(labelName);
            } else
                index = datasetBarFirstAxis.getRowIndex(serName);

            Color color = (Color) colorMap.get(serName);
            if (color != null) {
                barRenderer1.setSeriesPaint(index, color);
            }
        }

        for (Iterator iterator = datasetBarSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
            idx++;
            String serName = (String) iterator.next();
            String labelName = "";
            int index = -1;

            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serName;
                serName = (String) seriesCaptions.get(serName);
                index = datasetBarSecondAxis.getRowIndex(labelName);
            } else
                index = datasetBarSecondAxis.getRowIndex(serName);

            Color color = (Color) colorMap.get(serName);
            if (color != null) {
                barRenderer2.setSeriesPaint(index, color);
            }
        }
    }

    // LINE Dataset Colors!
    if (useLinesRenderers == true) {
        if (colorMap != null) {
            int idx = -1;
            for (Iterator iterator = datasetLineFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineFirstAxis.getRowIndex(labelName);
                } else
                    index = datasetLineFirstAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer1.setSeriesPaint(index, color);
                }
            }

            for (Iterator iterator = datasetLineSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineSecondAxis.getRowIndex(labelName);
                } else
                    index = datasetLineSecondAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer2.setSeriesPaint(index, color);
                }
            }
        }
    }

    //defines url for drill
    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    logger.debug("Calling Url Generation");

    MyCategoryUrlGenerator mycatUrl = null;
    if (super.rootUrl != null) {
        logger.debug("Set MycatUrl");
        mycatUrl = new MyCategoryUrlGenerator(super.rootUrl);

        mycatUrl.setDocument_composition(document_composition);
        mycatUrl.setCategoryUrlLabel(super.categoryUrlName);
        mycatUrl.setSerieUrlLabel(super.serieUrlname);
        mycatUrl.setDrillDocTitle(drillDocTitle);
        mycatUrl.setTarget(target);
    }
    if (mycatUrl != null) {
        barRenderer1.setItemURLGenerator(mycatUrl);
        barRenderer2.setItemURLGenerator(mycatUrl);
        if (useLinesRenderers) {
            lineRenderer1.setItemURLGenerator(mycatUrl);
            lineRenderer2.setItemURLGenerator(mycatUrl);
        }

    }

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    JFreeChart chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.setBackgroundPaint(Color.white);

    //      I want to re order the legend
    LegendItemCollection legends = plot.getLegendItems();
    // legend Temp 
    HashMap<String, LegendItem> legendTemp = new HashMap<String, LegendItem>();
    Vector<String> alreadyInserted = new Vector<String>();
    for (int i = 0; i < legends.getItemCount(); i++) {
        LegendItem item = legends.get(i);
        String label = item.getLabel();
        legendTemp.put(label, item);
    }
    LegendItemCollection newLegend = new LegendItemCollection();
    // force the order of the ones specified
    for (Iterator iterator = seriesOrder.iterator(); iterator.hasNext();) {
        String serie = (String) iterator.next();
        if (legendTemp.keySet().contains(serie)) {
            newLegend.add(legendTemp.get(serie));
            alreadyInserted.add(serie);
        }
    }
    // check that there are no serie not specified, otherwise add them
    for (Iterator iterator = legendTemp.keySet().iterator(); iterator.hasNext();) {
        String serie = (String) iterator.next();
        if (!alreadyInserted.contains(serie)) {
            newLegend.add(legendTemp.get(serie));
        }
    }

    plot.setFixedLegendItems(newLegend);

    if (legend == true)
        drawLegend(chart);
    logger.debug("OUT");

    return chart;

}

From source file:hudson.plugins.plot.Plot.java

/**
 * Generates the plot and stores it in the plot instance variable.
 *
 * @param forceGenerate//from  w  w  w.jav a2 s  .co m
 *            if true, force the plot to be re-generated even if the on-disk
 *            data hasn't changed
 */
private void generatePlot(boolean forceGenerate) {
    class Label implements Comparable<Label> {
        final private Integer buildNum;
        final private String buildDate;
        final private String text;

        public Label(String buildNum, String buildTime, String text) {
            this.buildNum = Integer.parseInt(buildNum);
            synchronized (DATE_FORMAT) {
                this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime)));
            }
            this.text = text;
        }

        public Label(String buildNum, String buildTime) {
            this(buildNum, buildTime, null);
        }

        public int compareTo(Label that) {
            return this.buildNum - that.buildNum;
        }

        @Override
        public boolean equals(Object o) {
            return o instanceof Label && ((Label) o).buildNum.equals(buildNum);
        }

        @Override
        public int hashCode() {
            return buildNum.hashCode();
        }

        public String numDateString() {
            return "#" + buildNum + " (" + buildDate + ")";
        }

        @Override
        public String toString() {
            return text != null ? text : numDateString();
        }
    }
    // LOGGER.info("Determining if we should generate plot " +
    // getCsvFileName());
    File csvFile = new File(project.getRootDir(), getCsvFileName());
    if (csvFile.lastModified() == csvLastModification && plot != null && !forceGenerate) {
        // data hasn't changed so don't regenerate the plot
        return;
    }
    if (rawPlotData == null || csvFile.lastModified() > csvLastModification) {
        // data has changed or has not been loaded so load it now
        loadPlotData();
    }
    // LOGGER.info("Generating plot " + getCsvFileName());
    csvLastModification = csvFile.lastModified();
    PlotCategoryDataset dataset = new PlotCategoryDataset();
    for (String[] record : rawPlotData) {
        // record: series y-value, series label, build number, build date,
        // url
        int buildNum;
        try {
            buildNum = Integer.valueOf(record[2]);
            if (!reportBuild(buildNum) || buildNum > getRightBuildNum()) {
                continue; // skip this record
            }
        } catch (NumberFormatException nfe) {
            LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe);
            continue; // skip this record all together
        }
        Number value = null;
        try {
            value = Integer.valueOf(record[0]);
        } catch (NumberFormatException nfe) {
            try {
                value = Double.valueOf(record[0]);
            } catch (NumberFormatException nfe2) {
                LOGGER.log(Level.SEVERE, "Exception converting to number", nfe2);
                continue; // skip this record all together
            }
        }
        String series = record[1];
        Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum))
                : new Label(record[2], record[3]);
        String url = null;
        if (record.length >= 5)
            url = record[4];
        dataset.setValue(value, url, series, xlabel);
    }

    String urlNumBuilds = getURLNumBuilds();
    int numBuilds;
    if (StringUtils.isBlank(urlNumBuilds)) {
        numBuilds = Integer.MAX_VALUE;
    } else {
        try {
            numBuilds = Integer.parseInt(urlNumBuilds);
        } catch (NumberFormatException nfe) {
            LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe);
            numBuilds = Integer.MAX_VALUE;
        }
    }

    dataset.clipDataset(numBuilds);
    plot = createChart(dataset);
    CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot();
    categoryPlot.setDomainGridlinePaint(Color.black);
    categoryPlot.setRangeGridlinePaint(Color.black);
    categoryPlot.setDrawingSupplier(Plot.supplier);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build());
    categoryPlot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.03);
    domainAxis.setCategoryMargin(0.0);
    for (Object category : dataset.getColumnKeys()) {
        Label label = (Label) category;
        if (label.text != null) {
            domainAxis.addCategoryLabelToolTip(label, label.numDateString());
        } else {
            domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum));
        }
    }
    // Replace the range axis by a logarithmic axis if the option is
    // selected
    if (isLogarithmic()) {
        LogarithmicAxis logAxis = new LogarithmicAxis(getYaxis());
        logAxis.setExpTickLabelsFlag(true);
        categoryPlot.setRangeAxis(logAxis);
    }

    // optionally exclude zero as default y-axis value
    ValueAxis rangeAxis = categoryPlot.getRangeAxis();
    if ((rangeAxis != null) && (rangeAxis instanceof NumberAxis)) {
        if (hasYaxisMinimum()) {
            ((NumberAxis) rangeAxis).setLowerBound(getYaxisMinimum());
        }
        if (hasYaxisMaximum()) {
            ((NumberAxis) rangeAxis).setUpperBound(getYaxisMaximum());
        }
        ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(!getExclZero());
    }

    AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer();
    int numColors = dataset.getRowCount();
    for (int i = 0; i < numColors; i++) {
        renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f)));
    }
    renderer.setBaseStroke(new BasicStroke(2.0f));
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}",
            NumberFormat.getInstance()));
    renderer.setBaseItemURLGenerator(new PointURLGenerator());
    if (renderer instanceof LineAndShapeRenderer) {
        String s = getUrlStyle();
        LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer;
        if ("lineSimple".equalsIgnoreCase(s)) {
            lasRenderer.setShapesVisible(false); // TODO: deprecated, may be unnecessary
        } else {
            lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary
        }
    }
}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createCategoryEventFreqChart_Time(String title, String xLabel, String yLabel,
        CategoryDataset dataset) {// w  w w .  j ava2 s.  co m

    JFreeChart chart = ChartFactory.createBarChart(title, // title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // dataset
            orientation, // orientation
            true, // include legend
            true, // tooltips
            false // URLs
    );

    chart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xCC));

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f);
    plot.setRangeAxis(new DateAxis(yLabel));
    CategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("",
            DateFormat.getDateInstance());
    LineAndShapeRenderer renderer = new LineAndShapeRenderer(false, true);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    plot.setRenderer(renderer);

    // setCategorySummary(dataset); time
    return chart;
}

From source file:com.naryx.tagfusion.cfm.tag.awt.cfCHART.java

private CategoryPlot getCategoryPlot(List<cfCHARTSERIESData> series, String xAxisTitle, String yAxisTitle,
        String labelFormat, boolean bShowMarkers, int markerSize, boolean bShow3D, String tipStyle,
        String drillDownUrl, int xOffset, int yOffset, int yAxisUnits, String seriesPlacement,
        boolean bSortXAxis, int height, String[] yAxisSymbols, int gridLines) throws cfmRunTimeException {
    // Create a category plot
    CategoryPlot plot = new CategoryPlot();

    // Set the domain axis (the x-axis)
    org.jfree.chart.axis.CategoryAxis categoryAxis;
    if (bShow3D)/*from w  ww  . j a  v  a  2s .  co m*/
        categoryAxis = new CategoryAxis3D(xAxisTitle);
    else
        categoryAxis = new CategoryAxis(xAxisTitle);
    plot.setDomainAxis(categoryAxis);

    // Set the range axis (the y-axis)
    ValueAxis valueAxis;
    DateFormat dateFormat = null;
    NumberFormat numberFormat = null;

    // Ignore a label format of date if the y-axis is using symbols
    if (labelFormat.equals("date") && (yAxisSymbols == null)) {
        valueAxis = new DateAxis(yAxisTitle);
        dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        ((DateAxis) valueAxis).setDateFormatOverride(dateFormat);
    } else {
        if (yAxisSymbols != null) {
            valueAxis = new SymbolAxis(yAxisTitle, yAxisSymbols);
            ((SymbolAxis) valueAxis).setGridBandsVisible(false);
            ((SymbolAxis) valueAxis).setAutoRangeStickyZero(true);
        } else if (bShow3D) {
            valueAxis = new NumberAxis3D(yAxisTitle);
        } else {
            valueAxis = new NumberAxis(yAxisTitle);
        }

        if (labelFormat.equals("currency")) {
            ((NumberAxis) valueAxis).setNumberFormatOverride(NumberFormat.getCurrencyInstance());
            numberFormat = NumberFormat.getCurrencyInstance();
        } else if (labelFormat.equals("percent")) {
            numberFormat = NumberFormat.getPercentInstance();
            numberFormat.setMaximumFractionDigits(3); // without this change .11443
                                                      // would be displayed as 11%
                                                      // instead of 11.443%
            ((NumberAxis) valueAxis).setNumberFormatOverride(numberFormat);
        } else {
            numberFormat = NumberFormat.getInstance();
        }

        if (yAxisUnits != 0)
            ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits));
    }
    plot.setRangeAxis(valueAxis);

    // Add a dataset and renderer for each series
    int barChartDatasetIndex = -1;
    int hBarChartDatasetIndex = -1;
    int num = 0;
    MinMaxData minMax = new MinMaxData();
    for (int i = 0; i < series.size(); i++) {
        cfCHARTSERIESData seriesData = series.get(i);

        // If the sortXAxis attribute was set to "yes" then sort the data.
        // NOTE: this attribute is only used with category charts.
        if (bSortXAxis)
            seriesData.sort();

        DefaultCategoryDataset dataset;
        if ((barChartDatasetIndex != -1) && (seriesData.getType().equals("bar"))) {
            dataset = (DefaultCategoryDataset) plot.getDataset(barChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(barChartDatasetIndex),
                    dataset.getRowCount() - 1, height);

            // Add the color list for this series to the custom color renderer
            CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(barChartDatasetIndex);
            cr.addColors(getColorList(seriesData));

            continue;
        } else if ((hBarChartDatasetIndex != -1) && (seriesData.getType().equals("horizontalbar"))) {
            dataset = (DefaultCategoryDataset) plot.getDataset(hBarChartDatasetIndex);

            addSeriesDataToDataset(seriesData, dataset, minMax);

            // Set the paint style for this series
            setPaintStyle(seriesData.getPaintStyle(), plot.getRenderer(hBarChartDatasetIndex),
                    dataset.getRowCount() - 1, height);

            // Add the color list for this series to the custom color renderer
            CustomColorRenderer cr = (CustomColorRenderer) plot.getRenderer(hBarChartDatasetIndex);
            cr.addColors(getColorList(seriesData));

            continue;
        } else {
            dataset = new DefaultCategoryDataset();

            addSeriesDataToDataset(seriesData, dataset, minMax);
        }

        plot.setDataset(num, dataset);

        AbstractCategoryItemRenderer renderer = null;
        if (seriesData.getType().equals("bar")) {
            plot.setOrientation(PlotOrientation.VERTICAL);
            renderer = getBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData));
            ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER);
            renderer.setPositiveItemLabelPosition(position1);
            ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6,
                    TextAnchor.TOP_CENTER);
            renderer.setNegativeItemLabelPosition(position2);
            ((BarRenderer) renderer).setItemMargin(0.0); // The margin between items
                                                         // in the same category
            categoryAxis.setCategoryMargin(0.2); // The margin between each category

            barChartDatasetIndex = num;
        } else if (seriesData.getType().equals("horizontalbar")) {
            plot.setOrientation(PlotOrientation.HORIZONTAL);
            plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
            renderer = getBarRenderer(seriesPlacement, bShow3D, xOffset, yOffset, getColorList(seriesData));
            if (bShow3D) {
                // change rendering order to ensure that bar overlapping is the
                // right way around
                plot.setRowRenderingOrder(org.jfree.util.SortOrder.DESCENDING);
                plot.setColumnRenderingOrder(org.jfree.util.SortOrder.DESCENDING);
            }
            ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3,
                    TextAnchor.CENTER_LEFT);
            renderer.setPositiveItemLabelPosition(position1);
            ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9,
                    TextAnchor.CENTER_RIGHT);
            renderer.setNegativeItemLabelPosition(position2);
            ((BarRenderer) renderer).setItemMargin(0.0); // The margin between items
                                                         // in the same category
            categoryAxis.setCategoryMargin(0.2); // The margin between each category

            hBarChartDatasetIndex = num;
        } else if (seriesData.getType().equals("line")) {
            if (bShow3D) {
                renderer = new LineRenderer3D();
                ((LineRenderer3D) renderer).setXOffset(xOffset);
                ((LineRenderer3D) renderer).setYOffset(yOffset);
            } else {
                renderer = new LineAndShapeRenderer(true, false);
            }

            // Enable/Disable displaying of markers
            ((LineAndShapeRenderer) renderer).setShapesVisible(bShowMarkers);

            // Set the shape of the markers based on the markerSize value
            ((LineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize));
        } else if (seriesData.getType().equals("area")) {
            if (seriesPlacement.equals("stacked"))
                renderer = new StackedAreaRenderer(); // this doesn't work for some
                                                      // reason
            else
                renderer = new AreaRenderer();

            // Truncate the first and last values to match CFMX 7
            ((AreaRenderer) renderer).setEndType(AreaRendererEndType.TRUNCATE);

            categoryAxis.setCategoryMargin(0.0);
        } else if (seriesData.getType().equals("step")) {
            renderer = new CategoryStepRenderer(true);
        } else if (seriesData.getType().equals("scatter")) {
            renderer = new LineAndShapeRenderer(false, true);

            // Set the shape of the markers based on the markerSize value
            ((LineAndShapeRenderer) renderer).setShape(getMarker(seriesData.getMarkerStyle(), markerSize));
        }

        if (!tipStyle.equals("none")) {
            if (dateFormat != null)
                renderer.setBaseToolTipGenerator(
                        new StandardCategoryToolTipGenerator("({0}, {1}) = {2}", dateFormat));
            else
                renderer.setBaseToolTipGenerator(
                        new StandardCategoryToolTipGenerator("({0}, {1}) = {2}", numberFormat));
        }

        if (drillDownUrl != null) {
            if (dateFormat != null)
                renderer.setBaseItemURLGenerator(
                        new com.newatlanta.bluedragon.CategoryURLGenerator(drillDownUrl, dateFormat));
            else
                renderer.setBaseItemURLGenerator(
                        new com.newatlanta.bluedragon.CategoryURLGenerator(drillDownUrl, numberFormat));
        }

        if (seriesData.getSeriesColor() != null)
            renderer.setSeriesPaint(0, convertStringToColor(seriesData.getSeriesColor()));

        String dataLabelStyle = seriesData.getDataLabelStyle();
        if (labelFormat.equals("date")) {
            if (dataLabelStyle.equals("none")) {
                renderer.setItemLabelsVisible(false);
            } else {
                setCategoryItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{2}", dateFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("rowlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{0}", dateFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("columnlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1}", dateFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("pattern"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1} {2}", dateFormat, yAxisSymbols));
                else
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator(dataLabelStyle, dateFormat, yAxisSymbols));
            }
        } else {
            if (dataLabelStyle.equals("none")) {
                renderer.setItemLabelsVisible(false);
            } else {
                setCategoryItemLabelsData(renderer, seriesData);
                if (dataLabelStyle.equals("value"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{2}", numberFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("rowlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{0}", numberFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("columnlabel"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1}", numberFormat, yAxisSymbols));
                else if (dataLabelStyle.equals("pattern"))
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator("{1} {2} ({3} of {4})", numberFormat, yAxisSymbols));
                else
                    renderer.setItemLabelGenerator(
                            new CategoryItemLabelGenerator(dataLabelStyle, numberFormat, yAxisSymbols));
            }
        }

        // Add the renderer to the plot.
        // NOTE: this must be done before the setPaintStyle() call so the
        // DrawingSupplier object
        // will be set up properly for the generation of default colors.
        plot.setRenderer(num, renderer);

        // Set the paint style for this series (series 0)
        if (seriesData.getType().equals("bar") || seriesData.getType().equals("horizontalbar")
                || seriesData.getType().equals("area"))
            setPaintStyle(seriesData.getPaintStyle(), renderer, 0, height);

        num++;
    }

    // If gridLines was specified then we need to calculate the yAxisUnits
    if ((gridLines != -1) && (valueAxis instanceof NumberAxis)) {
        // Calculate the yAxisUnits we need to use to create the number of
        // gridLines
        yAxisUnits = calculateYAxisUnits(gridLines, minMax);

        // Set the yAxisUnits
        ((NumberAxis) valueAxis).setTickUnit(new NumberTickUnit(yAxisUnits));
    }

    return plot;
}