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

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

Introduction

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

Prototype

public void setTickLabelFont(Font font) 

Source Link

Document

Sets the font for the tick labels and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:playground.dgrether.analysis.categoryhistogram.CategoryHistogramWriter.java

public JFreeChart getGraphic(final CategoryHistogram histo, final String modeName) {
    this.checkIndex(histo);
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries(this.departuresName, false, true);
    final XYSeries arrivalsSerie = new XYSeries(this.arrivalsName, false, true);
    final XYSeries onRouteSerie = new XYSeries(this.enRouteName, false, true);
    Integer enRoute = 0;/*from   w  ww.j  a v  a  2s . c o m*/
    for (int i = histo.getFirstIndex() - 2; i <= histo.getLastIndex() + 2; i++) {
        int departures = histo.getDepartures(modeName, i);
        int arrivals = histo.getArrivals(modeName, i);
        int stuck = histo.getAbort(modeName, i);
        enRoute = enRoute + departures - arrivals - stuck;
        double hour = i * histo.getBinSizeSeconds() / 60.0 / 60.0;
        departuresSerie.add(hour, departures);
        arrivalsSerie.add(hour, arrivals);
        onRouteSerie.add(hour, enRoute);
    }
    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            this.title + ", " + modeName + ", " + "it." + histo.getIteration(), "time [h]", yTitle, xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(1.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

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

/**
 * Creates a new demo.//from  ww  w.j a  v  a  2s  .c o m
 *
 * @param title  the frame title.
 */
public OverlaidCategoryChartDemo(String title) {

    super(title);
    DefaultIntervalCategoryDataset barData = null;
    double[][] lows = { { -.0315, .0159, .0306, .0453, .0557 } };
    double[][] highs = { { .1931, .1457, .1310, .1163, .1059 } };
    barData = new DefaultIntervalCategoryDataset(lows, highs);

    double[][] vals = { { 0.0808, 0.0808, 0.0808, 0.0808, 0.0808 } };
    CategoryDataset dotData = DatasetUtilities.createCategoryDataset("Series ", "Category ", vals);

    double[][] lineVals = new double[4][5];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 5; j++) {
            lineVals[i][j] = (Math.random() * 0.56) - 0.18;
        }
    }
    CategoryDataset lineData = DatasetUtilities.createCategoryDataset("Series ", "Category ", lineVals);

    String ctitle = "Strategie Sicherheit";
    String xTitle = "Zeitraum (in Jahren)";
    String yTitle = "Performance";
    CategoryAxis xAxis = new CategoryAxis(xTitle);
    xAxis.setLabelFont(titleFont);
    xAxis.setTickLabelFont(labelFont);
    xAxis.setTickMarksVisible(false);
    NumberAxis yAxis = new NumberAxis(yTitle);
    yAxis.setLabelFont(titleFont);
    yAxis.setTickLabelFont(labelFont);
    yAxis.setRange(-0.2, 0.4);
    DecimalFormat formatter = new DecimalFormat("0.##%");
    yAxis.setTickUnit(new NumberTickUnit(0.05, formatter));

    IntervalBarRenderer barRenderer = new IntervalBarRenderer();
    barRenderer.setItemLabelsVisible(Boolean.TRUE);

    CategoryPlot plot = new CategoryPlot(barData, xAxis, yAxis, barRenderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setOutlinePaint(Color.black);

    LineAndShapeRenderer dotRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES);
    dotRenderer.setItemLabelsVisible(Boolean.TRUE);

    plot.setSecondaryDataset(0, dotData);
    plot.setSecondaryRenderer(0, dotRenderer);

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES_AND_LINES);
    plot.setSecondaryDataset(1, lineData);
    plot.setSecondaryRenderer(1, lineRenderer);

    this.chart = new JFreeChart(ctitle, titleFont, plot, false);
    this.chart.setBackgroundPaint(Color.white);

    ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.javarebel.chart.generator.ChartGenerator.java

