Example usage for org.jfree.chart.axis Axis getLabelFont

List of usage examples for org.jfree.chart.axis Axis getLabelFont

Introduction

In this page you can find the example usage for org.jfree.chart.axis Axis getLabelFont.

Prototype

public Font getLabelFont() 

Source Link

Document

Returns the font for the axis label.

Usage

From source file:net.sf.dynamicreports.test.jasper.chart.XyBlockChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//from   w  w w  .j ava2  s  .c o  m

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", XYBlockRenderer.class, renderer.getClass());
    Assert.assertEquals("block width", 1.1, ((XYBlockRenderer) renderer).getBlockWidth());
    Assert.assertEquals("block height", 0.9, ((XYBlockRenderer) renderer).getBlockHeight());
    Assert.assertEquals("block anchor", org.jfree.ui.RectangleAnchor.BOTTOM_LEFT,
            ((XYBlockRenderer) renderer).getBlockAnchor());

    Assert.assertEquals("paintScale", LookupPaintScale.class,
            ((XYBlockRenderer) renderer).getPaintScale().getClass());
    LookupPaintScale paintScale = (LookupPaintScale) ((XYBlockRenderer) renderer).getPaintScale();
    Assert.assertEquals("paintScale default lower bound", 0.1, paintScale.getLowerBound());
    Assert.assertEquals("paintScale default upper bound", 5d, paintScale.getUpperBound());
    Assert.assertEquals("paintScale default paint", Color.WHITE, paintScale.getDefaultPaint());
    Assert.assertEquals("paintScale paint 1", Color.RED, paintScale.getPaint(1));
    Assert.assertEquals("paintScale paint 2", Color.GREEN, paintScale.getPaint(2));
    Assert.assertEquals("paintScale paint 3", Color.BLUE, paintScale.getPaint(3));

    LegendItemCollection legendItems = chart.getXYPlot().getLegendItems();
    Assert.assertEquals("legend item 1 label", "1", legendItems.get(0).getLabel());
    Assert.assertEquals("legend item 1 paint", Color.RED, legendItems.get(0).getFillPaint());
    Assert.assertEquals("legend item 2 label", "2", legendItems.get(1).getLabel());
    Assert.assertEquals("legend item 2 paint", Color.GREEN, legendItems.get(1).getFillPaint());
    Assert.assertEquals("legend item 3 label", "3", legendItems.get(2).getLabel());
    Assert.assertEquals("legend item 3 paint", Color.BLUE, legendItems.get(2).getFillPaint());

    xyzChartDataTest(chart, 0, "serie0",
            new Number[][] { { 1d, 2d, 0d }, { 2d, 3d, 1d }, { 3d, 4d, 2d }, { 4d, 5d, 3d } });

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
}

From source file:ch.zhaw.simulation.diagram.charteditor.DefaultAxisEditor.java

/**
 * Standard constructor: builds a panel for displaying/editing the
 * properties of the specified axis.//from   www .ja  v a  2  s  .c om
 * 
 * @param axis
 *            the axis whose properties are to be displayed/edited in the
 *            panel.
 */
