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

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

Introduction

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

Prototype

public void setLowerMargin(double margin) 

Source Link

Document

Sets the lower margin for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * DOC bZhou Comment method "decorateCategoryPlot".
 * /*from w ww .  j  a  va2s.  c om*/
 * @param chart
 */
public static void decorateCategoryPlot(JFreeChart chart, PlotOrientation orientation) {

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryItemRenderer render = plot.getRenderer();
    CategoryAxis domainAxis = plot.getDomainAxis();
    // ADD msjian TDQ-5111 2012-4-9: set something look it well
    domainAxis.setCategoryMargin(0.1);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);
    domainAxis.setCategoryLabelPositionOffset(10);
    // TDQ-5111~

    ValueAxis valueAxis = plot.getRangeAxis();

    Font font = new Font("Tahoma", Font.BOLD, BASE_ITEM_LABEL_SIZE);//$NON-NLS-1$

    render.setBaseItemLabelFont(font);
    // MOD zshen 10998: change the font name 2010-01-16
    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.BOLD, BASE_LABEL_SIZE);//$NON-NLS-1$
    valueAxis.setLabelFont(font);

    font = new Font("sans-serif", Font.PLAIN, BASE_TICK_LABEL_SIZE);//$NON-NLS-1$
    domainAxis.setTickLabelFont(font);
    valueAxis.setTickLabelFont(font);

    setLegendFont(chart);

    font = new Font("sans-serif", Font.BOLD, BASE_TITLE_LABEL_SIZE);//$NON-NLS-1$
    TextTitle title = chart.getTitle();
    if (title != null) {
        title.setFont(font);
    }

    font = null;

    if (render instanceof BarRenderer) {
        CategoryDataset dataset = chart.getCategoryPlot().getDataset();
        if (dataset != null) {
            int rowCount = dataset.getRowCount();
            List<?> columnKeys = dataset.getColumnKeys();
            if (!isContainCJKCharacter(columnKeys.toArray())) {
                domainAxis.setTickLabelFont(new Font("Tahoma", Font.PLAIN, 10));//$NON-NLS-1$
            }
            ((BarRenderer) render).setItemMargin(-0.40 * rowCount);

            // TDQ-12621 add Tooltip for Lable
            for (Object colKey : columnKeys) {
                domainAxis.addCategoryLabelToolTip(colKey.toString(), colKey.toString());
            }
        }
        domainAxis.setUpperMargin(0.1);
        // TDQ-12621 Only display in 1 line for the label, other chars will be displayed as "..."
        domainAxis.setMaximumCategoryLabelLines(1);

        // ADD msjian TDQ-5111 2012-4-9: set Bar Width and let it look well
        // not do this when the bar is horizontal Orientation
        if (orientation == null) {
            ((BarRenderer) render).setMaximumBarWidth(0.2);
        }
        // TDQ-5111~
    }
    // ~10998
}

From source file:org.operamasks.faces.render.graph.CurveAreaChartRenderer.java

private JFreeChart createCurveAreaChart(CategoryDataset dataset, PlotOrientation orientation) {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);/* w ww  . j  av  a 2  s  .com*/
    xAxis.setCategoryMargin(0.0);

    NumberAxis yAxis = new NumberAxis();
    yAxis.setAutoRangeIncludesZero(false);

    CurveAndShapeRenderer renderer = new CurveAndShapeRenderer(true, false);
    renderer.setDrawArea(true);

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (dataset.getRowCount() > 1) {
        plot.setForegroundAlpha(0.75f);
    }

    return new JFreeChart(null, null, plot, false);
}

From source file:org.shredzone.bullshitcharts.chart.BarChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());/*from w ww .  j a va 2s  .  c  o  m*/
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    BarRenderer3D renderer = new BarRenderer3D();

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

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

/**
 * Creates a new demo./*  w ww .j a v a  2 s.co  m*/
 *
 * @param title  the frame title.
 */
