Example usage for org.jfree.chart.axis LogarithmicAxis setStrictValuesFlag

List of usage examples for org.jfree.chart.axis LogarithmicAxis setStrictValuesFlag

Introduction

In this page you can find the example usage for org.jfree.chart.axis LogarithmicAxis setStrictValuesFlag.

Prototype

public void setStrictValuesFlag(boolean flgVal) 

Source Link

Document

Sets the 'strictValuesFlag' flag; if true and 'allowNegativesFlag' is false then this axis will throw a runtime exception if any of its values are less than or equal to zero; if false then the axis will adjust for values less than or equal to zero as needed.

Usage

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Logarithmic Axis Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    LogarithmicAxis logarithmicaxis = new LogarithmicAxis("X");
    logarithmicaxis.setExpTickLabelsFlag(true);
    logarithmicaxis.setStrictValuesFlag(false);
    LogarithmicAxis logarithmicaxis1 = new LogarithmicAxis("Y");
    logarithmicaxis1.setAllowNegativesFlag(true);
    logarithmicaxis1.setLog10TickLabelsFlag(true);
    xyplot.setDomainAxis(logarithmicaxis);
    xyplot.setRangeAxis(logarithmicaxis1);
    return jfreechart;
}

From source file:org.nbheaven.sqe.codedefects.dashboard.controlcenter.panels.Statistics.java

private static JFreeChart createOverviewPanel(DefaultCategoryDataset dataSet) {

    JFreeChart overview = org.jfree.chart.ChartFactory.createStackedBarChart(null, null, "CodeDefects", dataSet,
            PlotOrientation.HORIZONTAL, false, true, false);
    overview.setBorderVisible(false);/* w ww  . ja  va  2  s  . c  om*/
    overview.setBackgroundPaint(Color.WHITE);
    overview.setAntiAlias(true);
    overview.setNotify(true);

    CategoryPlot overviewPlot = overview.getCategoryPlot();
    overviewPlot.setRangeGridlinePaint(Color.BLACK);
    overviewPlot.setDomainGridlinePaint(Color.BLACK);
    overviewPlot.setBackgroundPaint(Color.WHITE);
    overviewPlot.setForegroundAlpha(0.7f);
    overviewPlot.setRangeAxisLocation(AxisLocation.getOpposite(overviewPlot.getRangeAxisLocation()));

    CategoryAxis domainAxis = overviewPlot.getDomainAxis();
    domainAxis.setVisible(true);

    LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects");
    rangeAxis.setLabel(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    overviewPlot.setRangeAxis(rangeAxis);

    CategoryItemRenderer categoryItemRenderer = new StackedBarRenderer(); //3D();
    //        categoryItemRenderers[0].setPaint(Color.RED);
    categoryItemRenderer.setSeriesPaint(0, Color.RED);
    categoryItemRenderer.setSeriesPaint(1, Color.ORANGE);
    categoryItemRenderer.setSeriesPaint(2, Color.YELLOW);

    categoryItemRenderer.setBaseItemLabelsVisible(true);

    overviewPlot.setRenderer(categoryItemRenderer);

    return overview;
}

From source file:net.sourceforge.subsonic.controller.UserChartController.java

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false,
            false, false);//  ww  w  .ja  v  a  2  s  .c o  m

    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}

From source file:net.sourceforge.subsonic.controller.FolderChartController.java

private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false,
            false, false);//from  ww  w. jav a 2 s  .  com
    CategoryPlot plot = chart.getCategoryPlot();
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_MIN_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setAllowNegativesFlag(true);
    //        rangeAxis.setTickUnit(new NumberTickUnit(.1, new DecimalFormat("##0%")));
    plot.setRangeAxis(rangeAxis);

    // Disable bar outlines.
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // Set up gradient paint for series.
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.gray, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, 11));
    renderer.setItemLabelAnchorOffset(-45.0);

    renderer.setSeriesItemLabelPaint(0, Color.white);
    renderer.setBaseItemLabelPaint(Color.white);

    // Rotate labels.
    CategoryAxis domainAxis = plot.getDomainAxis();
    //        domainAxis.setCategoryLabelPositions();
    //        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    return chart;
}