public DefaultAxisEditor(Axis axis) {
    this.labelFont = axis.getLabelFont();
    this.labelPaintSample = new PaintSample(axis.getLabelPaint());
    this.tickLabelFont = axis.getTickLabelFont();
    this.tickLabelPaintSample = new PaintSample(axis.getTickLabelPaint());

    // Insets values
    this.tickLabelInsets = axis.getTickLabelInsets();
    this.labelInsets = axis.getLabelInsets();

    setLayout(new BorderLayout());

    JPanel general = new JPanel(new BorderLayout());
    general.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
            localizationResources.getString("General")));

    JPanel interior = new JPanel(new LCBLayout(5));
    interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    interior.add(new JLabel(localizationResources.getString("Label")));
    this.label = new JTextField(axis.getLabel());
    interior.add(this.label);
    interior.add(new JPanel());

    interior.add(new JLabel(localizationResources.getString("Font")));
    this.labelFontField = new FontDisplayField(this.labelFont);
    interior.add(this.labelFontField);
    JButton b = new JButton(localizationResources.getString("Select..."));
    b.setActionCommand("SelectLabelFont");
    b.addActionListener(this);
    interior.add(b);

    interior.add(new JLabel(localizationResources.getString("Paint")));
    interior.add(this.labelPaintSample);
    b = new JButton(localizationResources.getString("Select..."));
    b.setActionCommand("SelectLabelPaint");
    b.addActionListener(this);
    interior.add(b);

    general.add(interior);

    add(general, BorderLayout.NORTH);

    this.slot1 = new JPanel(new BorderLayout());

    JPanel other = new JPanel(new BorderLayout());
    other.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
            localizationResources.getString("Other")));

    this.otherTabs = new JTabbedPane();
    this.otherTabs.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));

    JPanel ticks = new JPanel(new LCBLayout(3));
    ticks.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    this.showTickLabelsCheckBox = new JCheckBox(localizationResources.getString("Show_tick_labels"),
            axis.isTickLabelsVisible());
    ticks.add(this.showTickLabelsCheckBox);
    ticks.add(new JPanel());
    ticks.add(new JPanel());

    ticks.add(new JLabel(localizationResources.getString("Tick_label_font")));
    this.tickLabelFontField = new FontDisplayField(this.tickLabelFont);
    ticks.add(this.tickLabelFontField);
    b = new JButton(localizationResources.getString("Select..."));
    b.setActionCommand("SelectTickLabelFont");
    b.addActionListener(this);
    ticks.add(b);

    this.showTickMarksCheckBox = new JCheckBox(localizationResources.getString("Show_tick_marks"),
            axis.isTickMarksVisible());
    ticks.add(this.showTickMarksCheckBox);
    ticks.add(new JPanel());
    ticks.add(new JPanel());

    this.otherTabs.add(localizationResources.getString("Ticks"), ticks);

    other.add(this.otherTabs);

    this.slot1.add(other);

    this.slot2 = new JPanel(new BorderLayout());
    this.slot2.add(this.slot1, BorderLayout.NORTH);
    add(this.slot2);

}

From source file:org.jfree.experimental.chart.swt.editor.SWTAxisEditor.java

/**
 * Standard constructor: builds a composite for displaying/editing 
 * the properties of the specified axis.
 *
 * @param parent The parent composite.//from ww w  .jav a2  s . c om
 * @param style The SWT style of the SwtAxisEditor.
 * @param axis  the axis whose properties are to be displayed/edited  
 *              in the composite.
 */
