Example usage for org.jfree.chart.renderer.xy XYBlockRenderer setBlockWidth

List of usage examples for org.jfree.chart.renderer.xy XYBlockRenderer setBlockWidth

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYBlockRenderer setBlockWidth.

Prototype

public void setBlockWidth(double width) 

Source Link

Document

Sets the width of the blocks used to represent each data item and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.Chromatogram1DHeatmapViewTopComponent.java

private XYPlot createPlot(ADataset2D<IChromatogram1D, IScan> ds) {
    XYBlockRenderer xybr = new XYBlockRenderer();
    IPaintScaleProvider ips = Lookup.getDefault().lookup(IPaintScaleProvider.class);
    ips.setMin(ds.getMinZ());/*from  w  ww.  j  a  v  a 2s  .c om*/
    ips.setMax(ds.getMaxZ());
    PaintScale ps = ips.getPaintScales().get(0);
    xybr.setPaintScale(ps);
    xybr.setDefaultEntityRadius(5);
    xybr.setBlockWidth(0.1);
    xybr.setBlockAnchor(RectangleAnchor.CENTER);
    xybr.setBlockHeight(1.0);
    RTUnit rtUnit = RTUnit.SECONDS;
    xybr.setToolTipGenerator(
            new StandardXYZToolTipGenerator("{0}: @({1}, {2}) = {3}", DecimalFormat.getNumberInstance(),
                    DecimalFormat.getNumberInstance(), DecimalFormat.getNumberInstance()));
    NumberAxis rt1 = new NumberAxis("Retention Time [" + rtUnit.name().toLowerCase() + "]");
    NumberAxis rt2 = new NumberAxis("M/Z");
    rt1.setAutoRange(false);
    rt1.setLowerBound(ds.getMinX());
    rt1.setUpperBound(ds.getMaxX());
    rt1.setRangeWithMargins(ds.getMinX(), ds.getMaxX());
    rt2.setFixedAutoRange(ds.getMaxX() - ds.getMinX());
    rt2.setAutoRange(false);
    rt2.setLowerBound(ds.getMinY());
    rt2.setUpperBound(ds.getMaxY());
    rt2.setFixedAutoRange(ds.getMaxY() - ds.getMinY());
    rt2.setRangeWithMargins(ds.getMinY(), ds.getMaxY());
    XYPlot heatmapPlot = new XYPlot(ds, rt1, rt2, xybr);
    heatmapPlot.setDomainPannable(true);
    heatmapPlot.setRangePannable(true);
    return heatmapPlot;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.BlockChart.java

/**
 * Creates a chart for the specified dataset.
 * //from ww  w .  j av  a  2s .  c o m
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");
    //Creates the xAxis with its label and style
    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setLabel(xLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    //Creates the yAxis with its label and style
    NumberAxis yAxis = new NumberAxis(yLabel);

    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setInverted(false);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setTickLabelsVisible(true);
    yAxis.setLabel(yLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    Color outboundCol = new Color(Integer.decode(outboundColor).intValue());

    //Sets the graph paint scale and the legend paintscale
    LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(),
            outboundCol);
    LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol);

    for (int ke = 0; ke <= (zvalues.length - 1); ke++) {
        Double key = (new Double(zvalues[ke]));
        Color temp = (Color) colorRangeMap.get(key);
        paintScale.add(zvalues[ke], temp);
        legendPaintScale.add(0.5 + ke, temp);
    }
    //Configures the renderer
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    double blockHeight = (new Double(blockH)).doubleValue();
    double blockWidth = (new Double(blockW)).doubleValue();
    renderer.setBlockWidth(blockWidth);
    renderer.setBlockHeight(blockHeight);

    //configures the plot with title, subtitle, axis ecc.
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainCrosshairPaint(Color.black);

    plot.setForegroundAlpha(0.66f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    //Sets legend labels
    SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels);
    scaleAxis.setRange(0.5, 0.5 + zvalues.length);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    scaleAxis.setLabel(zLabel);
    //scaleAxis.setLabelAngle(3.14/2);
    scaleAxis.setLabelFont(addLabelsStyle.getFont());
    scaleAxis.setLabelPaint(addLabelsStyle.getColor());

    //draws legend as chart subtitle
    PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis);
    psl.setAxisOffset(2.0);
    psl.setPosition(RectangleEdge.RIGHT);
    psl.setMargin(new RectangleInsets(5, 1, 5, 1));
    chart.addSubtitle(psl);

    if (yLabels != null) {
        //Sets y legend labels
        LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white);

        for (int ke = 0; ke < yLabels.length; ke++) {
            Color temp = Color.white;
            legendPaintScale2.add(1 + ke, temp);
        }

        SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels);
        scaleAxis2.setRange(0, (yLabels.length - 1));
        scaleAxis2.setPlot(new PiePlot());
        scaleAxis2.setGridBandsVisible(false);

        //draws legend as chart subtitle
        PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2);
        psl2.setAxisOffset(5.0);
        psl2.setPosition(RectangleEdge.LEFT);
        psl2.setMargin(new RectangleInsets(8, 1, 40, 1));
        psl2.setStripWidth(0);
        psl2.setStripOutlineVisible(false);
        chart.addSubtitle(psl2);
    }

    return chart;
}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java

private void boxWidthSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_boxWidthSpinnerStateChanged
    XYItemRenderer renderer = this.chartPanel.getChart().getXYPlot().getRenderer();
    if (renderer instanceof XYBlockRenderer) {
        XYBlockRenderer xyb = (XYBlockRenderer) renderer;
        xyb.setBlockWidth((Double) boxWidthSpinner.getValue());
    }/*www . j  a  v  a2  s .  c o  m*/
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
public void setDataset(IDataset dataset) {
    if (getDataset() != null) {
        dataset.removeChangeListener(this);
    }//  w  w w  .ja v  a 2s . c o  m
    super.setDataset(dataset);
    XYBlockRenderer renderer = (XYBlockRenderer) getXYPlot().getRenderer();
    renderer.setBlockHeight(((IXYZDataset) dataset).getYBlockSize());
    renderer.setBlockWidth(((IXYZDataset) dataset).getXBlockSize());
    PaintScaleLegend legend = getPaintScaleLegend();
    if (legend != null) {
        ((ColorPaintScale) legend.getScale()).resetBoundPercentage();
    }
    dataset.addChangeListener(this);
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
public void datasetChanged(DatasetChangeEvent event) {
    XYBlockRenderer renderer = (XYBlockRenderer) getXYPlot().getRenderer();
    renderer.setBlockHeight(((IXYZDataset) getDataset()).getYBlockSize());
    renderer.setBlockWidth(((IXYZDataset) getDataset()).getXBlockSize());
    getXYPlot().configureDomainAxes();//from w w w .j ava 2 s  .  c om
    getXYPlot().configureRangeAxes();
    //      PaintScaleLegend legend = getPaintScaleLegend();
    //      if (legend != null) {
    //         ((ColorPaintScale) legend.getScale()).resetBoundPercentage();
    //      }
}

From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java

/**
 *
 * @param fragments//from ww w. j  a va2 s . c o  m
 * @param ticvar
 * @param useRT
 * @return
 */
public XYPlot provide1DCoPlot(List<IFileFragment> fragments, String ticvar, boolean useRT) {

    final String satVar = "scan_acquisition_time";

    DefaultXYZDataset cd = new DefaultXYZDataset();
    int rowIdx = 0;
    double min = 0;
    double max = 1;
    double minRT = Double.POSITIVE_INFINITY;
    double maxRT = Double.NEGATIVE_INFINITY;

    int y = 0;
    for (IFileFragment f : fragments) {

        double[] domainValues = null;
        if (useRT) {
            domainValues = (double[]) f.getChild(satVar).getArray().get1DJavaArray(double.class);
        } else {
            domainValues = (double[]) f.getChild("scan_index").getArray().get1DJavaArray(double.class);
        }

        double[] tic = (double[]) f.getChild(ticvar).getArray().get1DJavaArray(double.class);
        double maxtic = MathTools.max(tic);
        double mintic = MathTools.min(tic);
        double[][] values = new double[3][tic.length];
        for (int i = 0; i < tic.length; i++) {
            values[0][i] = domainValues[i];
            values[1][i] = y;
            values[2][i] = Math.sqrt((tic[i] - mintic) / (maxtic - mintic));
        }

        y++;
        cd.addSeries(f.getName(), values);
    }

    // ArrayDouble.D1 a = new ArrayDouble.D1(npoints);
    // int offset = 0;
    // for (IFileFragment f : t) {
    // Array tic = f.getChild(ticvar).getArray();
    // int len = tic.getShape()[0];
    // Array.arraycopy(tic, 0, a, offset, len);
    // offset += len;
    // }
    // histogram with fixed binsize
    // fill intensities into adequate bin, raise count in bin by one
    // afterwards, relative frequency within a bin gives a normalization
    // coefficient
    XYBlockRenderer xyb = new XYBlockRenderer();
    GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max,
            ImageTools.rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv")));

    xyb.setPaintScale(ps);
    final String[] colnames = new String[fragments.size()];
    for (int i = 0; i < colnames.length; i++) {
        colnames[i] = StringTools.removeFileExt(fragments.get(i).getName());
    }
    NumberAxis na = null;
    if (useRT) {
        na = new NumberAxis("time [s]");
        na.setAutoRangeIncludesZero(false);
        na.setLowerMargin(0);
        na.setUpperMargin(0);
    } else {
        na = new NumberAxis("scan index");
    }
    // na.setVerticalTickLabels(true);
    XYPlot xyp = new XYPlot(cd, na, new SymbolAxis("chromatogram", colnames), xyb);
    xyb.setBlockWidth(1);
    xyp.setBackgroundPaint(Color.BLACK);
    xyb.setBaseToolTipGenerator(new XYZToolTipGenerator() {
        @Override
        public String generateToolTip(XYZDataset xyzd, int i, int i1) {
            return colnames[xyzd.getY(i, i1).intValue()] + " @" + xyzd.getXValue(i, i1) + " = "
                    + xyzd.getZValue(i, i1);
        }

        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            if (xyd instanceof XYZDataset) {
                return generateToolTip((XYZDataset) xyd, i, i1);
            }
            return colnames[xyd.getY(i, i1).intValue()] + ":" + xyd.getXValue(i, i1);
        }
    });
    return xyp;
}

From source file:whitebox.stats.Kriging.java

/**
 * Draw Semivariogram surface map and also draw the search are if
 * Anisotropic//from   w w  w.j a va 2s. c  o  m
 *
 * @param Radius
 * @param AnIsotropic
 */
public void DrawSemivariogramSurface(double Radius, boolean AnIsotropic) {
    double[][] data = new double[3][BinSurface.length * BinSurface[0].length];
    int n = 0;
    double max = Double.MIN_VALUE;
    for (int i = 0; i < BinSurface.length; i++) {
        for (int j = 0; j < BinSurface[i].length; j++) {
            data[0][n] = BinSurface[i][j].GridHorDistance;
            data[1][n] = BinSurface[i][j].GridVerDistance;
            if ((Math.pow(data[0][n], 2) + Math.pow(data[1][n], 2)) <= Radius * Radius
                    && !Double.isNaN(BinSurface[i][j].Value)) {
                data[2][n] = BinSurface[i][j].Value;
                if (max < data[2][n]) {
                    max = data[2][n];
                }
            } else {
                data[2][n] = -1;
            }
            n++;
        }
    }
    DefaultXYZDataset dataset = new DefaultXYZDataset();
    dataset.addSeries("Value", data);
    NumberAxis xAxis = new NumberAxis();

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(LagSize);
    renderer.setBlockHeight(LagSize);
    renderer.setBlockAnchor(RectangleAnchor.CENTER);

    LookupPaintScale paintScale = new LookupPaintScale(0, max, Color.white);
    double colorRange = max / 6;
    //double colorRange = 23013;
    paintScale.add(0.0, Color.blue);
    paintScale.add(1 * colorRange, Color.green);
    paintScale.add(2 * colorRange, Color.cyan);
    paintScale.add(3 * colorRange, Color.yellow);
    paintScale.add(4 * colorRange, Color.ORANGE);
    paintScale.add(5 * colorRange, Color.red);

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);

    if (AnIsotropic) {
        CombinedRangeXYPlot combinedrangexyplot = new CombinedRangeXYPlot();
        XYSeries seriesT1 = new XYSeries("1");
        XYSeriesCollection AngleCollct = new XYSeriesCollection();

        double bw = BandWidth;
        double r = bw / Math.sin(Tolerance);
        if (r > Radius) {
            bw = Radius * Math.sin(Tolerance);
            r = Radius;
        }
        seriesT1.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));

        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = 2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 + bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 + bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x2, y2);
                }
            } else {
                double x1 = -bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x1, y2);
                }
            }
        } else {
            double y1 = bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT1.add(x1, y1);
            } else {
                seriesT1.add(x2, y1);
            }
        }

        AngleCollct.addSeries(seriesT1);

        XYSeries seriesT2 = new XYSeries("2");
        seriesT2.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));
        seriesT2.add(0.0, 0.0);
        AngleCollct.addSeries(seriesT2);

        XYSeries seriesT3 = new XYSeries("3");
        seriesT3.add(Radius * Math.cos(Angle), Radius * Math.sin(Angle));
        seriesT3.add(0, 0);
        AngleCollct.addSeries(seriesT3);

        XYSeries seriesT4 = new XYSeries("4");
        seriesT4.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        seriesT4.add(0, 0);
        AngleCollct.addSeries(seriesT4);

        XYSeries seriesT5 = new XYSeries("5");

        seriesT5.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = -2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 - bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 - bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x2, y2);
                }
            } else {
                double x1 = bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x1, y2);
                }
            }
        } else {
            double y1 = -bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT5.add(x1, y1);
            } else {
                seriesT5.add(x2, y1);
            }
        }
        AngleCollct.addSeries(seriesT5);
        plot.setDataset(1, AngleCollct);
        XYLineAndShapeRenderer lineshapRend = new XYLineAndShapeRenderer(true, false);
        for (int i = 0; i < AngleCollct.getSeriesCount(); i++) {
            //plot.getRenderer().setSeriesPaint(i , Color.BLUE);
            lineshapRend.setSeriesPaint(i, Color.BLACK);
        }
        plot.setRenderer(1, lineshapRend);
        combinedrangexyplot.add(plot);
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    JFreeChart chart = new JFreeChart("Semivariogram Surface", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    // create and display a frame...
    ChartFrame frame = new ChartFrame("", chart);
    frame.pack();
    //frame.setSize(100, 50);
    frame.setVisible(true);
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java

/**
 * Creates a chart for the specified dataset.
 * /*from  ww  w  .  j a va  2  s  .c  om*/
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = null;

    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (xLowerBound != null && xUpperBound != null) {
        xAxis.setLowerBound(xLowerBound);
        xAxis.setUpperBound(xUpperBound);
    } else {
        xAxis.setAutoRange(true);
    }
    xAxis.setAxisLinePaint(Color.white);
    xAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (yLowerBound != null && yUpperBound != null) {
        yAxis.setLowerBound(yLowerBound);
        yAxis.setUpperBound(yUpperBound);
    } else
        yAxis.setAutoRange(true);

    yAxis.setAxisLinePaint(Color.white);
    yAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    XYBlockRenderer renderer = new XYBlockRenderer();

    PaintScale paintScale = null;

    if (grayPaintScale) {
        paintScale = new GrayPaintScale(minScaleValue, maxScaleValue);
    } else {
        if (scaleLowerBound != null && scaleUpperBound != null) {
            paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray);
        } else {
            paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray);
        }
        for (int i = 0; i < zRangeArray.length; i++) {
            ZRange zRange = zRangeArray[i];
            ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor());

        }
    }

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setForegroundAlpha(0.66f);

    chart = new JFreeChart(plot);
    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    chart.removeLegend();

    NumberAxis scaleAxis = new NumberAxis(zLabel);
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    if (scaleLowerBound != null && scaleUpperBound != null) {
        scaleAxis.setLowerBound(scaleLowerBound);
        scaleAxis.setUpperBound(scaleUpperBound);
    } else
        scaleAxis.setAutoRange(true);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        scaleAxis.setLabelFont(addLabelsStyle.getFont());
        scaleAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    if (blockHeight != null && blockWidth != null) {
        renderer.setBlockWidth(blockWidth.doubleValue());
        renderer.setBlockHeight(blockHeight.doubleValue());
    }

    PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.black));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setBackgroundPaint(color);

    chart.addSubtitle(legend);

    //      chart.setBackgroundPaint(new Color(180, 180, 250));   
    chart.setBackgroundPaint(color);

    logger.debug("OUT");
    return chart;
}