Example usage for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions

List of usage examples for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis setCategoryLabelPositions.

Prototype

public void setCategoryLabelPositions(CategoryLabelPositions positions) 

Source Link

Document

Sets the category label position specification for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:userinterface.HealthAnalystRole.ViewReportJPanel.java

private void createChart() {
    DefaultCategoryDataset healthDataset = new DefaultCategoryDataset();
    int selectedRow = tblHealthTable.getSelectedRow();
    Device effects = (Device) tblHealthTable.getValueAt(selectedRow, 0);
    //Device device= device.getEffectsOnBodyList().getEffectsOnBodyList().;

    for (Device d : organization.getDeviceDirectory().getDeviceList()) {
        if (d.getEffectsOnBodyList().getEffectsOnBodyList().isEmpty()
                || d.getEffectsOnBodyList().getEffectsOnBodyList().size() == 1) {
            JOptionPane.showMessageDialog(this,
                    "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!",
                    "Warning", JOptionPane.INFORMATION_MESSAGE);
            return;
        } else {// w  ww  . j a  v a2 s.  com
            Double organ = Double.parseDouble(txtOrgan.getText());
            Double value = d.getMaxSAR();
        }
    }
    //ArrayList<EffectsOnBody> effectsOnBodyList = device.getEffectsOnBodyList().getEffectsOnBodyList();

    /*if (effectsOnBodyList.isEmpty() || effectsOnBodyList.size() == 1) {
    JOptionPane.showMessageDialog(this, "No body organs or only one body organ affected found. At least 2 organs effected records needed to show chart!", "Warning", JOptionPane.INFORMATION_MESSAGE);
    return;
    }*/
    Double organ = Double.parseDouble(txtOrgan.getText());
    for (Device device : organization.getDeviceDirectory().getDeviceList()) {
        for (EffectsOnBody b1 : device.getEffectsOnBodyList().getEffectsOnBodyList()) {
            Double value = device.getMaxSAR();

            //healthDataset.addValue(vitalSign.getHeartRate(),"Most Likely Diseases", device.getMaxSAR());
            //vitalSignDataset.addValue(vitalSign.getBloodPressure(),"BP", vitalSign.getTimestamp());
            //vitalSignDataset.addValue(vitalSign.getWeight(),"WT", vitalSign.getTimestamp());
        }

    }

    JFreeChart healthSignChart = ChartFactory.createBarChart3D("Effects On Health Chart", "Time Stamp", "Rate",
            healthDataset, PlotOrientation.VERTICAL, true, false, false);
    healthSignChart.setBackgroundPaint(Color.white);
    CategoryPlot vitalSignChartPlot = healthSignChart.getCategoryPlot();
    vitalSignChartPlot.setBackgroundPaint(Color.lightGray);

    CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis();
    vitalSignDomainAxis
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis();
    vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame chartFrame = new ChartFrame("Chart", healthSignChart);
    chartFrame.setVisible(true);
    chartFrame.setSize(500, 500);

}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a bar chart./*w ww.jav  a 2  s.  co  m*/
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @return JfreeChart instance.
 */
public JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    return chart;
}

From source file:ds.monte.carlo.Application.java

