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

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

Introduction

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

Prototype

public void setMaximumCategoryLabelWidthRatio(float ratio) 

Source Link

Document

Sets the maximum category label width ratio and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createTopNBarChart(String yAxisLabel, CategoryDataset dataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(null, null, yAxisLabel, dataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    categoryplot.setBackgroundPaint(null);
    categoryplot.setOutlinePaint(null);//from   w  w  w  . ja v  a 2 s  .  c  om
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);

    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBarPainter(new StandardBarPainter());
    barrenderer.setShadowVisible(false);
    barrenderer.setItemMargin(0.015);
    barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE);
    barrenderer.setSeriesPaint(1, UIConstants.INTEL_LIGHT_BLUE);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryMargin(0.15D);
    categoryaxis.setUpperMargin(0.02D);
    categoryaxis.setLowerMargin(0.02D);
    categoryaxis.setMaximumCategoryLabelWidthRatio(0.5F);

    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setRangeType(RangeType.POSITIVE);
    numberaxis.setStandardTickUnits(createLargeNumberTickUnits());
    numberaxis.setUpperMargin(0.20000000000000001D);
    numberaxis.setLabelFont(UIConstants.H5_FONT);
    numberaxis.setLabelInsets(new RectangleInsets(0, 0, 0, 0));
    numberaxis.setTickMarksVisible(true);
    numberaxis.setTickLabelsVisible(true);

    LegendTitle legend = jfreechart.getLegend();
    legend.setFrame(BlockBorder.NONE);
    legend.setItemFont(barrenderer.getBaseItemLabelFont().deriveFont(10.0f));

    return jfreechart;
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createBarChart(String xAxisLabel, String yAxisLabel, CategoryDataset dataset) {
    if (dataset == null) {
        throw new IllegalArgumentException("No dataset.");
    }/*from  w  ww.ja  v a 2  s  .c  om*/

    JFreeChart jfreechart = ChartFactory.createBarChart(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    categoryplot.setBackgroundPaint(null);
    categoryplot.setOutlinePaint(null);
    categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    categoryplot.setRangePannable(true);
    categoryplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY);
    categoryplot.getRangeAxis().setLabelFont(UIConstants.H5_FONT);
    categoryplot.getDomainAxis().setLabelFont(UIConstants.H5_FONT);

    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBarPainter(new StandardBarPainter());
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setShadowVisible(false);
    barrenderer.setSeriesPaint(0, UIConstants.INTEL_BLUE);

    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryMargin(0.02D);
    categoryaxis.setUpperMargin(0.01D);
    categoryaxis.setLowerMargin(0.01D);
    // categoryaxis.setAxisLineVisible(false);
    categoryaxis.setMaximumCategoryLabelWidthRatio(0.95F);

    NumberAxis axis = (NumberAxis) categoryplot.getRangeAxis();
    axis.setRangeType(RangeType.POSITIVE);

    return jfreechart;
}

From source file:netmason.support.graphics.GanttDisplay.java

public GanttDisplay(String title) {

    super(title);

    collection.add(s1);/*from   www  .j  ava  2s. c om*/

    // create the chart...
    chart = ChartFactory.createGanttChart("Gantt Chart", // chart title
            "Agent", // domain axis label
            "Date", // range axis label
            collection, // data
            false, // include legend
            true, // tooltips
            false // urls
    );

    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    plot.setDomainGridlinePosition(CategoryAnchor.START);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelPaint(Color.blue);
    domainAxis.setAxisLineVisible(false);

    domainAxis.setCategoryLabelPositionOffset(0);
    domainAxis.setMaximumCategoryLabelLines(2);
    domainAxis.setMaximumCategoryLabelWidthRatio(0.3f);

    renderer.setSeriesPaint(0, Color.blue);

    // add the chart to a panel...
    ChartPanel chartPanel = new ChartPanel(chart);
    setContentPane(chartPanel);

}