protected void configureAxis(CategoryAxis axis, DefaultAxisConfig config) {
    axis.setCategoryLabelPositions(config.getLabelPosition());
    axis.setLabelFont(config.getLabelFont());
    axis.setTickLabelFont(config.getTickLabelFont());
    axis.setLowerMargin(config.getLowerMargin());
    axis.setUpperMargin(config.getUpperMargin());
    axis.setCategoryMargin(config.getCategoryMargin());
}

From source file:com.netsteadfast.greenstep.action.CommonBarChartAction.java

private void fillChart(String title, String categoryLabel, String valueLabel, List<String> names,
        List<Float> values, List<String> colors, boolean horizontal) throws Exception {
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    for (int ix = 0; ix < names.size(); ix++) {
        data.addValue(values.get(ix), "", names.get(ix));
    }/*from ww w . jav a 2  s.co  m*/
    this.chart = ChartFactory.createBarChart3D(title, // title
            categoryLabel, valueLabel, data,
            (horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL), false, false, false);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    CategoryAxis categoryAxis = plot.getDomainAxis();
    categoryAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    categoryAxis.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
    this.setPlotColor(plot, names, colors);
    this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}

From source file:org.openmrs.module.vcttrac.web.view.chart.VCTCreateBarChartView.java

/**
 * Creates a sample chart./*from  w w w.ja  v a 2s .c o  m*/
 * 
 * @param dataset the dataset.
 * @return The chart.
 */
