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:dk.sdu.mmmi.featureous.views.codecharacterization.TanglingViewChart.java

public TanglingViewChart(boolean pkg, boolean sortByValue) {
    this.sortByValue = sortByValue;
    this.pkg = pkg;
    data = new DefaultKeyedValues2DDataset();
    String title = "Computational unit characterization";
    jchart = ChartFactory.createStackedBarChart(title, (pkg) ? "Package" : "Class", "Tangling", data,
            PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) jchart.getPlot();
    //        chart.getLegend().setPosition(RectangleEdge.RIGHT);
    //        chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP);
    //        chart.getLegend().setHorizontalAlignment(HorizontalAlignment.LEFT);
    LegendItemCollection lic = new LegendItemCollection();
    //        lic.add(new LegendItem("Infrastructural unit", "", "", "", new Rectangle(10, 10), Color.GREEN));
    //        lic.add(new LegendItem("Group-feature unit", "", "", "", new Rectangle(10, 10), Color.BLUE));
    //        lic.add(new LegendItem("Single-feature unit", "", "", "", new Rectangle(10, 10), Color.RED));
    plot.setFixedLegendItems(lic);/*from  w w  w  .  ja  v a 2  s  .  co m*/
    //        chart.removeLegend();
    plot.setDomainAxis(new SparselyLabeledCategoryAxis(20));
    CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    xAxis.setLabel((pkg) ? "Package" : "Class");
    //        xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 5, 5));
    //        xAxis.setMaximumCategoryLabelLines(1);
    xAxis.setLowerMargin(0);
    xAxis.setCategoryMargin(0);
    xAxis.setUpperMargin(0);
    //        xAxis.setMaximumCategoryLabelWidthRatio(20f);
    jchart.setBackgroundPaint(Color.white);

    StackedBarRenderer renderer = new StackedBarRenderer() {

        @Override
        public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
                CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset,
                int row, int column, int pass) {
            super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
            double start = plot.getDomainAxis().getCategoryStart(column, getColumnCount(), dataArea,
                    plot.getDomainAxisEdge());
            double end = plot.getDomainAxis().getCategoryEnd(column, getColumnCount(), dataArea,
                    plot.getDomainAxisEdge());

            String compUnit = data.getRowKey(row).toString();

            // Calculate y coeffs
            double posBase = getBase();
            //                for(int i = 0; i<row; i++){
            //                    Number val = dataset.getValue(i, column);
            //                    if(val!=null){
            //                        posBase = posBase + val.doubleValue();
            //                    }
            //                }

            Number value = dataset.getValue(row, column);
            if (value == null) {
                return;
            }
            double val = value.doubleValue();

            double translatedBase = plot.getRangeAxis().valueToJava2D(posBase, dataArea,
                    plot.getRangeAxisEdge());
            double translatedValue = plot.getRangeAxis().valueToJava2D(posBase + val, dataArea,
                    plot.getRangeAxisEdge());

            if (Controller.getInstance().getTraceSet().getSelectionManager().getSelectedClasses()
                    .contains(compUnit)
                    || Controller.getInstance().getTraceSet().getSelectionManager().getSelectedPkgs()
                            .contains(compUnit)) {
                g2.setPaint(UIUtils.SELECTION_COLOR);
                g2.setStroke(new BasicStroke(3f));
                Line2D l2d = new Line2D.Double(start, translatedBase, start, translatedValue);
                g2.draw(l2d);
                l2d = new Line2D.Double(end, translatedBase, end, translatedValue);
                g2.draw(l2d);
                l2d = new Line2D.Double(start, translatedBase, end, translatedBase);
                g2.draw(l2d);
                l2d = new Line2D.Double(start, translatedValue, end, translatedValue);
                g2.draw(l2d);
            }
        }
    };

    renderer.setToolTipGenerator(new CategoryToolTipGenerator() {

        public String generateToolTip(CategoryDataset cd, int i, int i1) {
            String key = data.getRowKey(i).toString();
            //                key = key.substring(0, key.length()-1);
            return "<html>" + i + " - " + key + "<br>" + Double.toString(cd.getValue(i, i1).doubleValue())
                    + "</hmtl>";
        }
    });

    plot.setRenderer(renderer);

    panel = new ChartPanel(jchart);

    panel.getPopupMenu().setEnabled(false);//add(SVGExporter.createExportAction(chart, panel));

    createView();
    Controller.getInstance().getTraceSet().getSelectionManager().addSelectionListener(this);
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo1.java

