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:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * Creates a JFreeChart based on the current query results produced by the
 * given chart.//from   w  w w  .ja v  a  2 s .com
 * 
 * @param c
 *            The chart from which to produce a JFreeChart component. Must
 *            not be null.
 * @return A chart based on the data and settings in the given chart, or
 *         null if the given chart is not sufficiently configured (for
 *         example, if its type is not set) or it is currently unable to
 *         produce a result set.
 */
public static JFreeChart createChartFromQuery(Chart c)
        throws SQLException, QueryInitializationException, InterruptedException {
    logger.debug("Creating JFreeChart for Wabit chart " + c);
    ChartType chartType = c.getType();

    if (chartType == null) {
        logger.debug("Returning null (chart's type is not set)");
        return null;
    }

    final JFreeChart chart;
    if (chartType.getDatasetType().equals(DatasetType.CATEGORY)) {

        JFreeChart categoryChart = createCategoryChart(c);
        logger.debug("Made a new category chart: " + categoryChart);

        if (categoryChart != null && categoryChart.getPlot() instanceof CategoryPlot) {

            double rotationRads = Math.toRadians(c.getXAxisLabelRotation());
            CategoryLabelPositions clp;
            if (Math.abs(rotationRads) < 0.05) {
                clp = CategoryLabelPositions.STANDARD;
            } else if (rotationRads < 0) {
                clp = CategoryLabelPositions.createUpRotationLabelPositions(-rotationRads);
            } else {
                clp = CategoryLabelPositions.createDownRotationLabelPositions(rotationRads);
            }

            CategoryAxis domainAxis = categoryChart.getCategoryPlot().getDomainAxis();
            domainAxis.setMaximumCategoryLabelLines(5);
            domainAxis.setCategoryLabelPositions(clp);
        }

        chart = categoryChart;

    } else if (chartType.getDatasetType().equals(DatasetType.XY)) {

        JFreeChart xyChart = createXYChart(c);
        logger.debug("Made a new XY chart: " + xyChart);
        chart = xyChart;

    } else {

        throw new IllegalStateException("Unknown chart dataset type " + chartType.getDatasetType());

    }

    if (chart != null) {
        makeChartNice(chart);
    }

    return chart;
}

From source file:org.jfree.chart.demo.CategoryStepChartDemo1.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    CategoryStepRenderer categorysteprenderer = new CategoryStepRenderer(true);
    categorysteprenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryAxis categoryaxis = new CategoryAxis("Category");
    NumberAxis numberaxis = new NumberAxis("Value");
    CategoryPlot categoryplot = new CategoryPlot(categorydataset, categoryaxis, numberaxis,
            categorysteprenderer);//from   ww  w. java 2s.  c  om
    JFreeChart jfreechart = new JFreeChart("Category Step Chart", categoryplot);
    jfreechart.setBackgroundPaint(Color.white);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    categoryaxis.setLowerMargin(0.0D);
    categoryaxis.setUpperMargin(0.0D);
    categoryaxis.addCategoryLabelToolTip("Type 1", "The first type.");
    categoryaxis.addCategoryLabelToolTip("Type 2", "The second type.");
    categoryaxis.addCategoryLabelToolTip("Type 3", "The third type.");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLabelAngle(0.0D);
    return jfreechart;
}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of a Comparative Response Model
 * Histogram./*from   w  w w .  j  a  va2 s  .com*/
 * 
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param dataBefore
 *          The array of values before the response.
 * @param dataAfter
 *          The array of values after the response.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createDailyResponseHistogram(String title, String x, String y, double[] dataBefore,
        double[] dataAfter) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < dataBefore.length; i++) {
        dataset.addValue(dataBefore[i], "Basic Scheme", "" + i + "");
        if (i < dataAfter.length)
            dataset.addValue(dataAfter[i], "New Scheme", "" + i + "");
        else
            dataset.addValue(0, "New Scheme", "" + i + "");
    }

    JFreeChart chart = ChartFactory.createBarChart3D(title, // chart title
            x, // domain axis label
            y, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();

    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    return new ChartPanel(chart);
}

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(//  www .  j  av a 2  s. co 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:Reportes.ChartCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2));
}

From source file:edu.esprit.pi.workshop.statistiques.BarChart.java

@Override
public JFreeChart construireChart2D() {
    graphe = ChartFactory.createBarChart("Pourcentage revenue par Dpartement", "Departement",
            "Pourcentage du revenu", createDataset(), PlotOrientation.VERTICAL, true, true, true);
    final CategoryPlot plot = graphe.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    return graphe;
}

From source file:edu.esprit.pi.workshop.statistiques.BarChart.java

@Override
public JFreeChart construireChart3D() {
    graphe = ChartFactory.createBarChart3D("Pourcentage revenue par Dpartement", "", "Pourcentage du revenu",
            createDataset(), PlotOrientation.HORIZONTAL, true, true, true);
    final CategoryPlot plot = graphe.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0));
    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    return graphe;
}

From source file:graph.GraphCreater.java

public GraphCreater(String applicationTitle, String chartTitle, ArrayList<String> resultList,
        ArrayList<String> dateList) {
    super(applicationTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Testing date",
            "Sugar level - units(mg/dL)", createDataset(resultList, dateList), PlotOrientation.VERTICAL, true,
            true, false);//  www. j  a  v  a2  s  .c o  m

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    setContentPane(chartPanel);
    final CategoryPlot plot = (CategoryPlot) lineChart.getPlot();
    CategoryAxis catAxis = plot.getDomainAxis();
    catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

}

From source file:net.neurowork.cenatic.centraldir.model.graphs.BarchartGraphCreator.java

@Override
public JFreeChart createGraphChart(String title, String yAxis, Dataset data) {
    PlotOrientation orientation = PlotOrientation.VERTICAL;

    JFreeChart chart = ChartFactory.createBarChart(title, "", // x-axis label
            yAxis, // y-axis label
            (CategoryDataset) data, orientation, false, // legend displayed
            true, // tooltips displayed
            false); // no URLs*/

    CategoryPlot categoryPlot = chart.getCategoryPlot();
    CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    return chart;
}

From source file:brightwell.gui.drawingplane.Chart3D.java

private JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart3D("Centrality", "Neuron", "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
    CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
    categoryitemrenderer.setItemLabelsVisible(true);
    BarRenderer barrenderer = (BarRenderer) categoryitemrenderer;
    barrenderer.setMaxBarWidth(0.050000000000000003D);
    return jfreechart;
}