public SWTAxisEditor(Composite parent, int style, Axis axis) {
    super(parent, style);
    this.labelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getLabelFont(), true);
    this.labelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getLabelPaint());
    this.tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getTickLabelFont(), true);
    this.tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getTickLabelPaint());

    FillLayout layout = new FillLayout(SWT.VERTICAL);
    layout.marginHeight = layout.marginWidth = 4;
    this.setLayout(layout);
    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));
    // row 1
    new Label(general, SWT.NONE).setText(localizationResources.getString("Label"));
    this.label = new Text(general, SWT.BORDER);
    if (axis.getLabel() != null) {
        this.label.setText(axis.getLabel());
    }
    this.label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(general, SWT.NONE).setText(""); //empty cell
    // row 2
    new Label(general, SWT.NONE).setText(localizationResources.getString("Font"));
    this.labelFontField = new Text(general, SWT.BORDER);
    this.labelFontField.setText(this.labelFont.toString());
    this.labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectFontButton = new Button(general, SWT.PUSH);
    selectFontButton.setText(localizationResources.getString("Select..."));
    selectFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTAxisEditor.this.labelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title 
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                //label.setFont( font );
                SWTAxisEditor.this.labelFontField.setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.labelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    // row 3
    new Label(general, SWT.NONE).setText(localizationResources.getString("Paint"));
    // Use a colored text field to show the color
    final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.labelPaintColor);
    GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    canvasGridData.heightHint = 20;
    colorCanvas.setLayoutData(canvasGridData);
    Button selectColorButton = new Button(general, SWT.PUSH);
    selectColorButton.setText(localizationResources.getString("Select..."));
    selectColorButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Title_Color"));
            dlg.setRGB(SWTAxisEditor.this.labelPaintColor.getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                // create the new color and set it to the 
                // SwtPaintCanvas
                SWTAxisEditor.this.labelPaintColor = new Color(getDisplay(), rgb);
                colorCanvas.setColor(SWTAxisEditor.this.labelPaintColor);
            }
        }
    });
    Group other = new Group(this, SWT.NONE);
    FillLayout tabLayout = new FillLayout();
    tabLayout.marginHeight = tabLayout.marginWidth = 4;
    other.setLayout(tabLayout);
    other.setText(localizationResources.getString("Other"));

    this.otherTabs = new TabFolder(other, SWT.NONE);
    TabItem item1 = new TabItem(this.otherTabs, SWT.NONE);
    item1.setText(" " + localizationResources.getString("Ticks") + " ");
    Composite ticks = new Composite(this.otherTabs, SWT.NONE);
    ticks.setLayout(new GridLayout(3, false));
    this.showTickLabelsCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickLabelsCheckBox.setText(localizationResources.getString("Show_tick_labels"));
    this.showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible());
    this.showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    new Label(ticks, SWT.NONE).setText(localizationResources.getString("Tick_label_font"));
    this.tickLabelFontField = new Text(ticks, SWT.BORDER);
    this.tickLabelFontField.setText(this.tickLabelFont.toString());
    //tickLabelFontField.setFont(SwtUtils.toSwtFontData(getDisplay(), 
    // axis.getTickLabelFont()));
    this.tickLabelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH);
    selectTickLabelFontButton.setText(localizationResources.getString("Select..."));
    selectTickLabelFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the font-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTAxisEditor.this.tickLabelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title 
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                //tickLabelFontField.setFont(font);
                SWTAxisEditor.this.tickLabelFontField
                        .setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.tickLabelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    this.showTickMarksCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickMarksCheckBox.setText(localizationResources.getString("Show_tick_marks"));
    this.showTickMarksCheckBox.setSelection(axis.isTickMarksVisible());
    this.showTickMarksCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    item1.setControl(ticks);
}

