Example usage for org.jfree.chart.renderer.category BoxAndWhiskerRenderer setBaseToolTipGenerator

List of usage examples for org.jfree.chart.renderer.category BoxAndWhiskerRenderer setBaseToolTipGenerator

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.category BoxAndWhiskerRenderer setBaseToolTipGenerator.

Prototype

@Override
public void setBaseToolTipGenerator(CategoryToolTipGenerator generator) 

Source Link

Document

Sets the base tool tip generator and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java

private static JFreeChart createBoxAndWhiskerChart(BoxAndWhiskerCategoryDataset dataset) {
    CategoryAxis categoryAxis = new CategoryAxis(xAxisLabel);
    NumberAxis valueAxis = new NumberAxis(yAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart("BoxAndWhiskerCategory Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot,
            legend);// w ww .  jav a 2  s.  co  m
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    return chart;
}

From source file:org.gephi.ui.utils.ChartsUtils.java

/**
 * Build a new box-plot from an array of numbers using a default title and yLabel.
 * String dataName will be used for xLabel.
 * @param numbers Numbers for building box-plot
 * @param dataName Name of the numbers data
 * @return Prepared box-plot//from ww w.  j av  a  2 s .  c o  m
 */
public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) {
    if (numbers == null || numbers.length == 0) {
        return null;
    }
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    final ArrayList<Number> list = new ArrayList<Number>();
    list.addAll(Arrays.asList(numbers));

    final String valuesString = getMessage("ChartsUtils.report.box-plot.values");
    dataset.add(list, valuesString, "");

    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMeanVisible(false);
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.5);

    final CategoryAxis xAxis = new CategoryAxis(dataName);
    final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range"));
    yAxis.setAutoRangeIncludesZero(false);
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setRenderer(renderer);

    JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot);
    return boxPlot;
}

From source file:guineu.modules.visualization.intensityboxplot.IntensityBoxPlotFrame.java

public IntensityBoxPlotFrame(ParameterSet parameters) {
    super("", true, true, true, true);

    String title = "Intensity box plot [" + GuineuCore.getDesktop().getSelectedDataFiles()[0].getDatasetName()
            + "]";
    String xAxisLabel = parameters.getParameter(IntensityBoxPlotParameters.xAxisValueSource).getValue()
            .toString();/*w w w  . ja  v a 2  s  . c  o  m*/
    this.xAxisValueSource = parameters.getParameter(IntensityBoxPlotParameters.xAxisValueSource).getValue();
    // create dataset
    this.selectedFiles = parameters.getParameter(IntensityBoxPlotParameters.dataFiles).getValue();

    this.selectedRows = parameters.getParameter(IntensityBoxPlotParameters.selectedRows).getValue();

    this.dataset = this.createSampleDataset();
    // create new JFreeChart
    logger.finest("Creating new chart instance");
    //      chart = ChartFactory.createLineChart(title, xAxisLabel, "Intensity",
    //               dataset, PlotOrientation.VERTICAL, true, true, false);

    //  CategoryPlot plot = (CategoryPlot) chart.getPlot();

    // set renderer
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);
    // set tooltip generator               
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    //  plot.setRenderer(renderer);
    //  plot.setBackgroundPaint(Color.white);
    //   CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
    //  xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // set y axis properties

    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    NumberFormat yAxisFormat = new DecimalFormat("0.0E0");
    yAxis.setNumberFormatOverride(yAxisFormat);
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    final JFreeChart chart = new JFreeChart("Intensity Box plot", new Font("SansSerif", Font.BOLD, 14), plot,
            true);
    chart.setBackgroundPaint(Color.white);

    // create chart JPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);

    //                IntensityBoxPlotToolBar toolBar = new IntensityBoxPlotToolBar(this);
    //   add(toolBar, BorderLayout.EAST);

    // disable maximum size (we don't want scaling)
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    // set title properties
    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    LegendTitle legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setBorder(0, 0, 0, 0);

    // set shape provider
    IntensityBoxPlotDrawingSupplier shapeSupplier = new IntensityBoxPlotDrawingSupplier();

    plot.setDrawingSupplier(shapeSupplier);

    setTitle(title);
    setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
    setBackground(Color.white);
    pack();

}

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