From source file:com.xpn.xwiki.plugin.charts.ChartCustomizer.java

public static void customizeCategoryAxis(CategoryAxis axis, ChartParams params, String prefix) {
    customizeAxis(axis, params, prefix);

    if (params.get(prefix + ChartParams.CATEGORY_AXIS_CATEGORY_MARGIN_SUFFIX) != null) {
        axis.setCategoryMargin(/* w w w . jav  a2s  .  c  o  m*/
                params.getDouble(prefix + ChartParams.CATEGORY_AXIS_CATEGORY_MARGIN_SUFFIX).doubleValue());
    }
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITIONS_SUFFIX) != null) {
        axis.setCategoryLabelPositions(
                params.getCategoryLabelPositions(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITIONS_SUFFIX));
    }
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITION_OFFSET_SUFFIX) != null) {
        axis.setCategoryLabelPositionOffset(
                params.getInteger(prefix + ChartParams.CATEGORY_AXIS_LABEL_POSITION_OFFSET_SUFFIX).intValue());
    }
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_LINES_SUFFIX) != null) {
        axis.setMaximumCategoryLabelLines(
                params.getInteger(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_LINES_SUFFIX).intValue());
    }
    if (params.get(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_WIDTH_RATIO_SUFFIX) != null) {
        axis.setMaximumCategoryLabelWidthRatio(params
                .getFloat(prefix + ChartParams.CATEGORY_AXIS_MAXIMUM_LABEL_WIDTH_RATIO_SUFFIX).floatValue());
    }
}

From source file:com.devoteam.srit.xmlloader.core.report.derived.DerivedCounter.java

public JFreeChart getHistogramChart() {

    double[] hits = this.counter.histogramDataset.getHistogramArray();
    double[] intervals = this.counter.histogramDataset.histogramParameters.histogramIntervals;
    double hitsCount = this.counter.histogramDataset.hits;
    DefaultCategoryDataset datasetNormal = new DefaultCategoryDataset();

    datasetNormal.addValue(0, "a", "          -INF");
    datasetNormal.addValue(0, "b", "          -INF");

    double cumul = 0;
    for (int i = 0; i < intervals.length - 1; i++) {
        String intervalName;/*  w  ww  .j  a v a  2 s  .  c o  m*/

        if (i == intervals.length - 2) {
            intervalName = "          +INF";
        } else {
            intervalName = "          " + Double.toString(intervals[i + 1]);
        }

        cumul += hits[i];
        datasetNormal.addValue((100 * hits[i]) / hitsCount, "a", intervalName);
        datasetNormal.addValue((100 * cumul) / hitsCount, "b", intervalName);
    }

    JFreeChart jFreeChart = ChartFactory.createBarChart("", "", "%", datasetNormal, PlotOrientation.VERTICAL,
            false, false, false);

    CategoryPlot plot = jFreeChart.getCategoryPlot();
    CategoryAxis axis = plot.getDomainAxis();
    LayeredBarRenderer layeredBarRenderer = new LayeredBarRenderer();
    layeredBarRenderer.setSeriesPaint(0, new Color(0, 0, 255, 85));
    layeredBarRenderer.setSeriesPaint(1, new Color(255, 0, 0, 85));
    plot.setRenderer(layeredBarRenderer);

    plot.setRowRenderingOrder(SortOrder.DESCENDING);
    axis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    axis.setMaximumCategoryLabelWidthRatio(1);

    jFreeChart.setBackgroundPaint(Color.WHITE);
    return jFreeChart;

}

