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

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

Introduction

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

Prototype

public void setLabelFont(Font font) 

Source Link

Document

Sets the font for the axis label and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:com.ohalo.cn.awt.JFreeChartTest2.java

public static JFreeChart createChart(CategoryDataset dataset) // ?
{
    JFreeChart chart = ChartFactory.createBarChart("hi", "", "?", dataset,
            PlotOrientation.VERTICAL, true, true, false); // JFreeChart
    chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20)));// ???hi?
    CategoryPlot plot = (CategoryPlot) chart.getPlot();// ?plot
    CategoryAxis categoryAxis = plot.getDomainAxis();// ??
    categoryAxis.setLabelFont(new Font("", Font.BOLD, 12));// ??
    return chart;
}

From source file:com.ouc.cpss.view.EmpSaleChartBuilder.java

private static JFreeChart createJFreeChart(CategoryDataset dataset) {
    /**//from w w w  . j a  v a  2 s.  co m
     * JFreeChart
     */
    //?     
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //     
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //    
    standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15));
    //?     
    standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15));
    //?   
    ChartFactory.setChartTheme(standardChartTheme);
    //?
    JFreeChart jfreeChart = ChartFactory.createBarChart3D("", "", "?", dataset,
            PlotOrientation.VERTICAL, true, false, false);
    /**
     * JFreeChart
     */
    jfreeChart.setTitle(new TextTitle("", new Font("", Font.BOLD + Font.ITALIC, 20)));
    CategoryPlot plot = (CategoryPlot) jfreeChart.getPlot();
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setLabelFont(new Font("", Font.ROMAN_BASELINE, 12));

    return jfreeChart;
}

From source file:edu.msu.cme.rdp.classifier.train.validation.distance.BoxPlotUtils.java

public static void createBoxplot(DefaultBoxAndWhiskerCategoryDataset scatterDataset, PrintStream outStream,
        String title, String xAxisLabel, String yAxisLabel, Font lableFont) throws IOException {

    CategoryAxis xAxis = new CategoryAxis(xAxisLabel);
    xAxis.setLabelFont(lableFont);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setTickLabelFont(lableFont);/*w w w.j a v a  2s. co  m*/
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setRange(0, 100);
    yAxis.setLabelFont(lableFont);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);
    renderer.setBaseLegendTextFont(lableFont);
    renderer.setStroke(new BasicStroke(5.0f));

    CategoryPlot plot = new CategoryPlot(scatterDataset, xAxis, yAxis, renderer);
    JFreeChart boxchart = new JFreeChart(title, new Font("Helvetica", Font.BOLD, 40), plot, true);

    // higher scale factor gives higher resolution
    ChartUtilities.writeScaledChartAsPNG(outStream, boxchart, 800, 1000, 3, 3);
}

From source file:com.ouc.cpss.view.ChartProBuilder.java

private static JFreeChart createJFreeChart(CategoryDataset dataset) {
    /**/*from  w  ww  . ja  v  a  2  s .  com*/
     * JFreeChart
     */
    //?     
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //     
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //    
    standardChartTheme.setRegularFont(new Font("", Font.PLAIN, 15));
    //?     
    standardChartTheme.setLargeFont(new Font("", Font.PLAIN, 15));
    //?   
    ChartFactory.setChartTheme(standardChartTheme);
    //?
    // ?
    JFreeChart jfreeChart = null;
    if (choice == 1) {
        jfreeChart = ChartFactory.createBarChart3D("? -- ?TOP10", "",
                "?", dataset, PlotOrientation.VERTICAL, true, false, false);
        /**
          * JFreeChart
          */
        jfreeChart.setTitle(new TextTitle("? -- ?TOP10",
                new Font("", Font.BOLD + Font.ITALIC, 20)));
        CategoryPlot plot = (CategoryPlot) jfreeChart.getPlot();
        CategoryAxis categoryAxis = plot.getDomainAxis();
        categoryAxis.setLabelFont(new Font("", Font.ROMAN_BASELINE, 12));
    } else {
        jfreeChart = ChartFactory.createBarChart3D("? -- ?TOP10", "",
                "?", dataset, PlotOrientation.VERTICAL, true, false, false);
        jfreeChart.setTitle(new TextTitle("? -- ?TOP10",
                new Font("", Font.BOLD + Font.ITALIC, 20)));
        CategoryPlot plot = (CategoryPlot) jfreeChart.getPlot();
        CategoryAxis categoryAxis = plot.getDomainAxis();
        categoryAxis.setLabelFont(new Font("", Font.ROMAN_BASELINE, 12));
    }
    return jfreeChart;
}

From source file:com.ouc.cpss.view.ProfitChartBuilder.java

