Example usage for org.jfree.chart.axis NumberAxis setStandardTickUnits

List of usage examples for org.jfree.chart.axis NumberAxis setStandardTickUnits

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setStandardTickUnits.

Prototype

public void setStandardTickUnits(TickUnitSource source) 

Source Link

Document

Sets the source for obtaining standard tick units for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.eumetsat.metop.visat.IasiInfoView.java

private void configureSpectrumPlotYAxis(NumberAxis axis) {
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis.setLabel("Brightness Temperature (K)");
    axis.setRange(new Range(180.0, 320.0), true, false);
}

From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java

private void buildLegendChart(int nbValues) {
    this.legendValues = new int[nbValues + 1];
    this.legendValues[0] = 0;
    int offset = 255 / nbValues;
    int step = offset;

    if (this.scaleMode == Chart.Scale.LOGARITHMIC) {
        double logStep = (Math.log(this.maxValue) / Math.log(2)) / nbValues;
        for (int i = 1; i < (nbValues + 1); i++) {
            this.legendValues[i] = (int) Math.pow(2, logStep * i);
        }/*from  w w  w. j  ava 2 s .com*/
    } else { // Linear scale mode
        for (int i = 1; i < (nbValues + 1); i++) {
            this.legendValues[i] = (step * this.maxValue) / 255;
            step += offset;
        }
    }

    final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createLegendDataSet());

    final JFreeChart chart = ChartFactory.createBubbleChart("", "", "", dataset, PlotOrientation.VERTICAL, true,
            true, false);

    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE));
    chart.removeLegend();

    // Perform customizations starts here ...
    final XYPlot plot1 = chart.getXYPlot();

    plot1.setDomainGridlinesVisible(false);
    plot1.setRangeGridlinesVisible(false);
    plot1.setForegroundAlpha(0.5f);
    plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel()));
    plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel()));

    // Custumize the domain axis ( x )
    final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-1, 1);
    domainAxis.setVisible(false);

    // Custumize the range axis ( y )
    final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis();
    rangeAxis.setTickUnit(new CustomTickUnit(rangeAxis.getTickUnit().getSize()));
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(-1, this.legendValues.length);
    rangeAxis.setTickLabelsVisible(true);
    rangeAxis.setTickMarkInsideLength(4);

    // Create custom renderer
    StandardXYItemRenderer ren = new CustomRenderer(true);
    ren.setSeriesItemLabelPaint(0, Color.BLUE);
    plot1.setRenderer(ren);
    plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);

    this.legendChart = chart;
}

From source file:userInteface.Patient.ManageVitalSignsJPanel.java