From source file:com.manydesigns.portofino.chart.Chart2DGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);//ww w  .j  a  va2s  .  c  o m
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper x = new ComparableWrapper((Comparable) current[0]);
        ComparableWrapper y = new ComparableWrapper((Comparable) current[1]);
        if (current.length > 3) {
            x.setLabel(current[3].toString());
        }
        if (current.length > 4) {
            y.setLabel(current[4].toString());
        }
        dataset.setValue((Number) current[2], x, y);
    }

    PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL;
    if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) {
        plotOrientation = PlotOrientation.VERTICAL;
    }

    JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation);

    chart.setAntiAlias(antiAlias);

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(borderVisible);

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression());
        renderer.setBaseItemURLGenerator(urlGenerator);
    } else {
        renderer.setBaseItemURLGenerator(null);
    }
    renderer.setBaseOutlinePaint(Color.BLACK);

    // ///////////////
    if (renderer instanceof BarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;

        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());
    }
    // ///////////////

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})"));

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // Category axis
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setAxisLinePaint(Color.BLACK);
    categoryAxis.setLabelFont(axisFont);
    categoryAxis.setAxisLineVisible(true);

    // impostiamo la rotazione dell'etichetta
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT,
                TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0,
                CategoryLabelWidthType.CATEGORY, 100);
        CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos);
        categoryAxis.setCategoryLabelPositions(positions);
        categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f);
        height = 333;
    } else {
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f);

        // recuperiamo 8 pixel a sinistra
        plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0));

        height = 74;

        // contiamo gli elementi nel dataset
        height += 23 * dataset.getColumnCount();

        height += 57;
    }

    Axis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAxisLinePaint(Color.BLACK);
    rangeAxis.setLabelFont(axisFont);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);
    // ?
    plot.setForegroundAlpha(1.0f);
    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:com.manydesigns.portofino.chart.ChartBarGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);/*from   w ww  .  ja v a2s .  co  m*/
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper x = new ComparableWrapper((Comparable) current[0]);
        ComparableWrapper y = new ComparableWrapper((Comparable) current[1]);
        if (current.length > 3) {
            x.setLabel(current[3].toString());
        }
        if (current.length > 4) {
            y.setLabel(current[4].toString());
        }
        dataset.setValue((Number) current[2], x, y);
    }

    PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL;
    if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) {
        plotOrientation = PlotOrientation.VERTICAL;
    }

    JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation);

    chart.setAntiAlias(antiAlias);

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(borderVisible);

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression());
        renderer.setBaseItemURLGenerator(urlGenerator);
    } else {
        renderer.setBaseItemURLGenerator(null);
    }
    renderer.setBaseOutlinePaint(Color.BLACK);

    // ///////////////
    if (renderer instanceof BarRenderer || renderer instanceof BarRenderer3D) {
        BarRenderer barRenderer = (BarRenderer) renderer;

        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        barRenderer.setBaseItemLabelsVisible(true);
        // ? setSeriesItemLabelGenerator
        barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.05);
        // ?????
        // ??90,??/3.14
        ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D);
        // ??labelposition
        // barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
        // barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);

        barRenderer.setItemLabelsVisible(true);

        // ?
        barRenderer.setBaseOutlinePaint(Color.BLACK);
        // ???
        barRenderer.setDrawBarOutline(true);

        // ???
        barRenderer.setItemMargin(0.0);

        // ?
        barRenderer.setIncludeBaseInRange(true);
        barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        barRenderer.setBaseItemLabelsVisible(true);
        // ?
        plot.setForegroundAlpha(1.0f);
    }

    // ///////////////

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})"));

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // Category axis
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setAxisLinePaint(Color.BLACK);
    categoryAxis.setLabelFont(axisFont);
    categoryAxis.setAxisLineVisible(true);

    // impostiamo la rotazione dell'etichetta
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT,
                TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0,
                CategoryLabelWidthType.CATEGORY, 100);
        CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos);
        categoryAxis.setCategoryLabelPositions(positions);
        categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f);
        height = 333;
    } else {
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f);

        // recuperiamo 8 pixel a sinistra
        plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0));

        height = 74;

        // contiamo gli elementi nel dataset
        height += 23 * dataset.getColumnCount();

        height += 57;
    }

    Axis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAxisLinePaint(Color.BLACK);
    rangeAxis.setLabelFont(axisFont);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);

    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

