Example usage for org.jfree.chart.plot CategoryPlot setAxisOffset

List of usage examples for org.jfree.chart.plot CategoryPlot setAxisOffset

Introduction

In this page you can find the example usage for org.jfree.chart.plot CategoryPlot setAxisOffset.

Prototype

public void setAxisOffset(RectangleInsets offset) 

Source Link

Document

Sets the axis offsets (gap between the data area and the axes) and sends a PlotChangeEvent to all registered listeners.

Usage

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

public static JPanel createDemoPanel() {
    JFreeChart jfreechart = createChart("Axis Offsets: 0", createDataset());
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setMinimumDrawWidth(0);/*from ww  w. j av a2s.c  om*/
    chartpanel.setMinimumDrawHeight(0);
    JFreeChart jfreechart1 = createChart("Axis Offsets: 5", createDataset());
    ChartPanel chartpanel1 = new ChartPanel(jfreechart1);
    chartpanel1.setMinimumDrawWidth(0);
    chartpanel1.setMinimumDrawHeight(0);
    CategoryPlot categoryplot1 = (CategoryPlot) jfreechart1.getPlot();
    categoryplot1.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    DemoPanel demopanel = new DemoPanel(new GridLayout(2, 1));
    demopanel.add(chartpanel);
    demopanel.add(chartpanel1);
    demopanel.addChart(jfreechart);
    demopanel.addChart(jfreechart1);
    return demopanel;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createAreaChart("Area Chart", "Category", "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    TextTitle texttitle = new TextTitle(
            "An area chart demonstration.  We use this subtitle as an example of what happens when you get a really long title or subtitle.");
    texttitle.setFont(new Font("SansSerif", 0, 12));
    texttitle.setPosition(RectangleEdge.TOP);
    texttitle.setPadding(new RectangleInsets(UnitType.RELATIVE, 0.050000000000000003D, 0.050000000000000003D,
            0.050000000000000003D, 0.050000000000000003D));
    texttitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    jfreechart.addSubtitle(texttitle);//www .j a v  a  2s .  c  om
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setForegroundAlpha(0.5F);
    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 categoryaxis = categoryplot.getDomainAxis();
    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 numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLabelAngle(0.0D);
    return jfreechart;
}

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

private static JFreeChart createChart(int i, CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createStackedBarChart3D("Chart " + (i + 1), "Category", "Value",
            categorydataset, PlotOrientation.VERTICAL, false, false, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.getDomainAxis().setMaximumCategoryLabelLines(2);
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    ValueAxis valueaxis = categoryplot.getRangeAxis();
    valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:statistic.ca.gui.Charts.java

public static JFreeChart createBarChart(ChartData data) {
    if (data.getDiagramType().equals("bar")) {
        chart = ChartFactory.createBarChart(data.getTitle(), // Title
                data.getYAxisLabel(), // X-Axis label
                "", // Y-Axis label
                data.getCDataSet(), // CategoryDataset
                PlotOrientation.VERTICAL, false, true, false // Show legend
        );//from w w  w .j a va 2  s .  c  o m
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinePaint(Color.WHITE);
        plot.setRangeGridlinePaint(Color.WHITE);
        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    }

    if (data.getDiagramType().equals("pie")) {
        chart = ChartFactory.createPieChart(data.getTitle(), // Title
                data.getPieDataSet(), false, true, false);
    }

    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

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

private static JFreeChart createChart(String s, CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart(s, null, "Value", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setItemMargin(0.02D);/*w w w  . jav  a 2 s .  co  m*/
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category",
            "Cost Per Unit", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    ValueAxis valueaxis = categoryplot.getRangeAxis();
    DecimalFormat decimalformat = new DecimalFormat("##,###");
    decimalformat.setNegativePrefix("(");
    decimalformat.setNegativeSuffix(")");
    TickUnits tickunits = new TickUnits();
    tickunits.add(new NumberTickUnit(5D, decimalformat));
    tickunits.add(new NumberTickUnit(10D, decimalformat));
    tickunits.add(new NumberTickUnit(20D, decimalformat));
    tickunits.add(new NumberTickUnit(50D, decimalformat));
    tickunits.add(new NumberTickUnit(100D, decimalformat));
    tickunits.add(new NumberTickUnit(200D, decimalformat));
    tickunits.add(new NumberTickUnit(500D, decimalformat));
    tickunits.add(new NumberTickUnit(1000D, decimalformat));
    tickunits.add(new NumberTickUnit(2000D, decimalformat));
    tickunits.add(new NumberTickUnit(5000D, decimalformat));
    valueaxis.setStandardTickUnits(tickunits);
    BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setDrawBarOutline(false);
    barrenderer.setBase(5D);/*from   w w w .ja va  2  s.c om*/
    DecimalFormat decimalformat1 = new DecimalFormat("$##,###.00");
    decimalformat1.setNegativePrefix("(");
    decimalformat1.setNegativeSuffix(")");
    barrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
    barrenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

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);/* w  w  w.j a va  2s.  co m*/
    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:gui.statistic.JChartPanel.java

protected static JFreeChart createChart() {
    categoryDataset = new DefaultCategoryDataset();
    //categoryDataset.addValue(20, "", "A");
    //categoryDataset.addValue(35, "", "A");
    //categoryDataset.addValue(40, "", "B");
    //categoryDataset.addValue(60, "", "B");

    JFreeChart chart = ChartFactory.createBarChart("", // Title
            "Belegungen", // X-Axis label
            "Werte", // Y-Axis label
            categoryDataset, // Dataset
            PlotOrientation.VERTICAL, false, true, false // Show legend
    );//w  ww .j  ava2s  .c om

    chart.setBackgroundPaint(Color.WHITE);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    //plot.setDomainCrosshairVisible(true);
    //plot.setRangeCrosshairVisible(true);

    return chart;

}

From source file:service.chart.FitnessChart.java

/**
 * Utworz wykres funkcji fitness dla najlepszego osobnika w danej iteracji algorytmu genetycznego 
 * na podstawie zestawu danych/* ww w.j  a  va  2  s  .  com*/
 * 
 * @param categoryDataset Zestaw danych
 * @return Wykres funkcji fitness
 */
private static JFreeChart createChart(CategoryDataset categoryDataset) {

    JFreeChart chart = ChartFactory.createLineChart("Best fitness function value", // title
            "Iteration", // x-axis label
            "Fitness", // y-axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    CategoryItemRenderer r = plot.getRenderer();
    if (r instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer renderer = (LineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false);
        renderer.setBaseShapesFilled(true);
    }

    return chart;
}

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

private static JFreeChart createChart(MultiValueCategoryDataset multivaluecategorydataset) {
    CategoryPlot categoryplot = new CategoryPlot(multivaluecategorydataset, new CategoryAxis("Category"),
            new NumberAxis("Value"), new ScatterRenderer());
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart("ScatterRendererDemo1", categoryplot);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}