From source file:edu.gmu.cs.sim.util.media.chart.XYChartGenerator.java

protected void buildGlobalAttributes(LabelledList list) {

    // create the chart
    ((XYPlot) (chart.getPlot())).setDomainGridlinesVisible(false);
    ((XYPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
    ((XYPlot) (chart.getPlot())).setDomainGridlinePaint(new Color(200, 200, 200));
    ((XYPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200));

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);//from w  w w .  j  a va  2  s.  c  o  m
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

    list.add(new JLabel("X Label"), xLabel);

    yLabel = new PropertyField() {
        public String newValue(String newValue) {
            setYAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    yLabel.setValue(getYAxisLabel());

    list.add(new JLabel("Y Label"), yLabel);

    xLog = new JCheckBox();
    xLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (xLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(xLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                chart.getXYPlot().setDomainAxis(logAxis);
            } else {
                chart.getXYPlot().setDomainAxis(new NumberAxis(xLabel.getValue()));
            }
        }
    });

    yLog = new JCheckBox();
    yLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (yLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                chart.getXYPlot().setRangeAxis(logAxis);
            } else {
                chart.getXYPlot().setRangeAxis(new NumberAxis(yLabel.getValue()));
            }
        }
    });

    Box box = Box.createHorizontalBox();
    box.add(new JLabel("X"));
    box.add(xLog);
    box.add(new JLabel(" Y"));
    box.add(yLog);
    box.add(Box.createGlue());
    list.add(new JLabel("Log Axis"), box);

    final JCheckBox xgridlines = new JCheckBox();
    xgridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                chart.getXYPlot().setDomainGridlinesVisible(true);
            } else {
                chart.getXYPlot().setDomainGridlinesVisible(false);
            }
        }
    };
    xgridlines.addItemListener(il);

    final JCheckBox ygridlines = new JCheckBox();
    ygridlines.setSelected(false);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                chart.getXYPlot().setRangeGridlinesVisible(true);
            } else {
                chart.getXYPlot().setRangeGridlinesVisible(false);
            }
        }
    };
    ygridlines.addItemListener(il);

    box = Box.createHorizontalBox();
    box.add(new JLabel("X"));
    box.add(xgridlines);
    box.add(new JLabel(" Y"));
    box.add(ygridlines);
    box.add(Box.createGlue());
    list.add(new JLabel("Grid Lines"), box);
}

From source file:sim.util.media.chart.XYChartGenerator.java

protected void buildGlobalAttributes(LabelledList list) {

    // create the chart
    ((XYPlot) (chart.getPlot())).setDomainGridlinesVisible(false);
    ((XYPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
    ((XYPlot) (chart.getPlot())).setDomainGridlinePaint(new Color(200, 200, 200));
    ((XYPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200));

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);/*  www.  j a v a2 s.  c  o m*/
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

    list.add(new JLabel("X Label"), xLabel);

    yLabel = new PropertyField() {
        public String newValue(String newValue) {
            setYAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    yLabel.setValue(getYAxisLabel());

    list.add(new JLabel("Y Label"), yLabel);

    xLog = new JCheckBox();
    xLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (xLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(xLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                chart.getXYPlot().setDomainAxis(logAxis);
            } else
                chart.getXYPlot().setDomainAxis(new NumberAxis(xLabel.getValue()));
        }
    });

    yLog = new JCheckBox();
    yLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (yLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                chart.getXYPlot().setRangeAxis(logAxis);
            } else
                chart.getXYPlot().setRangeAxis(new NumberAxis(yLabel.getValue()));
        }
    });

    Box box = Box.createHorizontalBox();
    box.add(new JLabel("X"));
    box.add(xLog);
    box.add(new JLabel(" Y"));
    box.add(yLog);
    box.add(Box.createGlue());
    list.add(new JLabel("Log Axis"), box);

    final JCheckBox xgridlines = new JCheckBox();
    xgridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                chart.getXYPlot().setDomainGridlinesVisible(true);
            } else {
                chart.getXYPlot().setDomainGridlinesVisible(false);
            }
        }
    };
    xgridlines.addItemListener(il);

    final JCheckBox ygridlines = new JCheckBox();
    ygridlines.setSelected(false);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                chart.getXYPlot().setRangeGridlinesVisible(true);
            } else {
                chart.getXYPlot().setRangeGridlinesVisible(false);
            }
        }
    };
    ygridlines.addItemListener(il);

    box = Box.createHorizontalBox();
    box.add(new JLabel("X"));
    box.add(xgridlines);
    box.add(new JLabel(" Y"));
    box.add(ygridlines);
    box.add(Box.createGlue());
    list.add(new JLabel("Grid Lines"), box);
}