From source file:com.manydesigns.portofino.chart.ChartStackedBarGenerator.java

public JFreeChart generate(ChartDefinition chartDefinition, Persistence persistence, Locale locale) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    java.util.List<Object[]> result;
    String query = chartDefinition.getQuery();
    logger.info(query);/*from  w  w w . j a v  a 2s  . co m*/
    Session session = persistence.getSession(chartDefinition.getDatabase());
    result = QueryUtils.runSql(session, query);
    for (Object[] current : result) {
        ComparableWrapper x = new ComparableWrapper((Comparable) current[0]);
        ComparableWrapper y = new ComparableWrapper((Comparable) current[1]);
        if (current.length > 3) {
            x.setLabel(current[3].toString());
        }
        if (current.length > 4) {
            y.setLabel(current[4].toString());
        }
        dataset.setValue((Number) current[2], x, y);
    }

    PlotOrientation plotOrientation = PlotOrientation.HORIZONTAL;
    if (chartDefinition.getActualOrientation() == ChartDefinition.Orientation.VERTICAL) {
        plotOrientation = PlotOrientation.VERTICAL;
    }

    JFreeChart chart = createChart(chartDefinition, dataset, plotOrientation);

    chart.setAntiAlias(antiAlias);

    // impostiamo il bordo invisibile
    // eventualmente e' il css a fornirne uno
    chart.setBorderVisible(borderVisible);

    // impostiamo il titolo
    TextTitle title = chart.getTitle();
    title.setFont(titleFont);
    title.setMargin(10.0, 0.0, 0.0, 0.0);

    // ottieni il Plot
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    CategoryItemRenderer renderer = plot.getRenderer();
    String urlExpression = chartDefinition.getUrlExpression();
    if (!StringUtils.isBlank(urlExpression)) {
        CategoryURLGenerator urlGenerator = new ChartBarUrlGenerator(chartDefinition.getUrlExpression());
        renderer.setBaseItemURLGenerator(urlGenerator);
    } else {
        renderer.setBaseItemURLGenerator(null);
    }
    renderer.setBaseOutlinePaint(Color.BLACK);

    // ///////////////
    if (renderer instanceof BarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;

        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        // ?
        barRenderer.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.06);
    }
    if (renderer instanceof StackedBarRenderer3D || renderer instanceof StackedBarRenderer) {
        BarRenderer barRenderer = (BarRenderer) renderer;
        barRenderer.setDrawBarOutline(true);
        barRenderer.setShadowVisible(false);
        barRenderer.setBarPainter(new StandardBarPainter());

        // hongliangpan add
        // ? setSeriesItemLabelGenerator
        barRenderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        // bar???
        barRenderer.setMinimumBarLength(0.02);
        // 
        barRenderer.setMaximumBarWidth(0.06);
        // ?????
        ItemLabelPosition itemLabelPositionFallback = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                TextAnchor.BASELINE_LEFT, TextAnchor.HALF_ASCENT_LEFT, -1.57D);
        // ??labelposition
        barRenderer.setPositiveItemLabelPositionFallback(itemLabelPositionFallback);
        barRenderer.setNegativeItemLabelPositionFallback(itemLabelPositionFallback);

        barRenderer.setItemLabelsVisible(true);
        barRenderer.setItemMargin(10);
    }

    // ///////////////

    // il plot ha sfondo e bordo trasparente
    // (quindi si vede il colore del chart)
    plot.setBackgroundPaint(transparentColor);
    plot.setOutlinePaint(transparentColor);

    // Modifico il toolTip
    // plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} ({2})"));

    // imposta il messaggio se non ci sono dati
    plot.setNoDataMessage(ElementsThreadLocals.getText("no.data.available"));
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);
    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

    // Category axis
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setAxisLinePaint(Color.BLACK);
    categoryAxis.setLabelFont(axisFont);
    categoryAxis.setAxisLineVisible(true);

    // impostiamo la rotazione dell'etichetta
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        CategoryLabelPosition pos = new CategoryLabelPosition(RectangleAnchor.TOP_LEFT,
                TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 4.0,
                CategoryLabelWidthType.CATEGORY, 100);
        CategoryLabelPositions positions = new CategoryLabelPositions(pos, pos, pos, pos);
        categoryAxis.setCategoryLabelPositions(positions);
        categoryAxis.setMaximumCategoryLabelWidthRatio(6.0f);
        height = 333;
    } else {
        categoryAxis.setMaximumCategoryLabelWidthRatio(0.4f);

        // recuperiamo 8 pixel a sinistra
        plot.setInsets(new RectangleInsets(4.0, 0.0, 4.0, 8.0));

        height = 74;

        // contiamo gli elementi nel dataset
        height += 23 * dataset.getColumnCount();

        height += 57;
    }

    Axis rangeAxis = plot.getRangeAxis();
    rangeAxis.setAxisLinePaint(Color.BLACK);
    rangeAxis.setLabelFont(axisFont);

    DrawingSupplier supplier = new DesaturatedDrawingSupplier(plot.getDrawingSupplier());
    plot.setDrawingSupplier(supplier);

    // impostiamo il titolo della legenda
    String legendString = chartDefinition.getLegend();
    Title subtitle = new TextTitle(legendString, legendFont, Color.BLACK, RectangleEdge.BOTTOM,
            HorizontalAlignment.CENTER, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));
    subtitle.setMargin(0, 0, 5, 0);
    chart.addSubtitle(subtitle);

    // impostiamo la legenda
    LegendTitle legend = chart.getLegend();
    legend.setBorder(0, 0, 0, 0);
    legend.setItemFont(legendItemFont);
    int legendMargin = 10;
    legend.setMargin(0.0, legendMargin, legendMargin, legendMargin);
    legend.setBackgroundPaint(transparentColor);

    // impostiamo un gradiente orizzontale
    Paint chartBgPaint = new GradientPaint(0, 0, new Color(255, 253, 240), 0, height, Color.WHITE);
    chart.setBackgroundPaint(chartBgPaint);
    return chart;
}

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

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final CategoryPlot cpl = chart.getCategoryPlot();
    final CategoryItemRenderer renderer = cpl.getRenderer();
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        renderer.setBaseToolTipGenerator(
                new FormulaCategoryTooltipGenerator(getRuntime(), getTooltipFormula()));
    }/*from  w w w  . ja  v  a 2s.c o  m*/
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        renderer.setBaseItemURLGenerator(new FormulaCategoryURLGenerator(getRuntime(), getUrlFormula()));
    }
    if (this.categoricalLabelFormat != null) {
        final StandardCategoryItemLabelGenerator scilg;
        if (categoricalLabelDecimalFormat != null) {
            final DecimalFormat numFormat = new DecimalFormat(categoricalLabelDecimalFormat,
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            numFormat.setRoundingMode(RoundingMode.HALF_UP);
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, numFormat);
        } else if (categoricalLabelDateFormat != null) {
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, new SimpleDateFormat(
                    categoricalLabelDateFormat, getRuntime().getResourceBundleFactory().getLocale()));
        } else {
            final DecimalFormat formatter = new DecimalFormat();
            formatter.setDecimalFormatSymbols(
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, formatter);
        }
        renderer.setBaseItemLabelGenerator(scilg);
    }
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null) {
        renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    if (categoricalItemLabelRotation != null) {
        final ItemLabelPosition orgPosItemLabelPos = renderer.getBasePositiveItemLabelPosition();
        if (orgPosItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition pos2 = new ItemLabelPosition(orgPosItemLabelPos.getItemLabelAnchor(),
                    orgPosItemLabelPos.getTextAnchor(), orgPosItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        }

        final ItemLabelPosition orgNegItemLabelPos = renderer.getBaseNegativeItemLabelPosition();
        if (orgNegItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition neg2 = new ItemLabelPosition(orgNegItemLabelPos.getItemLabelAnchor(),
                    orgNegItemLabelPos.getTextAnchor(), orgNegItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(neg2);
        }
    }

    final Font labelFont = Font.decode(getLabelFont());

    final CategoryAxis categoryAxis = cpl.getDomainAxis();
    categoryAxis.setLabelFont(labelFont);
    categoryAxis.setTickLabelFont(labelFont);
    if (getCategoryTitleFont() != null) {
        categoryAxis.setLabelFont(getCategoryTitleFont());
    }
    if (getCategoryTickFont() != null) {
        categoryAxis.setTickLabelFont(getCategoryTickFont());
    }

    if (maxCategoryLabelWidthRatio != null) {
        categoryAxis.setMaximumCategoryLabelWidthRatio(maxCategoryLabelWidthRatio.floatValue());
    }
    cpl.setDomainGridlinesVisible(showGridlines);
    if (labelRotation != null) {
        double angle = labelRotation.doubleValue();
        CategoryLabelPosition top = createUpRotationCategoryLabelPosition(PlaneDirection.TOP, angle);
        CategoryLabelPosition bottom = createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, angle);
        CategoryLabelPosition left = createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, angle);
        CategoryLabelPosition right = createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, angle);
        CategoryLabelPositions rotationLabelPositions = new CategoryLabelPositions(top, bottom, left, right);
        categoryAxis.setCategoryLabelPositions(rotationLabelPositions);
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }

    if (lowerMargin != null) {
        categoryAxis.setLowerMargin(lowerMargin.doubleValue());
    }
    if (upperMargin != null) {
        categoryAxis.setUpperMargin(upperMargin.doubleValue());
    }
    if (categoryMargin != null) {
        categoryAxis.setCategoryMargin(categoryMargin.doubleValue());
    }

    configureRangeAxis(cpl, labelFont);
}