public static JFreeChart createJFreeChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart("?", "", "?",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    // ?/*from w w w .  j a  v a 2  s .co  m*/
    LegendTitle legendTitle = chart.getLegend(0);
    // 
    legendTitle.setItemFont(new Font("", Font.BOLD, 18));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    // ?
    org.jfree.chart.axis.CategoryAxis categoryAxis = plot.getDomainAxis();
    // 
    categoryAxis.setLabelFont(new Font("", Font.BOLD, 18));

    // 
    categoryAxis.setTickLabelFont(new Font("", Font.BOLD, 12));
    // ?
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    // 
    numberAxis.setLabelFont(new Font("", Font.BOLD, 14));

    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//

    CategoryItemRenderer xylineandshaperenderer = plot.getRenderer();
    xylineandshaperenderer.setBaseItemLabelsVisible(true);
    xylineandshaperenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.BASELINE_RIGHT));
    xylineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    return chart;
}

From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java

/**
 * Creates a sample chart.//from   w w  w.ja v  a 2  s  . co  m
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
public static JFreeChart createChart(final CategoryDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "X-value", // domain axis label
            "Y-value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, false);
    chart.addSubtitle(new TextTitle("http://www.bupt.edu.cn", new Font("", Font.ITALIC, 10)));
    //   chart.setBackgroundPaint(Color.white);
    //   chart.setBackgroundPaint(Color.getHSBColor(2, 29, 100));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseItemLabelsVisible(true);

    //
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setCategoryMargin(0.1);//
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.10);

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

    chart.getTitle().setFont(new Font("", Font.PLAIN, 16));//

    CategoryAxis domainAxis = plot.getDomainAxis();
    //
    domainAxis.setLabelFont(new Font("", Font.PLAIN, 14));
    //
    domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10));

    //
    rangeAxis.setLabelFont(new Font("", Font.PLAIN, 15));

    chart.getLegend().setItemFont(new Font("", Font.PLAIN, 15));

    return chart;
}

From source file:MainUI.java

public static JFreeChart createChart(CategoryDataset dataset) //?
{
    JFreeChart chart = ChartFactory.createBarChart("hi", "", "?", dataset,
            PlotOrientation.VERTICAL, true, true, false); //JFreeChart
    chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20)));//???hi?
    CategoryPlot plot = (CategoryPlot) chart.getPlot();//?plot
    CategoryAxis categoryAxis = plot.getDomainAxis();//??
    categoryAxis.setLabelFont(new Font("", Font.BOLD, 12));//??
    return chart;
}

From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java

private static void setupPlot(CategoryPlot categoryPlot) {
    categoryPlot.setBackgroundPaint(Color.white);
    categoryPlot.setRangeGridlinePaint(Color.black);
    // hide the border of the sorrounding box
    categoryPlot.setOutlinePaint(Color.white);
    // get domanin and range axes
    CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    ValueAxis rangeAxis = categoryPlot.getRangeAxis();
    // set label paint for axes to black
    domainAxis.setLabelPaint(Color.black);
    rangeAxis.setLabelPaint(Color.black);
    // set font for labels, both on domain and range axes
    domainAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12));
    rangeAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12));

}

From source file:com.mxgraph.examples.swing.chart.BarChartDemo1.java

public static JFreeChart createChart1(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "X-value", // domain axis label
            "Y-value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*  w w w  . j  a va 2 s. c om*/

    // 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();
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setCategoryMargin(0.1);//
    categoryAxis.setUpperMargin(0.02);
    categoryAxis.setLowerMargin(0.02);

    // ******************************************************************
    //  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());
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.10);
    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(true);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    // 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);

    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
    renderer.setItemLabelAnchorOffset(10D);
    renderer.setItemLabelFont(new Font("", Font.PLAIN, 12));
    renderer.setItemLabelsVisible(true);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 180));

    // OPTIONAL CUSTOMISATION COMPLETED.      

    chart.getTitle().setFont(new Font("", Font.BOLD, 16));//

    //
    domainAxis.setLabelFont(new Font("", Font.BOLD, 14));
    //
    domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 10));

    //
    rangeAxis.setLabelFont(new Font("", Font.BOLD, 15));

    chart.getLegend().setItemFont(new Font("", Font.BOLD, 15));

    /**
     *  chart.getTitle().setFont(new Font("",Font.BOLD,20));//
            
    //
    domainAxis.setLabelFont(new Font("",Font.BOLD,14));
    //
    domainAxis.setTickLabelFont(new Font("",Font.BOLD,12));
    //
    rangeAxis.setLabelFont(new Font("",Font.BOLD,15));
            
    chart.getLegend().setItemFont(new Font("", Font.BOLD, 15));
     */
    return chart;

}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartAxisFactory.java

public static CategoryAxis createCategoryDomainAxis(PlotConfiguration plotConfiguration) {
    CategoryAxis domainAxis = new CategoryAxis(null);
    String label = plotConfiguration.getDomainConfigManager().getLabel();
    if (label == null) {
        label = I18N.getGUILabel("plotter.unnamed_value_label");
    }/*from w  w w. j a  v  a  2s  . c  o m*/
    domainAxis.setLabel(label);

    Font axesFont = plotConfiguration.getAxesFont();
    if (axesFont != null) {
        domainAxis.setLabelFont(axesFont);
        domainAxis.setTickLabelFont(axesFont);
    }

    // rotate labels
    if (plotConfiguration.getOrientation() != PlotOrientation.HORIZONTAL) {
        domainAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
    }

    formatAxis(plotConfiguration, domainAxis);
    return domainAxis;
}