From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java

public HistoChartPanel(final JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom,
        boolean tooltips, final ModelMaker modelMaker) {
    super(chart, properties, save, print, zoom, tooltips);
    this.modelMaker = modelMaker;
    // horizontal zoom doesn't work, by setting false we don't get bogus menu item
    //      setHorizontalZoom(false);
    //      setVerticalZoom(true);
    final JCheckBoxMenuItem logYScale = new JCheckBoxMenuItem(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.test.logscale.y"));
    logYScale.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot p = (CategoryPlot) chart.getPlot();
            Axis oldAxis = p.getRangeAxis();
            if (logYScale.isSelected()) {
                LogarithmicAxis yAxis = new LogarithmicAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"));
                yAxis.setStrictValuesFlag(false);
                p.setRangeAxis(yAxis);/*from www. j a  va 2s . com*/
            } else {
                p.setRangeAxis(new NumberAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs")));
            }
            oldAxis.setPlot(null);
            chartChanged(new ChartChangeEvent(this));
        }
    });
    JPopupMenu popup = getPopupMenu();
    popup.addSeparator();
    popup.add(logYScale);
    popup.addSeparator();
    select = new JMenu("Select");
    final JMenuItem all = new JMenuItem("All");
    select.add(all);
    final JMenuItem cmDiffer = new JMenuItem("Human marked differ");
    select.add(cmDiffer);
    final JMenuItem cmHold = new JMenuItem("Human marked hold");
    select.add(cmHold);
    final JMenuItem cmMatch = new JMenuItem("Human marked match");
    select.add(cmMatch);
    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
            filter.reset();
            filter.setFromPercentage(rangeFrom);
            filter.setToPercentage(rangeTo);
            Object src = ev.getSource();
            if (src != all) {
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                if (src == cmDiffer) {
                    b[Decision.DIFFER.toInt()] = true;
                } else if (src == cmHold) {
                    b[Decision.HOLD.toInt()] = true;
                } else if (src == cmMatch) {
                    b[Decision.MATCH.toInt()] = true;
                }
                filter.setHumanDecision(b);
            }
            modelMaker.filterMarkedRecordPairList();
        }
    };
    all.addActionListener(l);
    cmDiffer.addActionListener(l);
    cmHold.addActionListener(l);
    cmMatch.addActionListener(l);
    popup.add(select);
    addChartMouseListener(new ChartMouseListener() {
        public void chartMouseClicked(ChartMouseEvent evt) {
            ChartEntity e = evt.getEntity();
            if (e instanceof CategoryItemEntity) {
                CategoryItemEntity c = (CategoryItemEntity) e;
                int cat = c.getCategoryIndex();
                HistoCategoryDataset data = (HistoCategoryDataset) ((CategoryPlot) getChart().getPlot())
                        .getDataset();
                int len = data.getColumnCount();
                float step = 1f / len;
                rangeFrom = cat * step;
                rangeTo = rangeFrom + step;
                ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
                filter.reset();
                filter.setFromPercentage(rangeFrom);
                filter.setToPercentage(rangeTo);
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                int series = c.getSeries();
                if (data.isIncludeHolds() && series != 0) {
                    if (series == 1) {
                        series = 2;
                    } else {
                        series = 1;
                    }
                }
                b[series] = true;
                filter.setHumanDecision(b);
                modelMaker.filterMarkedRecordPairList();

            }
        }

        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });
}