From source file:net.sf.dynamicreports.test.jasper.chart.XyAreaChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//from   w  w  w  .  ja  v  a  2s.c om

    JFreeChart chart = getChart("summary.chart1", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    XYPlot plot = chart.getXYPlot();
    Assert.assertEquals("renderer", XYAreaRenderer.class, plot.getRenderer().getClass());
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart2", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}

From source file:com.rcp.wbw.demo.editor.SWTAxisEditor.java

/**
 * Standard constructor: builds a composite for displaying/editing
 * the properties of the specified axis.
 * /*from   w w  w .j  av a 2 s  .c  o m*/
 * @param parent
 *            The parent composite.
 * @param style
 *            The SWT style of the SwtAxisEditor.
 * @param axis
 *            the axis whose properties are to be displayed/edited
 *            in the composite.
 */
public SWTAxisEditor(Composite parent, int style, Axis axis) {
    super(parent, style);
    this.labelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getLabelFont(), true);
    this.labelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getLabelPaint());
    this.tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getTickLabelFont(), true);
    this.tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getTickLabelPaint());

    FillLayout layout = new FillLayout(SWT.VERTICAL);
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);
    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));
    // row 1
    new Label(general, SWT.NONE).setText(localizationResources.getString("Label"));
    this.label = new Text(general, SWT.BORDER);
    if (axis.getLabel() != null) {
        this.label.setText(axis.getLabel());
    }
    this.label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    new Label(general, SWT.NONE).setText(""); // empty cell
    // row 2
    new Label(general, SWT.NONE).setText(localizationResources.getString("Font"));
    this.labelFontField = new Text(general, SWT.BORDER);
    this.labelFontField.setText(this.labelFont.toString());
    this.labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectFontButton = new Button(general, SWT.PUSH);
    selectFontButton.setText(localizationResources.getString("Select..."));
    selectFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTAxisEditor.this.labelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                // label.setFont(font);
                SWTAxisEditor.this.labelFontField.setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.labelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    // row 3
    new Label(general, SWT.NONE).setText(localizationResources.getString("Paint"));
    // Use a colored text field to show the color
    final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.labelPaintColor);
    GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    canvasGridData.heightHint = 20;
    colorCanvas.setLayoutData(canvasGridData);
    Button selectColorButton = new Button(general, SWT.PUSH);
    selectColorButton.setText(localizationResources.getString("Select..."));
    selectColorButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the color-change dialog
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Title_Color"));
            dlg.setRGB(SWTAxisEditor.this.labelPaintColor.getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                // create the new color and set it to the
                // SwtPaintCanvas
                SWTAxisEditor.this.labelPaintColor = new Color(getDisplay(), rgb);
                colorCanvas.setColor(SWTAxisEditor.this.labelPaintColor);
            }
        }
    });
    Group other = new Group(this, SWT.NONE);
    FillLayout tabLayout = new FillLayout();
    tabLayout.marginHeight = tabLayout.marginWidth = 4;
    other.setLayout(tabLayout);
    other.setText(localizationResources.getString("Other"));

    this.otherTabs = new TabFolder(other, SWT.NONE);
    TabItem item1 = new TabItem(this.otherTabs, SWT.NONE);
    item1.setText(" " + localizationResources.getString("Ticks") + " ");
    Composite ticks = new Composite(this.otherTabs, SWT.NONE);
    ticks.setLayout(new GridLayout(3, false));
    this.showTickLabelsCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickLabelsCheckBox.setText(localizationResources.getString("Show_tick_labels"));
    this.showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible());
    this.showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    new Label(ticks, SWT.NONE).setText(localizationResources.getString("Tick_label_font"));
    this.tickLabelFontField = new Text(ticks, SWT.BORDER);
    this.tickLabelFontField.setText(this.tickLabelFont.toString());
    // tickLabelFontField.setFont(SwtUtils.toSwtFontData(getDisplay(),
    // axis.getTickLabelFont()));
    this.tickLabelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH);
    selectTickLabelFontButton.setText(localizationResources.getString("Select..."));
    selectTickLabelFontButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            // Create the font-change dialog
            FontDialog dlg = new FontDialog(getShell());
            dlg.setText(localizationResources.getString("Font_Selection"));
            dlg.setFontList(new FontData[] { SWTAxisEditor.this.tickLabelFont });
            if (dlg.open() != null) {
                // Dispose of any fonts we have created
                if (SWTAxisEditor.this.font != null) {
                    SWTAxisEditor.this.font.dispose();
                }
                // Create the new font and set it into the title
                // label
                SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList());
                // tickLabelFontField.setFont(font);
                SWTAxisEditor.this.tickLabelFontField
                        .setText(SWTAxisEditor.this.font.getFontData()[0].toString());
                SWTAxisEditor.this.tickLabelFont = SWTAxisEditor.this.font.getFontData()[0];
            }
        }
    });
    this.showTickMarksCheckBox = new Button(ticks, SWT.CHECK);
    this.showTickMarksCheckBox.setText(localizationResources.getString("Show_tick_marks"));
    this.showTickMarksCheckBox.setSelection(axis.isTickMarksVisible());
    this.showTickMarksCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    item1.setControl(ticks);
}