private JFreeChart createChart(CategoryDataset dataset, int typeOfChart) {
    String title = "";
    if (typeOfChart == 1)
        title = VCTTracUtil.getMessage("vcttrac.graph.statistic.compare.todayandyesterday", null);
    else if (typeOfChart == 2)
        title = VCTTracUtil.getMessage("vcttrac.year", null) + " : " + (new Date().getYear() + 1900);
    else if (typeOfChart == 3)
        title = VCTTracUtil.getMessage("vcttrac.graph.statistic.years", null);
    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(title, null, null, // chart title
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    Paint[] colors = createPaint();
    CustomBarRenderer renderer = new CustomBarRenderer(colors);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setRenderer(renderer);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setUpperMargin(0.15);

    //      CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 12));
    if (typeOfChart < 2)
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
    else
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

    return chart;

}

From source file:playground.dgrether.events.handlers.DgGeoFilteredLegHistogram.java

private JFreeChart getGraphic(final ModeData modeData, final String modeName) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < modeData.countsDep.length; i++) {
        onRoute = onRoute + modeData.countsDep[i] - modeData.countsArr[i] - modeData.countsStuck[i];
        double hour = i * this.binSizeSeconds / 60.0 / 60.0;
        departuresSerie.add(hour, modeData.countsDep[i]);
        arrivalsSerie.add(hour, modeData.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }//  w  w  w .  j a  v a 2 s .com

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "Leg Histogram, " + modeName + ", it." + this.iteration, "time", "# vehicles", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.ChartPostProcessorImpl.java

/**
 * This method sets the width of the bars, and the spacing between the bars. It sets a general, hard coded standard for this. In JFreeChart, you
 * cannot set the bar width. In stead, you set the gaps: - lowerMargin is the gap between the start of the x-axis and the first bar - upperMargin
 * is the gap between the end of the x-axis and the last bar - categoryMargin is the gap between the categories. Note that the number you provide
 * here, is divided over all the gaps. So if you set this margin to 0.5 (is 50%) and there are 6 categories, this means that there are 5 gaps, so
 * each gap will get 10%. - itemMargin is the gap between the bars within a category. Again, this number is divided over all the itemgaps in the
 * whole graph. The method also takes care that extreme cases (with a very small amount of bars) still look acceptable.
 * @param plot//from w w w .j  a  v  a 2 s .c  om
 */
private void setMargins(final CategoryPlot plot) {
    final CategoryAxis axis = plot.getDomainAxis();
    axis.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    final int categoryCount = plot.getCategories().size();
    final int seriesCount = plot.getDataset().getRowCount();
    axis.setCategoryMargin(0.23); // sets spacing between categories on x%
    // set spacing between bars inside a catgory (in fractions, so 1 = 100%)
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    if (categoryCount == 1) {
        renderer.setItemMargin(0.15);
    } else {
        renderer.setItemMargin(0.03);
    }
    // extreme cases
    if (categoryCount * seriesCount < 4) {
        final double outerMargins = (4.0 - (categoryCount * seriesCount)) / 10.0;
        axis.setLowerMargin(outerMargins);
        axis.setUpperMargin(outerMargins);
    }
}

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 */// w  ww  .  j  a va  2  s  . co  m
private JFreeChart getGraphic(String title, String legend, String modeName, int inputData[]) {

    /*
     * Write only the number of defined picture bins to the plot.
     */
    int data[];
    if (inputData.length > this.nofPictureBins) {
        data = Arrays.copyOfRange(inputData, 0, this.nofPictureBins);
    } else
        data = inputData;

    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries dataSerie = new XYSeries(legend, false, true);

    for (int i = 0; i < data.length; i++) {
        double hour = i * this.binSize / 60.0 / 60.0;
        dataSerie.add(hour, data[i]);
    }

    xyData.addSeries(dataSerie);
    final JFreeChart chart = ChartFactory.createXYStepChart(title + ", " + modeName + ", it." + this.iteration,
            "time", "# agents", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}

From source file:playground.johannes.snowball.Histogram.java

public void plot(String filename, String title) throws IOException {
    fillBins();//from   w w  w . j  ava2  s . co m
    final XYSeriesCollection data = new XYSeriesCollection();
    final XYSeries wave = new XYSeries(title, false, true);

    double min, max, width;
    //      int size;

    if (bounds != null) {
        min = bounds[0];
        max = bounds[1];
    } else {
        double minmax[] = getMinMax();
        min = minmax[0];
        max = minmax[1];
    }
    if (binWidth > 0) {
        //         size = (int)Math.ceil((max - min)/(double)binWidth);
        width = binWidth;
    } else {
        //         size = bincount;
        width = (max - min) / (double) bincount;
    }

    int cnt = bins.size();
    for (int i = 0; i < cnt; i++) {
        wave.add(i * width + min, bins.get(i));
    }

    data.addSeries(wave);

    final JFreeChart chart = ChartFactory.createXYStepChart("title", "x", "y", data, PlotOrientation.VERTICAL,
            true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("x");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("y"));
    ChartUtilities.saveChartAsPNG(new File(filename), chart, 1024, 768);
}

From source file:playground.christoph.evacuation.analysis.AgentsInEvacuationAreaWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//* w ww  .j  av a 2s.  co  m*/
private JFreeChart getGraphic(String[] modeNames, int inputData[][]) {

    /*
     * Write only the number of defined picture bins to the plot.
     */
    int data[][];
    data = new int[inputData.length][];
    for (int i = 0; i < inputData.length; i++) {
        if (inputData[i].length > this.nofPictureBins) {
            data[i] = Arrays.copyOfRange(inputData[i], 0, this.nofPictureBins);
        } else
            data[i] = inputData[i];
    }

    final XYSeriesCollection xyData = new XYSeriesCollection();

    for (int j = 0; j < modeNames.length; j++) {
        String modeName = modeNames[j];
        int[] d = data[j];

        XYSeries dataSerie = new XYSeries(modeName, false, true);

        for (int i = 0; i < d.length; i++) {
            double hour = i * this.binSize / 60.0 / 60.0;
            dataSerie.add(hour, d[i]);
        }

        xyData.addSeries(dataSerie);
    }

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "agents in evacuated area, all modes, it." + this.iteration, "time", "# agents", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}