From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java

/** Creates new form SQEHistoryPanel */
public SQEHistoryPanel() {
    historyChart = org.jfree.chart.ChartFactory.createStackedXYAreaChart(null, "Snapshot", "CodeDefects",
            perProjectDataSet, PlotOrientation.VERTICAL, false, true, false);
    historyChart.setBackgroundPaint(Color.WHITE);
    historyChart.getXYPlot().setRangeGridlinePaint(Color.BLACK);
    historyChart.getXYPlot().setDomainGridlinePaint(Color.BLACK);
    historyChart.getXYPlot().setBackgroundPaint(Color.WHITE);

    XYPlot plot = historyChart.getXYPlot();
    plot.setForegroundAlpha(0.7f);//from w  w w.  j  av  a 2 s  .c  o  m
    //        plot.getRenderer();

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects");
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setRangeAxis(rangeAxis);

    StackedXYAreaRenderer2 categoryItemRenderer = new StackedXYAreaRenderer2(); //3D();
    categoryItemRenderer.setSeriesPaint(0, Color.RED);
    categoryItemRenderer.setSeriesPaint(1, Color.ORANGE);
    categoryItemRenderer.setSeriesPaint(2, Color.YELLOW);

    plot.setRenderer(categoryItemRenderer);

    ChartPanel historyChartPanel = new ChartPanel(historyChart);
    historyChartPanel.setBorder(null);
    historyChartPanel.setPreferredSize(new Dimension(150, 200));
    historyChartPanel.setBackground(Color.WHITE);
    initComponents();

    historyView.setLayout(new BorderLayout());
    historyView.add(historyChartPanel, BorderLayout.CENTER);

    JPanel selectorPanel = new JPanel();
    selectorPanel.setOpaque(false);

    GroupLayout layout = new GroupLayout(selectorPanel);
    selectorPanel.setLayout(layout);

    // Turn on automatically adding gaps between components
    layout.setAutocreateGaps(true);

    // Turn on automatically creating gaps between components that touch
    // the edge of the container and the container.
    layout.setAutocreateContainerGaps(true);

    ParallelGroup horizontalParallelGroup = layout.createParallelGroup(GroupLayout.LEADING);
    SequentialGroup verticalSequentialGroup = layout.createSequentialGroup();

    layout.setHorizontalGroup(layout.createSequentialGroup().add(horizontalParallelGroup));

    layout.setVerticalGroup(verticalSequentialGroup);

    clearHistoryButton = new JButton();
    clearHistoryButton.setEnabled(false);
    clearHistoryButton.setIcon(ImageUtilities
            .image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/codedefects/history/resources/trash.png")));
    clearHistoryButton.setOpaque(false);
    clearHistoryButton.setFocusPainted(false);
    clearHistoryButton.setToolTipText(
            NbBundle.getBundle("org/nbheaven/sqe/codedefects/history/controlcenter/panels/Bundle")
                    .getString("HINT_clear_button"));
    horizontalParallelGroup.add(clearHistoryButton);
    verticalSequentialGroup.add(clearHistoryButton);
    clearHistoryButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (null != activeHistory) {
                activeHistory.clear();
            }
        }

    });

    Component createVerticalStrut = Box.createVerticalStrut(10);

    horizontalParallelGroup.add(createVerticalStrut);
    verticalSequentialGroup.add(createVerticalStrut);

    for (final QualityProvider provider : SQEUtilities.getProviders()) {
        final JToggleButton providerButton = new JToggleButton();
        providerButton.setIcon(provider.getIcon());
        providerButton.setOpaque(false);
        providerButton.setFocusPainted(false);
        horizontalParallelGroup.add(providerButton);
        verticalSequentialGroup.add(providerButton);
        ActionListener listener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (providerButton.isSelected()) {
                    addSelectedProvider(provider);
                } else {
                    removeSelectedProvider(provider);
                }
                updateView();
            }
        };
        providerButton.addActionListener(listener);
        addSelectedProvider(provider);
        providerButton.setSelected(true);
    }

    historyView.add(selectorPanel, BorderLayout.EAST);
}