protected void buildChart() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    // we build the chart manually rather than using ChartFactory
    // because we need to customize the getDataRange method below

    CategoryAxis categoryAxis = new CategoryAxis("");
    NumberAxis valueAxis = new NumberAxis("Untitled Y Axis");
    valueAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) {
        // Customizing this method in order to provide a bit of
        // vertical buffer.  Otherwise the bar chart box gets drawn
        // slightly off-chart, which looks really bad.

        public Range getDataRange(ValueAxis axis) {
            Range range = super.getDataRange(axis);
            if (range == null)
                return null;
            final double EXTRA_PERCENTAGE = 0.02;
            return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE);
        }//from w  w w. java2s .c  om
    };

    chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);

    chart.setAntiAlias(true);
    chartPanel = buildChartPanel(chart);
    setChartPanel(chartPanel);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}

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

protected void buildChart() {
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    // we build the chart manually rather than using ChartFactory
    // because we need to customize the getDataRange method below

    CategoryAxis categoryAxis = new CategoryAxis("");
    NumberAxis valueAxis = new NumberAxis("Untitled Y Axis");
    valueAxis.setAutoRangeIncludesZero(false);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer) {
        // Customizing this method in order to provide a bit of
        // vertical buffer.  Otherwise the bar chart box gets drawn
        // slightly off-chart, which looks really bad.

        public Range getDataRange(ValueAxis axis) {
            Range range = super.getDataRange(axis);
            if (range == null) {
                return null;
            }/*  w  ww .j ava  2 s . co m*/
            final double EXTRA_PERCENTAGE = 0.02;
            return Range.expand(range, EXTRA_PERCENTAGE, EXTRA_PERCENTAGE);
        }
    };

    chart = new JFreeChart("Untitled Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    ChartFactory.getChartTheme().apply(chart);

    chart.setAntiAlias(true);
    chartPanel = buildChartPanel(chart);
    setChartPanel(chartPanel);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}

From source file:at.ac.tuwien.inso.subcat.ui.widgets.DistributionChart.java

private void initCharts() {
    boxDataSet = new DefaultBoxAndWhiskerCategoryDataset();
    sizeDataSet = new DefaultCategoryDataset();

    // Box://from  w w  w.  j  av a 2s  .  com
    NumberAxis yAxis = new NumberAxis("Values");
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());

    boxPlot = new CategoryPlot(boxDataSet, null, yAxis, renderer);
    drawingSupplier = boxPlot.getDrawingSupplier();

    // Bar.
    NumberAxis rangeAxis2 = new NumberAxis("Values");
    rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    sizePlot = new CategoryPlot(sizeDataSet, null, rangeAxis2, renderer2);
    sizePlot.setDomainGridlinesVisible(true);
}

From source file:org.locationtech.udig.processingtoolbox.tools.BoxPlotDialog.java