/**
 * Creates a sample chart./*from  w  w  w  .  j av a2s. co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {
    domainLabel = "Category";
    rangeLabel = "Value";
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips?
            false // URLs?
    );

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

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

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

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

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

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    /*Summary s = new Summary(dataset);
            
            
            
      LegendTitle legend = new LegendTitle(chart.getPlot());
              
      BlockContainer wrapper = new BlockContainer(new BorderArrangement());
      wrapper.setBorder(new BlockBorder(1.0, 1.0, 1.0, 1.0));
            
    LegendItemSource[] legendSource= legend.getSources();
    LegendItemCollection old_legendItems = legendSource[0].getLegendItems();
    LegendItemCollection new_legendItems = new LegendItemCollection();
            
    int legendCount  = old_legendItems.getItemCount();
    for (int i=0; i<legendCount; i++){
       LegendItem old_legendItem = old_legendItems.get(i);
            
       String legendLabel = old_legendItem.getLabel();
       System.out.println("legendLabel="+old_legendLabel);
       LegendItem new_legendItem = new LegendItem(
                                  old_legendItem.getLabel()+s.getSummary(i),
                                  old_legendItem.getDescription(),
                                  old_legendItem.getToolTipText(),
                                  old_legendItem.getURLText(),
                                  old_legendItem.isShapeVisible(),
                                  old_legendItem.getShape(),
                                  old_legendItem.isShapeFilled(),
                                  old_legendItem.getFillPaint(),
                                  old_legendItem.isShapeOutlineVisible(),
                                  old_legendItem.getOutlinePaint(),
                                  old_legendItem.getOutlineStroke(),
                                  old_legendItem.isLineVisible(),
                                  old_legendItem.getLine(),
                                  old_legendItem.getLineStroke(),
                                  old_legendItem.getlinePaint()
                                  );
       new_legendItems.add(new_legendItem);
       }
              
            
      // *** this is important - you need to add the item container to
      // the wrapper, otherwise the legend items won't be displayed when
      // the wrapper is drawn... ***
      BlockContainer items = legend.getItemContainer();
      items.setPadding(2, 10, 5, 2);
      wrapper.add(items);
      legend.setWrapper(wrapper);
              
      legend.setPosition(RectangleEdge.BOTTOM);
      legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
      chart.addSubtitle(legend);*/

    setCategorySummary(dataset);
    return chart;

}

From source file:com.cwctravel.hudson.plugins.suitegroupedtests.TrendGraph.java

@Override
protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );//w w w .  j a v a 2 s. co m

    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();
    ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 7962375662395944968L;

        @Override
        public Paint getItemPaint(int row, int column) {
            ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
            if (key.getColor() != null)
                return key.getColor();
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getURL() + relativeUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

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

    return chart;
}

From source file:biz.ixnay.pivot.charts.skin.jfree.LineChartViewSkin.java

@Override
protected JFreeChart createChart() {
    LineChartView chartView = (LineChartView) getComponent();

    String title = chartView.getTitle();
    String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
    String verticalAxisLabel = chartView.getVerticalAxisLabel();
    boolean showLegend = chartView.getShowLegend();

    String seriesNameKey = chartView.getSeriesNameKey();
    List<?> chartData = chartView.getChartData();

    JFreeChart chart;/*from   w w  w . ja  v a  2s  . com*/
    ChartView.CategorySequence categories = chartView.getCategories();
    if (categories.getLength() > 0) {
        CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

        if (threeDimensional) {
            chart = ChartFactory.createLineChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else {
            chart = ChartFactory.createLineChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        }

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        CategoryLabelPositions categoryLabelPositions = CategoryLabelPositions
                .createUpRotationLabelPositions(categoryLabelRotation);
        domainAxis.setCategoryLabelPositions(categoryLabelPositions);

        if (rangeAxisRange != null) {
            ValueAxis rangeAxis = plot.getRangeAxis();
            rangeAxis.setRange(rangeAxisRange);
        }
    } else {
        chart = ChartFactory.createXYLineChart(title, horizontalAxisLabel, verticalAxisLabel,
                new XYSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend, false,
                false);

        if (rangeAxisRange != null) {
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis rangeAxis = plot.getRangeAxis();
            rangeAxis.setRange(rangeAxisRange);
        }
    }

    return chart;
}

From source file:de.mpg.mpdl.inge.pubman.web.statistic_charts.StatisticChartServlet.java

/**
 * Creates the statistic chart.//from w ww  . j av  a  2 s. co  m
 * 
 * @param dataset the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart
    JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips?
            false // URLs?
    );

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

    // get a reference to the plot for further customisation
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5));
    plot.setDomainGridlinePaint(Color.gray);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);

    // set the range axis to display integers only
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    // disable bar outlines...
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series
    /*
     * GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0,
     * 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64,
     * 0, 0));
     */
    Color series1Color = new Color(0xfa, 0x80, 0x72);
    Color series2Color = new Color(0x64, 0x95, 0xed);
    renderer.setSeriesPaint(1, series1Color);
    renderer.setSeriesPaint(0, series2Color);

    // remove shadow
    renderer.setShadowVisible(false);
    //

    // Labels in bars
    /*
     * renderer.setSeriesItemLabelsVisible(0, true); renderer.setSeriesItemLabelGenerator(0, new
     * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(0, Color.white);
     * renderer.setSeriesItemLabelsVisible(1, true); renderer.setSeriesItemLabelGenerator(1, new
     * StandardCategoryItemLabelGenerator()); renderer.setSeriesItemLabelPaint(1, Color.white);
     */

    // setCategorySummary(dataset);

    // rotate labels on x-axis
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;

}