From source file:sim.util.media.chart.BoxPlotGenerator.java

protected void buildGlobalAttributes(LabelledList list) {
    // create the chart
    ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
    ((CategoryPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200));

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);/*w ww  .ja v  a 2 s .  c om*/
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

    list.add(new JLabel("X Label"), xLabel);

    yLabel = new PropertyField() {
        public String newValue(String newValue) {
            setYAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    yLabel.setValue(getYAxisLabel());

    list.add(new JLabel("Y Label"), yLabel);

    yLog = new JCheckBox();
    yLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (yLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                ((CategoryPlot) (chart.getPlot())).setRangeAxis(logAxis);
            } else
                ((CategoryPlot) (chart.getPlot())).setRangeAxis(new NumberAxis(yLabel.getValue()));
        }
    });

    list.add(new JLabel("Y Log Axis"), yLog);

    final JCheckBox ygridlines = new JCheckBox();
    ygridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(true);
            } else {
                ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
            }
        }
    };
    ygridlines.addItemListener(il);

    // JFreeChart's Box Plots look awful when wide because the mean
    // circle is based on the width of the bar to the exclusion of all
    // else.  So I've restricted the width to be no more than 0.4, and 0.1
    // is the suggested default.

    final double INITIAL_WIDTH = 0.1;
    final double MAXIMUM_RATIONAL_WIDTH = 0.4;

    maximumWidthField = new NumberTextField(INITIAL_WIDTH, 2.0, 0) {
        public double newValue(double newValue) {
            if (newValue <= 0.0 || newValue > MAXIMUM_RATIONAL_WIDTH)
                newValue = currentValue;
            ((BoxAndWhiskerRenderer) (((CategoryPlot) (chart.getPlot())).getRenderer()))
                    .setMaximumBarWidth(newValue);
            //update();
            return newValue;
        }
    };
    list.addLabelled("Max Width", maximumWidthField);

    Box box = Box.createHorizontalBox();
    box.add(new JLabel(" Y"));
    box.add(ygridlines);
    box.add(Box.createGlue());
    list.add(new JLabel("Y Grid Lines"), ygridlines);

    mean = new JCheckBox();
    mean.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setMeanVisible(mean.isSelected());
        }
    };
    mean.addItemListener(il);

    median = new JCheckBox();
    median.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setMedianVisible(median.isSelected());
        }
    };
    median.addItemListener(il);

    list.add(new JLabel("Mean"), mean);
    list.add(new JLabel("Median"), median);

    final JCheckBox horizontal = new JCheckBox();
    horizontal.setSelected(false);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot plot = (CategoryPlot) (chart.getPlot());
            if (e.getStateChange() == ItemEvent.SELECTED) {
                plot.setOrientation(PlotOrientation.HORIZONTAL);
            } else {
                plot.setOrientation(PlotOrientation.VERTICAL);
            }
            //updateGridLines();
        }
    };
    horizontal.addItemListener(il);

    list.add(new JLabel("Horizontal"), horizontal);

    final JCheckBox whiskersUseFillColorButton = new JCheckBox();
    whiskersUseFillColorButton.setSelected(false);
    whiskersUseFillColorButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setUseOutlinePaintForWhiskers(!whiskersUseFillColorButton.isSelected());
        }
    });

    box = Box.createHorizontalBox();
    box.add(new JLabel(" Colored"));
    box.add(whiskersUseFillColorButton);
    box.add(Box.createGlue());
    list.add(new JLabel("Whiskers"), box);
}

From source file:edu.gmu.cs.sim.util.media.chart.BoxPlotGenerator.java

