Example usage for org.jfree.chart.axis ValueAxis getTickLabelFont

List of usage examples for org.jfree.chart.axis ValueAxis getTickLabelFont

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis getTickLabelFont.

Prototype

public Font getTickLabelFont() 

Source Link

Document

Returns the font used for the tick labels (if showing).

Usage

From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java

public static JFreeChart createXYChart(String title, XYDataset data, String xLabel, String yLabel,
        int pointRadius, int lineThickness, ColorTheme theme) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, data, PlotOrientation.VERTICAL,
            true, false, false);/*  w ww .j ava2 s.  c o  m*/

    formatColorTheme(chart, theme);

    XYPlot plot = (XYPlot) chart.getPlot();
    Shape icon = new Ellipse2D.Double(-pointRadius, -pointRadius, pointRadius * 2, pointRadius * 2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    Color[] colors = generateJetSpectrum(data.getSeriesCount());
    for (int i = 0; i < data.getSeriesCount(); i++) {
        plot.getRenderer().setSeriesStroke(i, new BasicStroke(lineThickness));
        plot.getRenderer().setSeriesShape(i, icon);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesVisible(i, true);
        ((XYLineAndShapeRenderer) plot.getRenderer()).setSeriesShapesFilled(i, true);
        plot.getRenderer().setSeriesPaint(i, colors[i]);
    }

    LegendTitle legend = chart.getLegend();
    Font legendFont = legend.getItemFont();
    float legendFontSize = legendFont.getSize();
    Font newLegendFont = legendFont.deriveFont(legendFontSize * 0.6f);
    legend.setItemFont(newLegendFont);

    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Font domainAxisLabelFont = domainAxis.getLabelFont();
    float domainAxisLabelFontSize = domainAxisLabelFont.getSize();
    domainAxis.setLabelFont(domainAxisLabelFont.deriveFont(domainAxisLabelFontSize * 0.6f));

    Font domainAxisTickLabelFont = domainAxis.getTickLabelFont();
    float domainAxisTickLabelFontSize = domainAxisTickLabelFont.getSize();
    domainAxis.setTickLabelFont(domainAxisTickLabelFont.deriveFont(domainAxisTickLabelFontSize * 0.6f));

    ValueAxis rangeAxis = ((XYPlot) chart.getPlot()).getRangeAxis();
    Font rangeAxisLabelFont = rangeAxis.getLabelFont();
    float rangeAxisLabelFontSize = rangeAxisLabelFont.getSize();
    rangeAxis.setLabelFont(rangeAxisLabelFont.deriveFont(rangeAxisLabelFontSize * 0.6f));

    Font rangeAxisTickLabelFont = rangeAxis.getTickLabelFont();
    float rangeAxisTickLabelFontSize = rangeAxisTickLabelFont.getSize();
    rangeAxis.setTickLabelFont(rangeAxisTickLabelFont.deriveFont(rangeAxisTickLabelFontSize * 0.6f));

    return chart;
}

From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java

/**
 * @param folderToWrite Folder to write the resulted charts.
 * @param plots Collections of plots./*from  ww  w . jav  a2s  .  c  o  m*/
 * @param infoMap Map with additional plot info.
 * @param mode Generation mode.
 * @throws Exception If failed.
 */
private static void processPlots(File folderToWrite, Collection<List<PlotData>> plots,
        Map<String, List<JFreeChartPlotInfo>> infoMap, JFreeChartGenerationMode mode) throws Exception {
    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    int idx = -1;

    while (true) {
        idx++;

        DefaultXYDataset dataSet = new DefaultXYDataset();

        List<JFreeChartPlotInfo> infoList = new ArrayList<>();

        String xAxisLabel = "";
        String yAxisLabel = "";
        String plotName = "";

        int cnt = 0;

        for (List<PlotData> plotData0 : plots) {
            if (plotData0.size() <= idx)
                continue;

            PlotData plotData = plotData0.get(idx);

            dataSet.addSeries(plotData.plotName() + "_" + cnt++, plotData.series().data);

            xAxisLabel = plotData.xAxisLabel;
            yAxisLabel = plotData.yAxisLabel;
            plotName = plotData.plotName();

            infoList.add(info(plotData.series(), mode));
        }

        if (infoList.isEmpty())
            break;

        JFreeChart chart = ChartFactory.createXYLineChart("", xAxisLabel, yAxisLabel, dataSet,
                PlotOrientation.VERTICAL, false, false, false);

        AxisSpace as = new AxisSpace();

        as.add(150, RectangleEdge.LEFT);

        XYPlot plot = (XYPlot) chart.getPlot();

        BasicStroke stroke = new BasicStroke(1);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(WHITE);
        plot.setRangeGridlinePaint(GRAY);
        plot.setDomainGridlinePaint(GRAY);
        plot.setFixedRangeAxisSpace(as);
        plot.setOutlineStroke(stroke);

        for (int i = 0; i < infoList.size(); i++) {
            Color color = PLOT_COLORS[i % PLOT_COLORS.length];

            renderer.setSeriesPaint(i, color);
            renderer.setSeriesStroke(i, new BasicStroke(3)); // Line thickness.

            infoList.get(i).color(Integer.toHexString(color.getRGB()).substring(2));
        }

        ValueAxis axis = plot.getRangeAxis();

        Font font = new Font("Helvetica,Arial,sans-serif", Font.BOLD, axis.getTickLabelFont().getSize() + 5);

        axis.setTickLabelFont(font);
        axis.setLabelFont(font);
        plot.getDomainAxis().setTickLabelFont(font);
        plot.getDomainAxis().setLabelFont(font);

        chart.setTitle(new TextTitle(yAxisLabel, new Font(font.getName(), font.getStyle(), 30)));

        File res = new File(folderToWrite, plotName + ".png");

        ChartUtilities.saveChartAsPNG(res, chart, 1000, 500, info);

        infoMap.put(res.getAbsolutePath(), infoList);

        println("Chart is saved to file: ", res);
    }
}

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