From source file:com.cwctravel.hudson.plugins.multimoduletests.TrendGraph.java

@Override
protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*from w ww  . j a v a2 s .c om*/

    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();
    ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        private static final long serialVersionUID = 7962375662395944968L;

        @Override
        public Paint getItemPaint(int row, int column) {
            ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
            if (key.getColor() != null)
                return key.getColor();
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return prefixUrl + label.getURL() + suffixUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

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

    return chart;
}

From source file:piilSource.BarChart.java

private JFreeChart createChart(String title, final CategoryDataset dataset, String metaLabel) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart(
            "Barplot of the " + metaLabel + " values for all samples - " + title, // chart title
            "Samples", // domain axis label
            metaLabel + " values", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//  w ww.  jav  a2 s  .  c o  m

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

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.red);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (metaLabel.equals("beta")) {
        rangeAxis.setRange(0, 1);
        rangeAxis.setTickUnit(new NumberTickUnit(0.2));
    }

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

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.green);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.red);
    final GradientPaint gp3 = new GradientPaint(0.0f, 0.0f, Color.yellow, 0.0f, 0.0f, Color.yellow);
    final GradientPaint gp4 = new GradientPaint(0.0f, 0.0f, Color.cyan, 0.0f, 0.0f, Color.cyan);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setSeriesPaint(3, gp3);
    renderer.setSeriesPaint(4, gp4);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    if (dataset.getColumnCount() > 40) {
        domainAxis.setTickLabelFont(new Font("Serif", Font.PLAIN, 10));
        domainAxis
                .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2));
    }
    return chart;
}

From source file:de.mpg.escidoc.pubman.statistic_charts.StatisticChartServlet.java

/**
 * Creates the statistic chart.//w  ww.java 2 s . co  m
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private JFreeChart createChart(CategoryDataset dataset) {

    // create the chart
    JFreeChart chart = ChartFactory.createStackedBarChart(null, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips?
            false // URLs?
    );

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

    // get a reference to the plot for further customisation
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xf5, 0xf5, 0xf5));
    plot.setDomainGridlinePaint(Color.gray);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);

    // set the range axis to display integers only
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    // disable bar outlines...
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series
    /*
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue,
        0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red,
        0.0f, 0.0f, new Color(64, 0, 0));
    */
    Color series1Color = new Color(0xfa, 0x80, 0x72);
    Color series2Color = new Color(0x64, 0x95, 0xed);
    renderer.setSeriesPaint(1, series1Color);
    renderer.setSeriesPaint(0, series2Color);

    //remove shadow
    renderer.setShadowVisible(false);
    //

    //Labels in bars
    /*
    renderer.setSeriesItemLabelsVisible(0, true);
    renderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelPaint(0, Color.white);
    renderer.setSeriesItemLabelsVisible(1, true);
    renderer.setSeriesItemLabelGenerator(1, new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelPaint(1, Color.white);
      */

    //setCategorySummary(dataset);

    //rotate labels on x-axis
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;

}

From source file:com.indicator_engine.controller.GraphController.java

private JFreeChart createBarChart(final CategoryDataset dataset, final String chartTitle) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            "Indicators", // domain axis label
            "Count", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from  ww  w . j  a  v a  2 s . c  o m*/

    // SOME OPTIONAL CUSTOMISATION OF THE CHART

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

    // get a reference to the plot for further customisation
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

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

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    return chart;

}

From source file:RDGraphGenerator.java

private JFreeChart createTimeChart(String riderID) {

    String riderName = (String) riders.get(riderID);
    final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Hours", // chart title
            "Month", // domain axis label
            "Hours", // range axis label
            (CategoryDataset) riderTimes.get(riderID), // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );/* ww w  . j av a 2 s .  c  o  m*/

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("0", "G1");
    map.mapKeyToGroup("1", "G1");
    map.mapKeyToGroup("2", "G1");
    map.mapKeyToGroup("3", "G1");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    CategoryAxis ca = plot.getDomainAxis();
    ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    //Make around the chart transparent.
    chart.setBackgroundPaint(null);
    return chart;

}