protected void buildGlobalAttributes(LabelledList list) {
    // create the chart
    ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
    ((CategoryPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200));

    xLabel = new PropertyField() {
        public String newValue(String newValue) {
            setXAxisLabel(newValue);//  w  ww . j  a v  a  2 s . c o  m
            getChartPanel().repaint();
            return newValue;
        }
    };
    xLabel.setValue(getXAxisLabel());

    list.add(new JLabel("X Label"), xLabel);

    yLabel = new PropertyField() {
        public String newValue(String newValue) {
            setYAxisLabel(newValue);
            getChartPanel().repaint();
            return newValue;
        }
    };
    yLabel.setValue(getYAxisLabel());

    list.add(new JLabel("Y Label"), yLabel);

    yLog = new JCheckBox();
    yLog.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (yLog.isSelected()) {
                LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue());
                logAxis.setStrictValuesFlag(false);
                ((CategoryPlot) (chart.getPlot())).setRangeAxis(logAxis);
            } else {
                ((CategoryPlot) (chart.getPlot())).setRangeAxis(new NumberAxis(yLabel.getValue()));
            }
        }
    });

    list.add(new JLabel("Y Log Axis"), yLog);

    final JCheckBox ygridlines = new JCheckBox();
    ygridlines.setSelected(false);
    ItemListener il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(true);
            } else {
                ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false);
            }
        }
    };
    ygridlines.addItemListener(il);

    // JFreeChart's Box Plots look awful when wide because the mean
    // circle is based on the width of the bar to the exclusion of all
    // else.  So I've restricted the width to be no more than 0.4, and 0.1
    // is the suggested default.

    final double INITIAL_WIDTH = 0.1;
    final double MAXIMUM_RATIONAL_WIDTH = 0.4;

    maximumWidthField = new NumberTextField(INITIAL_WIDTH, 2.0, 0) {
        public double newValue(double newValue) {
            if (newValue <= 0.0 || newValue > MAXIMUM_RATIONAL_WIDTH) {
                newValue = currentValue;
            }
            ((BoxAndWhiskerRenderer) (((CategoryPlot) (chart.getPlot())).getRenderer()))
                    .setMaximumBarWidth(newValue);
            //update();
            return newValue;
        }
    };
    list.addLabelled("Max Width", maximumWidthField);

    Box box = Box.createHorizontalBox();
    box.add(new JLabel(" Y"));
    box.add(ygridlines);
    box.add(Box.createGlue());
    list.add(new JLabel("Y Grid Lines"), ygridlines);

    mean = new JCheckBox();
    mean.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setMeanVisible(mean.isSelected());
        }
    };
    mean.addItemListener(il);

    median = new JCheckBox();
    median.setSelected(true);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setMedianVisible(median.isSelected());
        }
    };
    median.addItemListener(il);

    list.add(new JLabel("Mean"), mean);
    list.add(new JLabel("Median"), median);

    final JCheckBox horizontal = new JCheckBox();
    horizontal.setSelected(false);
    il = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot plot = (CategoryPlot) (chart.getPlot());
            if (e.getStateChange() == ItemEvent.SELECTED) {
                plot.setOrientation(PlotOrientation.HORIZONTAL);
            } else {
                plot.setOrientation(PlotOrientation.VERTICAL);
            }
            //updateGridLines();
        }
    };
    horizontal.addItemListener(il);

    list.add(new JLabel("Horizontal"), horizontal);

    final JCheckBox whiskersUseFillColorButton = new JCheckBox();
    whiskersUseFillColorButton.setSelected(false);
    whiskersUseFillColorButton.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot()))
                    .getRenderer());
            renderer.setUseOutlinePaintForWhiskers(!whiskersUseFillColorButton.isSelected());
        }
    });

    box = Box.createHorizontalBox();
    box.add(new JLabel(" Colored"));
    box.add(whiskersUseFillColorButton);
    box.add(Box.createGlue());
    list.add(new JLabel("Whiskers"), box);
}