Example usage for org.jfree.chart.axis CategoryLabelPositions createUpRotationLabelPositions

List of usage examples for org.jfree.chart.axis CategoryLabelPositions createUpRotationLabelPositions

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryLabelPositions createUpRotationLabelPositions.

Prototype

public static CategoryLabelPositions createUpRotationLabelPositions(double angle) 

Source Link

Document

Creates a new instance where the category labels angled upwards by the specified amount.

Usage

From source file:j2se.jfreechart.barchart.BarChart3DDemo1.java

/**
 * Creates a chart.//  w w w . j a v a  2s  .  c  o m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));
    final BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    return chart;

}

From source file:org.eevolution.form.CRPDetail.java

/**
 * Create Chart based on UOM//from   ww  w.ja  va2  s.  c  om
 * 
 * @param dataset
 * @param title
 * @param uom
 * @return JFreeChart Chart based On UOM
 */
public JFreeChart createChart(CategoryDataset dataset, String title, MUOM uom) {

    JFreeChart chart = ChartFactory.createBarChart3D(title, Msg.translate(Env.getCtx(), "Day"), // X-Axis label
            Msg.translate(Env.getCtx(), (uom == null) ? "" : uom.getName()), // Y-Axis
            // label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(Color.WHITE);
    chart.setAntiAlias(true);
    chart.setBorderVisible(true);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.GRAY);

    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.GRAY);

    BarRenderer3D barrenderer = (BarRenderer3D) plot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBaseItemLabelGenerator(new LabelGenerator());
    barrenderer.setBaseItemLabelsVisible(true);
    barrenderer.setSeriesPaint(0, new Color(10, 80, 150, 128));
    barrenderer.setSeriesPaint(1, new Color(180, 60, 50, 128));

    ItemLabelPosition itemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
            TextAnchor.TOP_CENTER);
    barrenderer.setPositiveItemLabelPosition(itemlabelposition);

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

From source file:graficos.GraficoBarras.java

private static JFreeChart crearGrafico(CategoryDataset cjto_datos) {
    JFreeChart grafico = ChartFactory.createBarChart3D("Distribucin de Recursos", // Ttulo
            "Unidad de tiempo", // Ttulo eje x
            "Recurso", // Ttulo eje y
            cjto_datos, // Datos
            PlotOrientation.VERTICAL, // Orientacin
            true, // Incluir leyenda
            true, // Incluir tooltips
            false // Incluir URLs
    );/*w w w  .ja v a  2 s  .  co m*/
    grafico.setBackgroundPaint(new Color(240, 240, 240));
    grafico.getPlot().zoom(0.0);
    CategoryPlot ploter = (CategoryPlot) grafico.getPlot();
    NumberAxis3D rangeAxis = (NumberAxis3D) ploter.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis3D.createIntegerTickUnits());
    BarRenderer3D renderer = (BarRenderer3D) ploter.getRenderer();
    renderer.setDrawBarOutline(false);
    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));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setItemMargin(0.0);
    CategoryAxis domainAxis = ploter.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.0));
    return grafico;
}

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

@Override
protected JFreeChart createChart() {
    BarChartView chartView = (BarChartView) 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();

    // TODO Make plot orientation a style property

    JFreeChart chart;//from   www .  j  a va2s .c  o  m
    ChartView.CategorySequence categories = chartView.getCategories();
    if (categories.getLength() > 0) {
        CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

        if (stacked && threeDimensional) {
            chart = ChartFactory.createStackedBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (stacked) {
            chart = ChartFactory.createStackedBarChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (threeDimensional) {
            chart = ChartFactory.createBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else {
            chart = ChartFactory.createBarChart(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);
    } else {
        // TODO Make the dateAxis argument a style property
        chart = ChartFactory.createXYBarChart(title, horizontalAxisLabel, false, verticalAxisLabel,
                new IntervalSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend,
                false, false);
    }

    return chart;
}

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

public static JPanel createDemoPanel() {
    CategoryDataset categorydataset = createDataset();
    chart = createChart(categorydataset);
    JPanel jpanel = new JPanel(new BorderLayout());
    JPanel jpanel1 = new JPanel(new BorderLayout());
    JPanel jpanel2 = new JPanel();
    invertCheckBox = new JCheckBox("Invert Range Axis?");
    invertCheckBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
            categoryplot.getRangeAxis().setInverted(CategoryLabelPositionsDemo1.invertCheckBox.isSelected());
        }/*from   w  w  w  .j  a  v a2 s. c o  m*/

    });
    jpanel2.add(invertCheckBox);
    ButtonGroup buttongroup = new ButtonGroup();
    horizontalRadioButton = new JRadioButton("Horizontal", false);
    horizontalRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            if (CategoryLabelPositionsDemo1.horizontalRadioButton.isSelected()) {
                CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
                categoryplot.setOrientation(PlotOrientation.HORIZONTAL);
            }
        }

    });
    buttongroup.add(horizontalRadioButton);
    verticalRadioButton = new JRadioButton("Vertical", true);
    verticalRadioButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionevent) {
            if (CategoryLabelPositionsDemo1.verticalRadioButton.isSelected()) {
                CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
                categoryplot.setOrientation(PlotOrientation.VERTICAL);
            }
        }

    });
    buttongroup.add(verticalRadioButton);
    jpanel2.add(horizontalRadioButton);
    jpanel2.add(verticalRadioButton);
    jpanel2.setBorder(new TitledBorder("Plot Settings: "));
    JPanel jpanel3 = new JPanel(new BorderLayout());
    slider = new JSlider(0, 90, 45);
    slider.setMajorTickSpacing(10);
    slider.setMinorTickSpacing(5);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent changeevent) {
            CategoryPlot categoryplot = (CategoryPlot) CategoryLabelPositionsDemo1.chart.getPlot();
            CategoryAxis categoryaxis = categoryplot.getDomainAxis();
            categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(
                    ((double) CategoryLabelPositionsDemo1.slider.getValue() * 3.1415926535897931D) / 180D));
        }

    });
    jpanel3.add(slider);
    jpanel3.setBorder(new TitledBorder("Axis Label Rotation Angle:"));
    jpanel1.add("North", jpanel2);
    jpanel1.add(jpanel3);
    jpanel.add(new ChartPanel(chart));
    jpanel.add("South", jpanel1);
    return jpanel;
}

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * Creates a JFreeChart based on the current query results produced by the
 * given chart.//  w w  w .  ja  va2s. c o m
 * 
 * @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:com.thingsfx.swing.jfreechart.JFreeChartPanel2.java

void initComponents() {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("JFreeChart is Definitely cool!", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            createDataset(), // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//w w w.j  a  va  2s  . c o  m

    // 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 = (CategoryPlot) chart.getPlot();

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    // 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);

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

    add(new ChartPanel(chart));
}

From source file:net.sourceforge.subsonic.controller.UserChartController.java

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false,
            false, false);/* w  w  w  . j a  v  a  2s .  c om*/

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

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

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}

From source file:graphs.LimitsGraphs.java

/**
 * Creates a sample chart.//from  w w  w .  j a  v a2 s .c om
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Limits ..", // chart title
            "Metric", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // 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...
    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));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * Creates a chart./*from  w  w w .java2  s  .c  o m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createBarChart3D("3D Bar Chart Demo", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0));

    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    final BarRenderer r = (BarRenderer) renderer;
    r.setMaxBarWidth(0.05);

    return chart;

}