private void createGrowthGraph(double[] growthMap) {
    DefaultCategoryDataset growthDataset = new DefaultCategoryDataset();
    double min = 1000000;
    double max = 0;
    int l_100 = growthMap.length;
    int l_40 = (int) Math.round(l_100 * 0.4);
    System.out.print(growthMap.length);
    for (int i = l_40; i < growthMap.length; i++) {
        growthDataset.setValue(growthMap[i], "", "" + i);
        if (growthMap[i] < min) {
            min = growthMap[i];/*from w w  w.  j ava 2  s.  c  om*/
        }
        if (growthMap[i] > max) {
            max = growthMap[i];
        }
    }

    JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", growthDataset,
            PlotOrientation.VERTICAL, false, false, false);
    growChart.setBackgroundPaint(Color.WHITE);

    CategoryPlot catPlot = growChart.getCategoryPlot();
    catPlot.setRangeGridlinePaint(new Color(92, 184, 92));

    ValueAxis vAxis = catPlot.getRangeAxis();
    CategoryAxis cAxis = catPlot.getDomainAxis();

    cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    vAxis.setRange(min, max);

    cAxis.setTickLabelsVisible(false);

    Font font = new Font("SansSerif", Font.PLAIN, 12);
    Font fontTitle = new Font("SansSerif", Font.PLAIN, 14);
    vAxis.setTickLabelFont(font);
    growChart.getTitle().setFont(fontTitle);

    LineAndShapeRenderer renderer = (LineAndShapeRenderer) catPlot.getRenderer();
    Color bootstrapGreen = new Color(92, 184, 92);
    renderer.setSeriesPaint(0, bootstrapGreen);

    ChartPanel chartPanel = new ChartPanel(growChart);
    jPanel6.removeAll();
    jPanel6.add(chartPanel, BorderLayout.CENTER);
    jPanel6.validate();
    //jPanel5.setVisible(true);
}

From source file:vis2006.VisGrafik.java

public JFreeChart createChart(Stand st, int speciesCode) {
    // create the dataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Durchmesserhufigkeiten in 5-cm-Klassen bestimmen (Klassenmitten: 7.5 bis max. 152.5)
    for (int i = 0; i < 30; i++) {
        for (int j = 0; j < 3; j++) {
            double anz = 0;
            double gesamtZahl = 0;
            for (int k = 0; k < st.ntrees; k++) {
                if (speciesCode == st.tr[k].code && st.tr[k].fac > 0.0) {
                    if ((st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5))
                        gesamtZahl = gesamtZahl + st.tr[k].fac;
                    if ((j == 2) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0)
                            && (st.tr[k].crop == true))
                        anz = anz + st.tr[k].fac;
                    if ((j == 0) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out < 0)
                            && (st.tr[k].crop == false))
                        anz = anz + st.tr[k].fac;
                    if ((j == 1) && (st.tr[k].d > i * 5) && (st.tr[k].d <= (i + 1) * 5) && (st.tr[k].out > 0))
                        anz = anz + st.tr[k].fac;
                }/*from ww w . ja  v a2  s  . co  m*/
            }
            if (gesamtZahl > 0) {
                Integer m = (5 * i) + 2;
                String textcode = "";
                if (j == 0)
                    textcode = "verbleibend";
                if (j == 1)
                    textcode = "ausscheidend";
                if (j == 2)
                    textcode = "Z-Bume";
                dataset.addValue(anz / st.size, // Anzahl pro ha
                        textcode, // Gruppe
                        m.toString() + ".5"); // Durchmesserklassenmitte

            }
        }
    }

    //     
    JFreeChart chart = ChartFactory.createStackedBarChart(messages.getString("diameterDistribution"), // chart title
            messages.getString("dbhClass"), // domain axis label
            messages.getString("numberOfStems"), // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = chart.getCategoryPlot();
    //     plot.setBackgroundPaint(Color.lightGray);
    //     plot.setDomainGridlinePaint(Color.white);
    //     plot.setDomainGridlinesVisible(true);
    //     plot.setRangeGridlinePaint(Color.white);
    // reenderer
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    // set up gradient paints for series...
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesPaint(2, Color.BLUE);
    //renderer.setMaxBarWidth(0.15);
    renderer.setMaximumBarWidth(0.15);

    if (dataset.getColumnCount() > 10) {
        CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
        if (dataset.getColumnCount() < 21)
            xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        else
            xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    }

    return chart;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a line chart.//  ww  w.ja  va 2s  .  com
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @param includeZero
 *            True when zero shall be included to the axis range.
 * @return JfreeChart instance.
 */
public JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, boolean includeZero, boolean drawShapes) {
    JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.025);
    domainAxis.setUpperMargin(0.025);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(includeZero);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseShapesVisible(drawShapes);
    renderer.setBaseShapesFilled(true);
    return chart;
}

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