/**
 * A demonstration application showing some bugs with tick labels in version 0.9.13
 *
 * @param title  the frame title./*  ww w .j  av  a 2 s . c o  m*/
 */
public XYTickLabelDemo(final String title) {

    super(title);
    this.chart = createChart();
    final ChartPanel chartPanel = new ChartPanel(this.chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(600, 270));

    final JPanel mainPanel = new JPanel(new BorderLayout());
    setContentPane(mainPanel);
    mainPanel.add(chartPanel);

    final JPanel optionsPanel = new JPanel();
    mainPanel.add(optionsPanel, BorderLayout.SOUTH);

    this.symbolicAxesCheckBox = new JCheckBox("Symbolic axes");
    this.symbolicAxesCheckBox.addActionListener(this);
    optionsPanel.add(this.symbolicAxesCheckBox);

    this.verticalTickLabelsCheckBox = new JCheckBox("Tick labels vertical");
    this.verticalTickLabelsCheckBox.addActionListener(this);
    optionsPanel.add(this.verticalTickLabelsCheckBox);

    this.fontSizeTextField = new JTextField(3);
    this.fontSizeTextField.addActionListener(this);
    optionsPanel.add(new JLabel("Font size:"));
    optionsPanel.add(this.fontSizeTextField);
    final ValueAxis axis = this.chart.getXYPlot().getDomainAxis();
    this.fontSizeTextField.setText(DEFAULT_FONT_SIZE + "");

    final XYPlot plot = this.chart.getXYPlot();
    Font ft = axis.getTickLabelFont();
    ft = ft.deriveFont((float) DEFAULT_FONT_SIZE);
    plot.getDomainAxis().setTickLabelFont(ft);
    plot.getRangeAxis().setTickLabelFont(ft);
    plot.getDomainAxis(1).setTickLabelFont(ft);
    plot.getRangeAxis(1).setTickLabelFont(ft);

    this.horizontalPlotCheckBox = new JCheckBox("Plot horizontal");
    this.horizontalPlotCheckBox.addActionListener(this);
    optionsPanel.add(this.horizontalPlotCheckBox);
}

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

/**
 * When a checkbox is changed .../*from w w  w  .  j a v a2  s  . c o  m*/
 * 
 * @param event  the event.
 */
public void actionPerformed(final ActionEvent event) {
    final ValueAxis[] axes = new ValueAxis[4];
    final XYPlot plot = this.chart.getXYPlot();
    axes[0] = plot.getDomainAxis();
    axes[1] = plot.getRangeAxis();
    axes[2] = plot.getDomainAxis(1);
    axes[3] = plot.getRangeAxis(1);

    final Object source = event.getSource();

    if (source == this.symbolicAxesCheckBox) {

        final boolean val = this.symbolicAxesCheckBox.isSelected();

        for (int i = 0; i < axes.length; i++) {
            ValueAxis axis = axes[i];
            final String label = axis.getLabel();
            final int maxTick = (int) axis.getUpperBound();
            final String[] tickLabels = new String[maxTick];
            final Font ft = axis.getTickLabelFont();
            for (int itk = 0; itk < maxTick; itk++) {
                tickLabels[itk] = "Label " + itk;
            }
            axis = val ? new SymbolicAxis(label, tickLabels) : new NumberAxis(label);
            axis.setTickLabelFont(ft);
            axes[i] = axis;
        }
        plot.setDomainAxis(axes[0]);
        plot.setRangeAxis(axes[1]);
        plot.setDomainAxis(1, axes[2]);
        plot.setRangeAxis(1, axes[3]);

    }

    if (source == this.symbolicAxesCheckBox || source == this.verticalTickLabelsCheckBox) {
        final boolean val = this.verticalTickLabelsCheckBox.isSelected();

        for (int i = 0; i < axes.length; i++) {
            axes[i].setVerticalTickLabels(val);
        }

    } else if (source == this.symbolicAxesCheckBox || source == this.horizontalPlotCheckBox) {

        final PlotOrientation val = this.horizontalPlotCheckBox.isSelected() ? PlotOrientation.HORIZONTAL
                : PlotOrientation.VERTICAL;
        this.chart.getXYPlot().setOrientation(val);

    } else if (source == this.symbolicAxesCheckBox || source == this.fontSizeTextField) {
        final String s = this.fontSizeTextField.getText();
        if (s.length() > 0) {
            final float sz = Float.parseFloat(s);
            for (int i = 0; i < axes.length; i++) {
                final ValueAxis axis = axes[i];
                Font ft = axis.getTickLabelFont();
                ft = ft.deriveFont(sz);
                axis.setTickLabelFont(ft);
            }
        }
    }
}