From source file:lucee.runtime.tag.Chart.java

private void setLabelFormat(JFreeChart chart) {
    Plot plot = chart.getPlot();/* w  ww .j a  va2 s  .  co  m*/
    if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        rangeAxis.setAutoTickUnitSelection(true);
        rangeAxis.setStandardTickUnits(new TickUnitsImpl(rangeAxis.getStandardTickUnits(), labelFormat));
        CategoryItemRenderer r = cp.getRenderer();
        r.setBaseItemLabelsVisible(false);

        CategoryAxis da = cp.getDomainAxis();
        if (!showXLabel)
            da.setTickLabelsVisible(false);
        da.setCategoryLabelPositions(labelPosition);
        da.setMaximumCategoryLabelWidthRatio(100);
        //da.setVisible(false);
    }
    if (plot instanceof XYPlot) {
        XYPlot cp = (XYPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        rangeAxis.setAutoTickUnitSelection(true);
        rangeAxis.setStandardTickUnits(new TickUnitsImpl(rangeAxis.getStandardTickUnits(), labelFormat));
        XYItemRenderer r = cp.getRenderer();
        r.setBaseItemLabelsVisible(false);
        ValueAxis da = cp.getDomainAxis();
        if (!_plotItemLables.isEmpty()) {
            _plotItemLables.add(0, "");
            String[] cols = _plotItemLables.toArray(new String[_plotItemLables.size()]);
            SymbolAxis sa = new SymbolAxis(da.getLabel(), cols);
            sa.setRange(da.getRange());
            if (labelPosition == LABEL_VERTICAL) {
                sa.setVerticalTickLabels(true);
            }
            cp.setDomainAxis(sa);
        }
        if (!showXLabel)
            cp.getDomainAxis().setTickLabelsVisible(false);
        //da.setVisible(false);
    }
}