private void createChart() {
    DefaultCategoryDataset vitalSignDataset = new DefaultCategoryDataset();
    int selectedRow = viewPatientsJTable.getSelectedRow();
    Person person = (Person) viewPatientsJTable.getValueAt(selectedRow, 0);
    Patient patient = person.getPatient();
    if (patient == null) {
        JOptionPane.showMessageDialog(this, "Patient not created, Please create Patient first.", "Error",
                JOptionPane.ERROR_MESSAGE);
        return;/*from  ww  w.j  a va  2  s.c o m*/
    }

    ArrayList<VitalSign> vitalSignList = patient.getVitalSignHistory().getHistory();
    /*At least 2 vital sign records needed to show chart */
    if (vitalSignList.isEmpty() || vitalSignList.size() == 1) {
        JOptionPane.showMessageDialog(this,
                "No vital signs or only one vital sign found. At least 2 vital sign records needed to show chart!",
                "Warning", JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    for (VitalSign vitalSign : vitalSignList) {
        vitalSignDataset.addValue(vitalSign.getRespiratoryRate(), "RR", vitalSign.getTimestamp());
        vitalSignDataset.addValue(vitalSign.getHeartRate(), "HR", vitalSign.getTimestamp());
        vitalSignDataset.addValue(vitalSign.getBloodPressure(), "BP", vitalSign.getTimestamp());
        vitalSignDataset.addValue(vitalSign.getWeight(), "WT", vitalSign.getTimestamp());
    }

    JFreeChart vitalSignChart = ChartFactory.createBarChart3D("Vital Sign Chart", "Time Stamp", "Rate",
            vitalSignDataset, PlotOrientation.VERTICAL, true, false, false);
    vitalSignChart.setBackgroundPaint(Color.white);
    CategoryPlot vitalSignChartPlot = vitalSignChart.getCategoryPlot();
    vitalSignChartPlot.setBackgroundPaint(Color.lightGray);

    CategoryAxis vitalSignDomainAxis = vitalSignChartPlot.getDomainAxis();
    vitalSignDomainAxis
            .setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    NumberAxis vitalSignRangeAxis = (NumberAxis) vitalSignChartPlot.getRangeAxis();
    vitalSignRangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartFrame chartFrame = new ChartFrame("Chart", vitalSignChart);
    chartFrame.setVisible(true);
    chartFrame.setSize(500, 500);

}

From source file:PhysicDrawing.PhysicGraph.java

private JFreeChart createAccelerationChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart("Acceleration", // chart title
            "X - Time (s)", // x axis label
            "Y - A (px/s^2)", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//  w  w w .  java2 s  .  c  o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white); // vertical line 
    plot.setRangeGridlinePaint(Color.white); // horizontal line 

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true); // (index , value)
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesPaint(0, Color.RED, true);
    renderer.setSeriesPaint(1, Color.black, true);
    renderer.setSeriesPaint(2, Color.white, true);
    renderer.setSeriesShape(0, new Rectangle(1, 1));
    renderer.setSeriesShape(1, new Rectangle(1, 1));

    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.rapidminer.gui.plotter.charts.SeriesChartPlotter.java

private JFreeChart createChart(XYDataset dataset, boolean createLegend) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, createLegend, // include legend
            true, // tooltips
            false // urls
    );/*from www.  j  a v  a2s.c  o  m*/

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    DeviationRenderer renderer = new DeviationRenderer(true, false);

    // colors
    if (dataset.getSeriesCount() == 1) {
        renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        renderer.setSeriesPaint(0, getColorProvider().getPointColor(1.0d));
    } else { // special case needed for avoiding devision by zero
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesStroke(i, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            renderer.setSeriesPaint(i,
                    getColorProvider().getPointColor(1.0d - i / (double) (dataset.getSeriesCount() - 1)));
        }
    }
    // background for bounds
    if (plotBounds) {
        float[] dashArray = new float[] { 7, 14 };
        renderer.setSeriesStroke(boundsSeriesIndex,
                new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dashArray, 0));
        renderer.setSeriesPaint(boundsSeriesIndex, Color.GRAY.brighter());
        renderer.setSeriesFillPaint(boundsSeriesIndex, Color.GRAY);
    }
    // alpha
    renderer.setAlpha(0.25f);

    plot.setRenderer(renderer);

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    if (axis[INDEX] < 0) {
        xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        xAxis.setLabel(SERIESINDEX_LABEL);
        Range range = getRangeForName(SERIESINDEX_LABEL);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    } else {
        xAxis.setLabel(dataTable.getColumnName(axis[INDEX]));
        Range range = getRangeForDimension(axis[INDEX]);
        if (range == null) {
            xAxis.setAutoRange(true);
            xAxis.setAutoRangeStickyZero(false);
            xAxis.setAutoRangeIncludesZero(false);
        } else {
            xAxis.setRange(range, true, false);
        }
    }

    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel(VALUEAXIS_LABEL);
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));
    setYAxisRange(yAxis);

    yAxis.setLabelFont(LABEL_FONT_BOLD);
    yAxis.setTickLabelFont(LABEL_FONT);

    return chart;
}

From source file:PhysicDrawing.PhysicGraph.java