private void updateChart(SimpleFeatureCollection features, String[] fields) {
    // Setup Box plot
    int fontStyle = java.awt.Font.BOLD;
    FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0];

    CategoryAxis xPlotAxis = new CategoryAxis(EMPTY); // Type
    xPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    xPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 12));

    NumberAxis yPlotAxis = new NumberAxis("Value"); // Value //$NON-NLS-1$
    yPlotAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12));
    yPlotAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10));
    yPlotAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMedianVisible(true);//  ww  w .  jav a 2  s. c o  m
    renderer.setMeanVisible(false);
    renderer.setFillBox(true);
    renderer.setSeriesFillPaint(0, java.awt.Color.CYAN);
    renderer.setBaseFillPaint(java.awt.Color.CYAN);
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    // Set the scatter data, renderer, and axis into plot
    CategoryDataset dataset = getDataset(features, fields);
    CategoryPlot plot = new CategoryPlot(dataset, xPlotAxis, yPlotAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setRangePannable(false);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setForegroundAlpha(0.85f);

    // Map the scatter to the first Domain and first Range
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    // 3. Setup Selection
    /*****************************************************************************************
     * CategoryAxis xSelectionAxis = new CategoryAxis(EMPTY);
     * xSelectionAxis.setTickMarksVisible(false); xSelectionAxis.setTickLabelsVisible(false);
     * 
     * NumberAxis ySelectionAxis = new NumberAxis(EMPTY);
     * ySelectionAxis.setTickMarksVisible(false); ySelectionAxis.setTickLabelsVisible(false);
     * 
     * BoxAndWhiskerRenderer selectionRenderer = new BoxAndWhiskerRenderer();
     * selectionRenderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 6, 6));
     * selectionRenderer.setSeriesPaint(0, java.awt.Color.RED); // dot
     * 
     * plot.setDataset(2, new DefaultBoxAndWhiskerCategoryDataset()); plot.setRenderer(2,
     * selectionRenderer); plot.setDomainAxis(2, xSelectionAxis); plot.setRangeAxis(2,
     * ySelectionAxis);
     * 
     * // Map the scatter to the second Domain and second Range plot.mapDatasetToDomainAxis(2,
     * 0); plot.mapDatasetToRangeAxis(2, 0);
     *****************************************************************************************/

    // 5. Finally, Create the chart with the plot and a legend
    java.awt.Font titleFont = new Font(fontData.getName(), fontStyle, 20);
    JFreeChart chart = new JFreeChart(EMPTY, titleFont, plot, false);
    chart.setBackgroundPaint(java.awt.Color.WHITE);
    chart.setBorderVisible(false);

    chartComposite.setChart(chart);
    chartComposite.forceRedraw();
}

From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java

/**    
 * Creates and returns a default instance of a box and whisker chart    
 * based on data from a {@link BoxAndWhiskerCategoryDataset}.    
 *    /* w w  w  .  ja va  2 s . com*/
 * @param title  the chart title (<code>null</code> permitted).    
 * @param categoryAxisLabel  a label for the category axis     
 *     (<code>null</code> permitted).    
 * @param valueAxisLabel  a label for the value axis (<code>null</code>     
 *     permitted).    
 * @param dataset  the dataset for the chart (<code>null</code> permitted).    
 * @param legend  a flag specifying whether or not a legend is required.    
 *    
 * @return A box and whisker chart.    
 *     
 * @since 1.0.4    
 */
public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel,
        BoxAndWhiskerCategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
}

From source file:KIDLYFactory.java

/**
 * Creates and returns a default instance of a box and whisker chart
 * based on data from a {@link BoxAndWhiskerCategoryDataset}.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  a label for the category axis
 *     (<code>null</code> permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *     permitted).//from   w ww.  ja va 2 s.  c o  m
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 *
 * @since 1.0.4
 */
public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel,
        BoxAndWhiskerCategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);

    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}

From source file:org.moeaframework.analysis.plot.Plot.java

/**
 * If the chart has not yet been initialized, creates a chart for
 * categorical data.  If the chart is already initialized, checks if the
 * chart is for categorical data./*from   ww  w. j  av a 2s.  c  o m*/
 * 
 * @throws FrameworkException if the chart does not support categorical data
 */
private void createCategoryPlot() {
    if (chart == null) {
        CategoryAxis xAxis = new CategoryAxis("");

        NumberAxis yAxis = new NumberAxis("Value");
        yAxis.setAutoRangeIncludesZero(false);

        final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
        renderer.setFillBox(true);
        renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());

        final CategoryPlot plot = new CategoryPlot();
        plot.setDomainAxis(xAxis);
        plot.setRangeAxis(yAxis);
        plot.setRenderer(renderer);

        chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
        ChartFactory.getChartTheme().apply(chart);
    } else if (!(chart.getPlot() instanceof CategoryPlot)) {
        throw new FrameworkException("Can not combine XY plot and categorial plot");
    }
}