public BarChartDemo6(final String title) {

    super(title);

    // create a dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(83.0, "First", "Factor 1");

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            "Category", // domain axis label
            "Score (%)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.yellow); // not seen
    final CategoryPlot plot = chart.getCategoryPlot();
    //        plot.setInsets(new Insets(0, 0, 0, 0));
    plot.setRangeGridlinesVisible(false);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.20);
    domainAxis.setUpperMargin(0.20);
    domainAxis.setVisible(false);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0);
    rangeAxis.setVisible(false);
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.shredzone.bullshitcharts.chart.LineChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());/* w  w w  .  ja  v a2s.c om*/
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    LineAndShapeRenderer renderer = new LineRenderer3D();
    renderer.setBaseShapesVisible(false);
    //        renderer.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

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

/**
 * Creates a new demo.// w w w .  ja  v a 2s  .  com
 *
 * @param title  the frame title.
 */
public StatisticalBarChartDemo(final String title) {

    super(title);
    final StatisticalCategoryDataset dataset = createDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    xAxis.setLowerMargin(0.01d); // percentage of space before first bar
    xAxis.setUpperMargin(0.01d); // percentage of space after last bar
    xAxis.setCategoryMargin(0.05d); // percentage of space between categories
    final ValueAxis yAxis = new NumberAxis("Value");

    // define the plot
    final CategoryItemRenderer renderer = new StatisticalBarRenderer();
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart("Statistical Bar Chart Demo", new Font("Helvetica", Font.BOLD, 14),
            plot, true);
    //chart.setBackgroundPaint(Color.white);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.sonar.plugins.core.charts.DistributionAreaChart.java

@Override
protected Plot getPlot(ChartParameters params) {
    DefaultCategoryDataset dataset = createDataset(params);

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryMargin(0.0);/*from  w  ww  .  j  ava  2s  .co m*/
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance(params.getLocale()));
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    AreaRenderer renderer = new AreaRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    plot.setForegroundAlpha(0.5f);
    plot.setDomainGridlinesVisible(true);
    configureColors(dataset, plot, params.getValues(PARAM_COLORS, ","));
    return plot;
}

From source file:app.Histogram.java

public void histogramDesign(JFreeChart chart) {
    final CategoryPlot plot = chart.getCategoryPlot();
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();

    renderer.setDrawBarOutline(false);/*from   ww w  . j  a  v  a  2s  .  c  o m*/
    renderer.setItemMargin(0.10);
    renderer.setShadowVisible(false);

    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.black, 0.0f, 0.0f, Color.black);

    final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.02);
    domainAxis.setUpperMargin(0.02);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(1));

    renderer.setSeriesPaint(0, gp0);
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.black);
    plot.setRenderer(renderer);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(650, 500));

    JPanel panelJPanel = new JPanel();
    panelJPanel.removeAll();
    //panelJComboBox.removeAll();
    PlotWindow hist = new PlotWindow();
    hist.setVisible(true);
    // HistogtamWindow f = new HistogtamWindow();
    // HistogtamWindow f2 = f.getInstance();
    // f2.setVisible(true);
    // f2.getHistogramPanel().add(chartPanel);
    panelJPanel.add(chartPanel);
    hist.setContentPane(panelJPanel);
}

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

/**
 * Creates a sample chart.//from w ww  .  j a  v  a  2  s .  co m
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
public JFreeChart createChart(CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedAreaChart("Stacked Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(0.5f);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelsVisible(true);

    return chart;

}

From source file:org.aksw.iguana.reborn.charts.datasets.StatisticalBarChartDemo.java

/**
 * Creates a new demo.//from www  .j  a va  2  s  .  c om
 *
 * @param title
 *            the frame title.
 * @throws DocumentException
 * @throws FileNotFoundException
 */
public StatisticalBarChartDemo(final String title) throws FileNotFoundException, DocumentException {

    super(title);
    final StatisticalCategoryDataset dataset = createDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    xAxis.setLowerMargin(0.01d); // percentage of space before first bar
    xAxis.setUpperMargin(0.01d); // percentage of space after last bar
    xAxis.setCategoryMargin(0.05d); // percentage of space between
    // categories
    final ValueAxis yAxis = new NumberAxis("Value");

    // define the plot
    final CategoryItemRenderer renderer = new StatisticalBarRenderer();
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart("Statistical Bar Chart Demo", new Font("Helvetica", Font.BOLD, 14),
            plot, true);
    ChartUtilities2.saveChartAsPDF(new File("/home/raven/tmp/foo.pdf"), chart, 1000, 300);

    // chart.setBackgroundPaint(Color.white);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}