/**
 * Creates a chart.// w  ww. j av a 2 s.c  o m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createDisplacementChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart("Displacement", // chart title
            "X - Time (s)", // x axis label
            "Y - S (px)", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            true // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white); // vertical line 
    plot.setRangeGridlinePaint(Color.white); // horizontal line 

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true); // (index , value)
    renderer.setSeriesLinesVisible(1, true);
    // renderer.setSeriesShapesVisible(1, true);
    // renderer.setSeriesFillPaint(2, Color.black);
    renderer.setSeriesPaint(0, Color.RED, true);
    renderer.setSeriesPaint(1, Color.black, true);
    renderer.setSeriesPaint(2, Color.white, true);
    renderer.setSeriesShape(0, new Rectangle(1, 1));
    renderer.setSeriesShape(1, new Rectangle(1, 1));

    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:PhysicDrawing.PhysicGraph.java

/**
 * Creates a chart./* ww w  . j  a va 2  s  .  c  o m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createVelocityChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart("Velocity", // chart title
            "X - Time (s)", // x axis label
            "Y - V (px/s)", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white); // vertical line 
    plot.setRangeGridlinePaint(Color.white); // horizontal line 

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true); // (index , value)
    renderer.setSeriesLinesVisible(1, true);
    // renderer.setSeriesShapesVisible(1, true);
    // renderer.setSeriesFillPaint(2, Color.black);
    renderer.setSeriesPaint(0, Color.RED, true);
    renderer.setSeriesPaint(1, Color.black, true);
    renderer.setSeriesPaint(2, Color.white, true);
    renderer.setSeriesShape(0, new Rectangle(1, 1));
    renderer.setSeriesShape(1, new Rectangle(1, 1));

    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:charts.Chart.java

public static void PlotParallelCoordinates(String title, String x_axis_label, String y_axis_label, float[][] Md,
        int classes, int[] features, Vector featurestitles, Vector datatitles) {
    JFrame chartwindow = new JFrame(title);
    JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, null,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.black);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    int lines = Md.length;
    int columns = Md[0].length;

    LineAndShapeRenderer[] lineandshaperenderer = new LineAndShapeRenderer[classes];

    for (int i = 0; i < lineandshaperenderer.length; i++) {
        lineandshaperenderer[i] = new LineAndShapeRenderer();
        lineandshaperenderer[i].setShapesVisible(true);
        lineandshaperenderer[i].setDrawOutlines(true);
        lineandshaperenderer[i].setUseFillPaint(true);
        lineandshaperenderer[i].setFillPaint(Color.white);
        lineandshaperenderer[i].setBaseStroke(new BasicStroke(2.0f));
    }//w  ww .j av  a 2s.co  m
    int count = 0;
    for (int i = 0; i < lines; i++) {
        int classe = ((int) Md[i][columns - 1]);
        DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset();
        int j = 0;
        double value = 0;
        while (j < features.length) {
            /*value recebe o valor da linha i e da coluna especificada
            pelo usuario, por meio do parametro de chegada features[]*/
            value = Md[i][features[j]];

            String strclasse = String.valueOf(classe);
            //especifico Marie-Anne
            /*
            if (classe == 0) {
            strclasse = "thi1";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.RED);
            Shape s0 = new Rectangle2D.Float(-3f, -3f, 6f, 6f);
            lineandshaperenderer[classe].setSeriesShape(0, s0);
            } else if (classe == 1) {
            strclasse = "controle";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.PINK);
            Shape s1 = new Ellipse2D.Float(-3f, -3f, 6f, 6f);
            lineandshaperenderer[classe].setSeriesShape(0, s1);
            } else if (classe == 2) {
            strclasse = "fotossntese";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.GREEN);
            int[] x = {-3, 0, 3};
            int[] y = {-3, 3, -3};
            int n = 3;
            Shape s2 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesShape(0, s2);
            } else if (classe == 3) {
            strclasse = "respirao";
            int[] x = {-3, 0, 3};
            int[] y = {3, -3, 3};
            int n = 3;
            Shape s3 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesShape(0, s3);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.BLUE);
            } else if (classe == 4) {
            strclasse = "sntese de tiamina";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.BLACK);
            Shape s4 = new Rectangle2D.Float(-1f, -3f, 1f, 6f);
            lineandshaperenderer[classe].setSeriesShape(0, s4);
            } else if (classe == 5) {
            strclasse = "gliclise";
            int[] x = {-3, 0, 3, 0};
            int[] y = {0, -3, 0, 3};
            int n = 4;
            Shape s5 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.ORANGE);
            lineandshaperenderer[classe].setSeriesShape(0, s5);
            } else if (classe == 6) {
            strclasse = "AT4G34200";
            int[] x = {-3, 0, 3, 0};
            int[] y = {0, -3, 0, 3};
            int n = 4;
            Shape s5 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.MAGENTA);
            lineandshaperenderer[classe].setSeriesShape(0, s5);
            } else if (classe == 7) {
            strclasse = "AT2G36530";
            int[] x = {-3, 0, 3, 0};
            int[] y = {0, -3, 0, 3};
            int n = 4;
            Shape s5 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.CYAN);
            lineandshaperenderer[classe].setSeriesShape(0, s5);
            }
             */

            if (featurestitles != null) {
                if (datatitles != null) {
                    dataset.addValue(value, strclasse, (String) featurestitles.get(features[j] + 1));
                    //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c + 1));
                } else {
                    dataset.addValue(value, strclasse, (String) featurestitles.get(features[j]));
                    //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c));
                }
            } else {
                dataset.addValue(value, strclasse, String.valueOf(features[j]));
                //datasets[i].addValue(Mo[lineindex[i]][c], label, String.valueOf(c));
            }
            //dataset.addValue(value, String.valueOf(classe), String.valueOf(features[j]));
            j++;
        }
        categoryplot.setDataset(count, dataset);
        categoryplot.setRenderer(count, lineandshaperenderer[classe]);
        count++;
    }
    LegendItemCollection legends = categoryplot.getLegendItems();
    LegendItemCollection newlegends = new LegendItemCollection();
    for (int i = 0; i < classes; i++) {
        int l = 0;
        //especifico Marie-Anne
        String label1 = null;
        if (i == 0) {
            label1 = "thi1";
        } else if (i == 1) {
            label1 = "controle";
        } else if (i == 2) {
            label1 = "fotossntese";
        } else if (i == 3) {
            label1 = "respirao";
        } else if (i == 4) {
            label1 = "sntese de tiamina";
        } else if (i == 5) {
            label1 = "gliclise";
        } else if (i == 6) {
            label1 = "AT4G34200";
        } else if (i == 7) {
            label1 = "AT2G36530";
        }

        //String label1 = String.valueOf(i);
        String label2 = null;
        boolean found = false;
        do {
            label2 = legends.get(l).getLabel();
            if (label1.equalsIgnoreCase(label2)) {
                found = true;
            } else {
                l++;
            }
        } while (!found && (l < lines));
        if (found) {
            //newlegends.add(legends.get(l));
            LegendItem li = new LegendItem(legends.get(l).getLabel(), legends.get(l).getDescription(),
                    legends.get(l).getToolTipText(), legends.get(l).getURLText(),
                    legends.get(l).isShapeVisible(), legends.get(l).getShape(), legends.get(l).isShapeFilled(),
                    legends.get(l).getFillPaint(), legends.get(l).isShapeOutlineVisible(),
                    legends.get(l).getOutlinePaint(), legends.get(l).getOutlineStroke(),
                    legends.get(l).isLineVisible(), legends.get(l).getLine(), legends.get(l).getLineStroke(),
                    legends.get(l).getLinePaint());
            newlegends.add(li);
        }
    }
    categoryplot.setFixedLegendItems(newlegends);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
}