/**
 * Inherited by IChart.//from   w w  w .  ja v a  2  s . c  o m
 * 
 * @param chartTitle the chart title
 * @param dataset the dataset
 * 
 * @return the j free chart
 */

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    CategoryAxis categoryAxis = new CategoryAxis(categoryLabel);
    ValueAxis valueAxis = new NumberAxis(valueLabel);
    if (rangeIntegerValues == true) {
        valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    org.jfree.chart.renderer.category.BarRenderer renderer = new org.jfree.chart.renderer.category.BarRenderer();

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    //      renderer.setBaseItemLabelFont(new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
    //      renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

    if (showValueLabels) {
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());
    }

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

    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    MyCategoryUrlGenerator mycatUrl = new MyCategoryUrlGenerator(rootUrl);
    mycatUrl.setDocument_composition(document_composition);
    mycatUrl.setCategoryUrlLabel(categoryUrlName);
    mycatUrl.setSerieUrlLabel(serieUrlname);
    mycatUrl.setDrillDocTitle(drillDocTitle);
    mycatUrl.setTarget(target);

    renderer.setItemURLGenerator(mycatUrl);

    /*      }
    else{
       renderer.setItemURLGenerator(new StandardCategoryURLGenerator(rootUrl));
    }*/

    CategoryPlot plot = new CategoryPlot((CategoryDataset) dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    if (horizontalView) {
        plot.setOrientation(PlotOrientation.HORIZONTAL);
    }

    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

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

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(color);

    // get a reference to the plot for further customisation...
    //CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setNumberFormatOverride(nf);

    if (rangeAxisLocation != null) {
        if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
        } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
        }
    }

    // disable bar outlines...
    //BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    /*   if(currentSeries!=null && colorMap!=null){
       //for each serie selected
       int j=0;   
       for (Iterator iterator = currentSeries.iterator(); iterator.hasNext();) {
    String s = (String) iterator.next();
    Integer position=(Integer)seriesNumber.get(s);
    // check if for that position a value is defined
    if(colorMap.get("color"+position.toString())!=null){
       Color col= (Color)colorMap.get("color"+position);
       renderer.setSeriesPaint(j, col);
    }
    j++;
       }  // close for on series
    } // close case series selcted and color defined
    else{
       if(colorMap!=null){ // if series not selected check color each one
            
    for (Iterator iterator = colorMap.keySet().iterator(); iterator.hasNext();) {
       String key = (String) iterator.next();
       Color col= (Color)colorMap.get(key);
       String keyNum=key.substring(5, key.length());
       int num=Integer.valueOf(keyNum).intValue();
       num=num-1;
       renderer.setSeriesPaint(num, col);
    }
       }
    }*/

    int seriesN = dataset.getRowCount();

    if (orderColorVector != null && orderColorVector.size() > 0) {
        logger.debug("color serie by SERIES_ORDER_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            if (orderColorVector.get(i) != null) {
                Color color = orderColorVector.get(i);
                renderer.setSeriesPaint(i, color);
            }
        }
    } else if (colorMap != null) {
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getRowKey(i);
            Color color = (Color) colorMap.get(serieName);
            if (color != null) {
                renderer.setSeriesPaint(i, color);
            }
        }
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    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());

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

    logger.debug("OUT");
    return chart;

}

From source file:tn.mariages.gui.Accueil.java

public JFreeChart createChart(CategoryDataset dataset) {
    final JFreeChart chart = ChartFactory.createBarChart(" Ventes par mois ", // chart title
            " ", // domain axis label
            "  Le nombre de produit ", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            true // urls
    );/*from  w  ww  . j a v  a 2 s  .c o  m*/

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    return chart;
}

From source file:org.toobsframework.pres.chart.ChartUtil.java