From source file:net.sf.dynamicreports.test.jasper.chart.AreaChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*from  w w  w. j a v a  2s.c  o  m*/

    JFreeChart chart = getChart("summary.chart1", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", AreaRenderer.class, categoryPlot.getRenderer().getClass());
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions()
            .getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart2", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}

From source file:net.sf.dynamicreports.test.jasper.chart.StackedAreaChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//from  w  w  w  .  ja v a2  s  .c o m

    JFreeChart chart = getChart("summary.chart1", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", StackedAreaRenderer.class, categoryPlot.getRenderer().getClass());
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions()
            .getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart2", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

/** Generate CGI chart output. */
@Override/*from w w w.  j a  va 2s  .  c o m*/
protected void writeContents() throws IOException {
    buildData(); // get the data for display

    chromeless = (parameters.get("chromeless") != null);
    JFreeChart chart = createChart();

    int width = getIntSetting("width");
    int height = getIntSetting("height");
    Color initGradColor = getColorSetting("initGradColor");
    Color finalGradColor = getColorSetting("finalGradColor");
    chart.setBackgroundPaint(new GradientPaint(0, 0, initGradColor, width, height, finalGradColor));
    if (parameters.get("hideOutline") != null)
        chart.getPlot().setOutlinePaint(INVISIBLE);

    String title = getSetting("title");
    if (chromeless || title == null || title.length() == 0)
        chart.setTitle((TextTitle) null);
    else {
        chart.setTitle(Translator.translate(title));
        String titleFontSize = getSetting("titleFontSize");
        if (titleFontSize != null)
            try {
                float fontSize = Float.parseFloat(titleFontSize);
                TextTitle t = chart.getTitle();
                t.setFont(t.getFont().deriveFont(fontSize));
            } catch (Exception tfe) {
            }
    }

    if (chromeless || parameters.get("hideLegend") != null)
        chart.removeLegend();
    else {
        LegendTitle l = chart.getLegend();
        String legendFontSize = getSetting("legendFontSize");
        if (l != null && legendFontSize != null)
            try {
                float fontSize = Float.parseFloat(legendFontSize);
                l.setItemFont(l.getItemFont().deriveFont(fontSize));
            } catch (Exception lfe) {
            }
    }

    chart.getPlot().setNoDataMessage(resources.getString("No_Data_Message"));

    Axis xAxis = getHorizontalAxis(chart);
    if (xAxis != null) {
        if (parameters.get("hideTickLabels") != null || parameters.get("hideXTickLabels") != null) {
            xAxis.setTickLabelsVisible(false);
        } else if (parameters.get("tickLabelFontSize") != null
                || parameters.get("xTickLabelFontSize") != null) {
            String tfs = getParameter("xTickLabelFontSize");
            if (tfs == null)
                tfs = getParameter("tickLabelFontSize");
            float fontSize = Float.parseFloat(tfs);
            xAxis.setTickLabelFont(xAxis.getTickLabelFont().deriveFont(fontSize));
        }
    }

    Axis yAxis = getVerticalAxis(chart);
    if (yAxis != null) {
        if (parameters.get("hideTickLabels") != null || parameters.get("hideYTickLabels") != null) {
            yAxis.setTickLabelsVisible(false);
        } else if (parameters.get("tickLabelFontSize") != null
                || parameters.get("yTickLabelFontSize") != null) {
            String tfs = getParameter("yTickLabelFontSize");
            if (tfs == null)
                tfs = getParameter("tickLabelFontSize");
            float fontSize = Float.parseFloat(tfs);
            yAxis.setTickLabelFont(yAxis.getTickLabelFont().deriveFont(fontSize));
        }
    }

    String axisFontSize = getSetting("axisLabelFontSize");
    if (axisFontSize != null)
        try {
            float fontSize = Float.parseFloat(axisFontSize);
            if (xAxis != null)
                xAxis.setLabelFont(xAxis.getLabelFont().deriveFont(fontSize));
            if (yAxis != null)
                yAxis.setLabelFont(yAxis.getLabelFont().deriveFont(fontSize));
        } catch (Exception afs) {
        }

    ChartRenderingInfo info = (isHtmlMode() ? new ChartRenderingInfo() : null);
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = img.createGraphics();
    if ("auto".equals(getSetting("titleFontSize")))
        maybeAdjustTitleFontSize(chart, g2, width);
    chart.draw(g2, new Rectangle2D.Double(0, 0, width, height), info);
    g2.dispose();

    String outputFormat = getSetting("outputFormat");
    OutputStream imgOut;
    if (isHtmlMode()) {
        imgOut = PngCache.getOutputStream();
    } else {
        imgOut = outStream;
    }
    ImageIO.write(img, outputFormat, imgOut);
    imgOut.flush();
    imgOut.close();
    if (isHtmlMode())
        writeImageHtml(width, height, imgOut.hashCode(), info);
}