From source file:edu.illinois.ncsa.datawolf.service.ExecutionsResource.java

private JFreeChart createChart(String xVariable, String yVariable, XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart("Convergence Graph", xVariable, yVariable, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.WHITE);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.BoxAndWhiskerChartDemo1.java

/**
 * Creates a sample chart./*  w  w w .ja v a 2 s .  co  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(BoxAndWhiskerCategoryDataset dataset) {

    CategoryAxis domainAxis = new CategoryAxis(null);
    NumberAxis rangeAxis = new NumberAxis(rangeLabel);
    BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
    JFreeChart chart = new JFreeChart(chartTitle, plot);

    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setLegendItemLabelGenerator(
            new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT));

    //RowCount -- serie count
    if (dataset.getColumnCount() * dataset.getRowCount() < 5) {

        domainAxis.setLowerMargin(0.2);
        domainAxis.setUpperMargin(0.2);
        if (dataset.getColumnCount() == 1)
            renderer.setItemMargin(0.5);
        //   domainAxis.setCategoryMargin(domainAxis.getCategoryMargin()*2);
        /*         
        System.out.println("1lowerMargin="+domainAxis.getLowerMargin());
        System.out.println("ItemMargin="+renderer.getItemMargin());
        System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/

    }

    else if (dataset.getColumnCount() * dataset.getRowCount() < 10) {
        domainAxis.setLowerMargin(domainAxis.getLowerMargin() * 2);
        domainAxis.setUpperMargin(domainAxis.getUpperMargin() * 2);
        if (dataset.getColumnCount() == 1)
            renderer.setItemMargin(renderer.getItemMargin() * 2);
        else
            domainAxis.setCategoryMargin(domainAxis.getCategoryMargin() * 2);

        /*System.out.println("2lowerMargin="+domainAxis.getLowerMargin());
        System.out.println("ItemMargin="+renderer.getItemMargin());
        System.out.println("CategoryMargin="+domainAxis.getCategoryMargin());*/

    }

    if (legendPanelOn)
        chart.removeLegend();
    return chart;

}