public static CategoryAxis createCategoryAxis(IRequest componentRequest, DomainAxisDef categoryAxisDef,
        Map params, boolean is3D) {
    CategoryAxis categoryAxis;
    if (is3D) {//  w w  w  .ja  v a 2 s  .  co m
        categoryAxis = new CategoryAxis3D();
    } else {
        categoryAxis = new CategoryAxis();
    }
    if (categoryAxisDef != null) {
        if (categoryAxisDef.getDomainLabel() != null) {
            categoryAxis
                    .setLabel(evaluateTextLabel(componentRequest, categoryAxisDef.getDomainLabel(), params));
            if (categoryAxisDef.getDomainLabel().getFont() != null) {
                categoryAxis.setLabelFont(getFont(categoryAxisDef.getDomainLabel(), null));
            }
            categoryAxis.setLabelPaint(getColor(categoryAxisDef.getDomainLabel().getColor()));
        }

        if (categoryAxisDef.getLabelPosition() != null) {
            Integer labelPos = domainLabelPositions.get(ParameterUtil.resolveParam(componentRequest,
                    categoryAxisDef.getLabelPosition(), params, "standard")[0]);
            if (labelPos != null) {
                switch (labelPos) {
                case DOM_LABEL_STANDARD_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
                    break;
                case DOM_LABEL_UP_45_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
                    break;
                case DOM_LABEL_DOWN_45_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
                    break;
                case DOM_LABEL_UP_90_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
                    break;
                case DOM_LABEL_DOWN_90_TYPE:
                    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
                    break;
                }
            }
        }
        double domainMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getDomainMargin(), params, "0.0")[0]);
        double lowerMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getLowerMargin(), params, "0.0")[0]);
        double upperMargin = Double.parseDouble(ParameterUtil.resolveParam(componentRequest,
                categoryAxisDef.getUpperMargin(), params, "0.0")[0]);

        categoryAxis.setCategoryMargin(domainMargin);
        categoryAxis.setLowerMargin(lowerMargin);
        categoryAxis.setUpperMargin(upperMargin);
    }
    return categoryAxis;
}

From source file:org.adempiere.apps.graph.ChartBuilder.java

private void setupCategoryChart(JFreeChart chart) {
    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesPaint(3, Color.GREEN);
    renderer.setSeriesPaint(4, Color.ORANGE);
    renderer.setSeriesPaint(5, Color.CYAN);
    renderer.setSeriesPaint(6, Color.MAGENTA);
    renderer.setSeriesPaint(7, Color.GRAY);
    renderer.setSeriesPaint(8, Color.PINK);

    plot.setRenderer(renderer);//  w  w w.  j a v  a 2  s . co  m
}

From source file:hudson.tasks.test.AbstractTestResultAction.java

private JFreeChart createChart(StaplerRequest req, CategoryDataset dataset) {

    final String relPath = getRelPath(req);

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // unused
            "count", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//from   www.  j  a  va2  s  .co  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //        legend.setAnchor(StandardLegend.SOUTH);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    //        plot.setDomainGridlinesVisible(true);
    //        plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            return relPath + label.getRun().getNumber() + "/testReport/";
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            NumberOnlyBuildLabel label = (NumberOnlyBuildLabel) dataset.getColumnKey(column);
            AbstractTestResultAction a = label.getRun().getAction(AbstractTestResultAction.class);
            switch (row) {
            case 0:
                return String.valueOf(Messages.AbstractTestResultAction_fail(label.getRun().getDisplayName(),
                        a.getFailCount()));
            case 1:
                return String.valueOf(Messages.AbstractTestResultAction_skip(label.getRun().getDisplayName(),
                        a.getSkipCount()));
            default:
                return String.valueOf(Messages.AbstractTestResultAction_test(label.getRun().getDisplayName(),
                        a.getTotalCount()));
            }
        }
    };
    plot.setRenderer(ar);
    ar.setSeriesPaint(0, ColorPalette.RED); // Failures.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Skips.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}