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

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

Introduction

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

Prototype

public XYBlockRenderer() 

Source Link

Document

Creates a new XYBlockRenderer instance with default attributes.

Usage

From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java

@Override
public void run() {
    CSV2TableLoader tl = new CSV2TableLoader(this.ph, this.is);

    DefaultTableModel dtm;//from   w ww .j a va 2 s.  co  m
    try {
        dtm = tl.call();
        if (this.mode == CHART.XY) {
            XYSeriesCollection cd = new XYSeriesCollection();
            for (int j = 0; j < dtm.getColumnCount(); j++) {
                XYSeries xys = new XYSeries(dtm.getColumnName(j));
                for (int i = 0; i < dtm.getRowCount(); i++) {
                    Object o = dtm.getValueAt(i, j);
                    try {
                        double d = Double.parseDouble(o.toString());
                        xys.add(i, d);
                        Logger.getLogger(getClass().getName()).log(Level.INFO, "Adding {0} {1} {2}",
                                new Object[] { i, d, dtm.getColumnName(j) });
                    } catch (Exception e) {
                    }
                }
                cd.addSeries(xys);
            }
            XYLineAndShapeRenderer d = new XYLineAndShapeRenderer(true, false);
            XYPlot xyp = new XYPlot(cd, new NumberAxis("category"), new NumberAxis("value"), d);

            JFreeChart jfc = new JFreeChart(this.title, xyp);
            jtc.setChart(jfc);
            Logger.getLogger(getClass().getName()).info("creating chart done");
        } else if (this.mode == CHART.MATRIX) {
            DefaultXYZDataset cd = new DefaultXYZDataset();
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Name of column 0: {0}",
                    dtm.getColumnName(0));
            if (dtm.getColumnName(0).isEmpty()) {
                Logger.getLogger(getClass().getName()).info("Removing column 0");
                dtm = removeColumn(dtm, 0);
            }
            if (dtm.getColumnName(dtm.getColumnCount() - 1).equalsIgnoreCase("filename")) {
                dtm = removeColumn(dtm, dtm.getColumnCount() - 1);
            }
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {
                    sb.append(dtm.getValueAt(i, j) + " ");
                }
                sb.append("\n");
            }
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Table before sorting: {0}", sb.toString());
            //                dtm = sort(dtm);
            StringBuilder sb2 = new StringBuilder();
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {
                    sb2.append(dtm.getValueAt(i, j) + " ");
                }
                sb2.append("\n");
            }
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Table after sorting: {0}", sb2.toString());
            int rows = dtm.getRowCount();
            int columns = dtm.getColumnCount();
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Storing {0} * {1} elements, {2} total!",
                    new Object[] { columns, rows, rows * columns });
            double[][] data = new double[3][(columns * rows)];
            ArrayDouble.D1 dt = new ArrayDouble.D1((columns) * rows);
            double min = Double.POSITIVE_INFINITY;
            double max = Double.NEGATIVE_INFINITY;
            EvalTools.eqI(rows, columns, this);
            int k = 0;
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {

                    Object o = dtm.getValueAt(i, j);
                    try {
                        double d = Double.parseDouble(o.toString());
                        if (d < min) {
                            min = d;
                        }
                        if (d > max) {
                            max = d;
                        }
                        data[0][k] = (double) i;
                        data[1][k] = (double) j;
                        data[2][k] = d;
                        dt.set(k, d);
                        k++;
                        //System.out.println("Adding "+i+" "+d+" "+dtm.getColumnName(j));
                    } catch (Exception e) {
                    }
                }
                //cd.addSeries(xys);
            }
            cd.addSeries(this.title, data);
            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[dtm.getColumnCount()];
            for (int i = 0; i < colnames.length; i++) {
                colnames[i] = dtm.getColumnName(i);
            }
            NumberAxis na1 = new SymbolAxis("category", colnames);
            na1.setVerticalTickLabels(false);
            NumberAxis na2 = new SymbolAxis("category", colnames);
            na1.setVerticalTickLabels(true);
            XYPlot xyp = new XYPlot(cd, na1, na2, xyb);
            xyb.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {

                @Override
                public String generateToolTip(XYDataset xyd, int i, int i1) {
                    return "[" + colnames[xyd.getX(i, i1).intValue()] + ":"
                            + colnames[xyd.getY(i, i1).intValue()] + "] = "
                            + ((XYZDataset) xyd).getZValue(i, i1) + "";
                }
            });

            JFreeChart jfc = new JFreeChart(this.title, xyp);
            NumberAxis values = new NumberAxis("value");
            values.setAutoRange(false);
            values.setRangeWithMargins(min, max);
            PaintScaleLegend psl = new PaintScaleLegend(ps, values);
            psl.setBackgroundPaint(jfc.getBackgroundPaint());
            jfc.addSubtitle(psl);
            psl.setStripWidth(50);
            psl.setPadding(20, 20, 20, 20);
            psl.setHeight(200);
            psl.setPosition(RectangleEdge.RIGHT);
            jtc.setChart(jfc);
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }

    ph.finish();
}

From source file:org.jls.toolbox.math.chart.XYBlockChart.java

/**
 * Permet de crer le graphique  partir des paramtres spcifis.
 *//*from   w  w  w  . j  a va 2 s. com*/
private void createChart() {
    // Cration des axes
    NumberAxis xAxis = new NumberAxis(this.xTitle);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLabelFont(new Font("Dialog", Font.BOLD, 14));
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);

    NumberAxis yAxis = new NumberAxis(this.yTitle);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLabelFont(new Font("Dialog", Font.BOLD, 14));
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);

    this.renderer = new XYBlockRenderer();
    PaintScale scale = new GrayPaintScale(0, 10);
    this.renderer.setPaintScale(scale);

    // Cration de la courbe
    this.plot = new XYPlot(this.dataset, xAxis, yAxis, this.renderer);

    // Cration du graphique
    this.chart = new JFreeChart(this.title, this.plot);
    this.chart.removeLegend();

    createPaintScaleLegend(scale);
    setColorGradient(Color.yellow, Color.red, 0, 1);
}

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

/**
 * Creates a chart for the specified dataset.
 * //www .  j ava  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:org.fhcrc.cpl.toolbox.gui.chart.PanelWithHeatMap.java

public void setData(double[] xValues, double[] yValues, double[][] zValues) {
    this.xValues = xValues;
    this.yValues = yValues;
    this.zValues = zValues;

    double minZValue = Double.MAX_VALUE;
    double maxZValue = Double.MIN_VALUE;
    int width = xValues.length;
    int height = yValues.length;
    int numCells = width * height;
    _log.debug("Number of cells in heat map: " + numCells);
    if (zValues.length != width || zValues[0].length != height)
        throw new RuntimeException(
                "PanelWithHeatMap: wrong number of z values for x and y values (" + zValues.length + " vs. "
                        + width + ", " + zValues[0].length + " vs. " + height + ", x/y first, z second)");
    DefaultXYZDataset theDataset = new DefaultXYZDataset();
    double[][] data = new double[3][numCells];
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            int cellIndex = (j * width) + i;
            data[0][cellIndex] = xValues[i];
            data[1][cellIndex] = yValues[j];
            data[2][cellIndex] = zValues[i][j];
            //keep track of lowest/highest z values
            minZValue = Math.min(zValues[i][j], minZValue);
            maxZValue = Math.max(zValues[i][j], maxZValue);
        }// w w  w .  j  ava  2  s  . c  o  m
    }
    lowerZBound = Rounder.round(minZValue, 3);
    upperZBound = Rounder.round(maxZValue, 3);
    if (lowerZBound == upperZBound)
        upperZBound += .0001;
    _log.debug("low,high values: " + lowerZBound + ", " + upperZBound);
    theDataset.addSeries("Range: " + lowerZBound + "-" + upperZBound, data);

    dataset = theDataset;
    if (renderer == null) {
        renderer = new XYBlockRenderer();
    }

    if (paintScale == null) {
        setPaintScale(createPaintScale(palette));
    }
    //This is necessary to get everything to line up
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM);

    if (getPlot() != null) {
        ((XYPlot) getPlot()).setDataset(dataset);
        ((XYPlot) getPlot()).setRenderer(renderer);

        invalidate();
        return;
    }
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(dataSetName, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    //        chart.addLegend(new LegendTitle(renderer));
    //        PaintScaleLegend legend = new PaintScaleLegend(paintScale, xAxis);
    //        chart.addLegend(legend);

    //        LegendItemCollection c1 = new LegendItemCollection();
    //
    //        LegendItem item1 = new LegendItem("Label", "Description",
    //                "ToolTip", "URL", true,
    //                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red,
    //                true, Color.blue, new BasicStroke(1.2f), true,
    //                new Line2D.Double(1.0, 2.0, 3.0, 4.0),
    //                new BasicStroke(2.1f), Color.green);
    //        LegendItem item2 = new LegendItem("Label", "Description",
    //                "ToolTip", "URL", true,
    //                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0),
    //                true, Color.red, true, Color.blue, new BasicStroke(1.2f), true,
    //                new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
    //                Color.green);
    //        c1.add(item1);
    //
    //        chart.getLegend().setSources(new LegendItemSource[]{renderer});

    init(chart);
}

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

/**
 *
 * @param fragments/*  w ww  .  j ava2  s . com*/
 * @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:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    super.createChart(datasets);
    DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1");

    DateAxis xAxis = new DateAxis(yLabel);
    xAxis.setLowerMargin(0.0);//from w w  w  . j  av a2  s  .  c  o m
    xAxis.setUpperMargin(0.0);
    xAxis.setInverted(false);
    xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
    if (dateAutoRange) {
        xAxis.setAutoRange(true);
    } else {
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter);
        xAxis.setTickUnit(unit);
    }

    if (dateMin != null && dateMax != null) {
        xAxis.setRange(dateMin, addDay(dateMax));
    } else {
        xAxis.setRange(minDateFound, addDay(maxDateFound));
    }

    //      Calendar c=new GregorianCalendar();
    //      c.set(9 + 2000, Calendar.JANUARY, 1);
    //      java.util.Date minima=c.getTime();
    //      Calendar c1=new GregorianCalendar();
    //      c1.set(9 + 2000, Calendar.FEBRUARY, 1);
    //      java.util.Date massima=c1.getTime();

    NumberAxis yAxis = new NumberAxis(xLabel);
    yAxis.setUpperMargin(0.0);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setRange(hourMin, hourMax);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(BLOCK_HEIGHT);
    // one block for each minute!
    renderer.setBlockHeight(0.017);
    //renderer.setBlockWidth(1);
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);

    //      MyXYItemLabelGenerator my=new MyXYItemLabelGenerator();
    //      renderer.setItemLabelsVisible(null);
    //      renderer.setSeriesItemLabelGenerator(0, my);
    //      renderer.setSeriesItemLabelsVisible(0, true);

    //      XYTextAnnotation annotation1 = new XYTextAnnotation(
    //      "P_",1.2309372E12, 14.3);
    //      XYTextAnnotation annotation2 = new XYTextAnnotation(
    //      "P_",1.2308508E12, 16.3);

    for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) {
        String annotationCode = (String) iterator.next();
        AnnotationBlock annotationBlock = annotations.get(annotationCode);
        XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(),
                annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition());
        if (styleAnnotation != null) {
            xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize()));
            xyAnnotation.setPaint(styleAnnotation.getColor());
        } else {
            xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8));
            xyAnnotation.setPaint(Color.BLACK);
        }

        xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
        renderer.addAnnotation(xyAnnotation);
    }

    logger.debug("Annotation set");

    LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color);
    String[] labels = new String[ranges.size() + 1];
    labels[0] = "";

    // ******************** SCALE ****************************
    for (Iterator iterator = ranges.iterator(); iterator.hasNext();) {
        RangeBlocks range = (RangeBlocks) iterator.next();
        Integer index = patternRangeIndex.get(range.getPattern());
        Color color = range.getColor();
        if (color != null) {
            //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);         
            Paint colorTransparent = null;
            if (addTransparency == true) {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);
            } else {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue());
            }
            paintScale.add(index + 0.5, colorTransparent);
        }
        //String insertLabel="            "+range.getLabel();
        String insertLabel = range.getLabel();
        labels[index + 1] = insertLabel;
    }
    renderer.setPaintScale(paintScale);

    SymbolAxis scaleAxis = new SymbolAxis(null, labels);
    scaleAxis.setRange(0.5, ranges.size() + 0.5);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);

    org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setMargin(new RectangleInsets(3, 10, 3, 10));
    psl.setPosition(RectangleEdge.BOTTOM);
    psl.setAxisOffset(5.0);
    // ******************** END SCALE ****************************

    logger.debug("Scale Painted");

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

    logger.debug("Plot set");

    JFreeChart chart = new JFreeChart(name, plot);
    if (styleTitle != null) {
        TextTitle title = setStyleTitle(name, styleTitle);
        chart.setTitle(title);
    }
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(psl);

    logger.debug("OUT");

    return chart;

}

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

/**
 * Creates a chart for the specified dataset.
 * /*from w  ww.  j  a v  a2s.  co m*/
 * @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;
}

From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java

/**
 * Create a SNP block graph for the given parameters. This graph
 * will show where the intervals do and don't exist. Interval lists
 * are organized with the X axis label matching the list's key
 * @param snpIntervals/*  w  ww  . j a va 2 s  .com*/
 *          the blocks
 * @param startInBasePairs
 *          the x location to start the graph at
 * @param extentInBasePairs
 *          the extent to use for the graph
 * @param maximumImageBlockCount
 *          the max # of separate image blocks to use
 * @param renderAxes
 *          if true render the axes... otherwise dont
 * @param legendText
 *          the text to use for the legend
 * @param yAxisText
 *          the text to use for the y axis
 * @param trueColor
 *          the color to use for true
 * @param falseColor
 *          the color to use for false 
 * @return
 *          the graph
 */
public JFreeChart createSnpIntervalGraph(
        final Map<String, ? extends List<? extends BasePairInterval>> snpIntervals, final long startInBasePairs,
        final long extentInBasePairs, final int maximumImageBlockCount, final boolean renderAxes,
        final String legendText, final String yAxisText, final Color trueColor, final Color falseColor) {
    XYDataset dataset = snpIntervalsToDataset(snpIntervals, startInBasePairs, extentInBasePairs,
            maximumImageBlockCount);

    NumberAxis xAxis = new NumberAxis("SNP Position (Base Pairs)");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs));
    String[] sortedStrainNames = extractSortedStrainNames(snpIntervals);
    for (int strainIndex = 0; strainIndex < sortedStrainNames.length; strainIndex++) {
        LOG.info("Strain Name: " + sortedStrainNames[strainIndex]);
    }
    SymbolAxis yAxis = new SymbolAxis(yAxisText == null ? "" : yAxisText, sortedStrainNames);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    LegendItemCollection items = new LegendItemCollection();
    if (legendText != null) {
        items.add(new LegendItem(legendText, null, null, null, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0),
                trueColor, new BasicStroke(), Color.BLACK));
    }
    plot.setFixedLegendItems(items);

    XYBlockRenderer r = new XYBlockRenderer();
    SmoothPaintScale ps = new SmoothPaintScale(0.0, 1.0, falseColor, trueColor);

    r.setPaintScale(ps);
    r.setBlockHeight(1.0);
    r.setBlockWidth(1.0);
    plot.setRenderer(r);

    final JFreeChart chart;
    if (renderAxes) {
        chart = new JFreeChart("Identical By State Blocks", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        xAxis.setVisible(false);
        yAxis.setVisible(false);
        plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
        chart = new JFreeChart(plot);
    }

    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:SciTK.PlotXYZBlock.java

private void init(String x_label, String y_label, String window_title) {
    chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true,
            false);/*  www .ja va  2s .co m*/

    // turn off borders of the plot:
    XYPlot p = chart.getXYPlot();
    p.getDomainAxis().setLowerMargin(0.0);
    p.getDomainAxis().setUpperMargin(0.0);
    p.getRangeAxis().setLowerMargin(0.0);
    p.getRangeAxis().setUpperMargin(0.0);

    // --------------------------------------------
    //          set up a lookup table
    // --------------------------------------------
    // this is how we render the block plots:
    XYBlockRenderer renderer = new XYBlockRenderer();
    // need to find max and min z of the data set:
    double min = 0;
    double max = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) // iterate over data sets
    {
        for (int j = 0; j < data.getItemCount(i); j++) // iterate over points in dataset
        {
            if (data.getZValue(i, j) < min)
                min = data.getZValue(i, j);
            else if (data.getZValue(i, j) > max)
                max = data.getZValue(i, j);
        }
    }
    // create paint scale using min and max values, default color black:
    LookupPaintScale paintScale = new LookupPaintScale(min, max, Color.black);
    // set up the LUT:
    double step_size = (max - min) / 255.; // step size for LUT
    for (int i = 0; i < 256; i++) {
        paintScale.add(min + i * step_size, new Color(i, i, i, 255));
    }
    renderer.setPaintScale(paintScale);
    // set this renderer to the plot:
    p.setRenderer(renderer);

    // --------------------------------------------
    //          set up a color bar
    // --------------------------------------------
    // create an array of display labels:
    num_labels = 10; // default to 10 labels on color bar
    double display_step_size = (max - min) / ((double) num_labels);
    String[] scale_bar_labels = new String[num_labels + 1];
    // to format numbers in scientific notation:
    DecimalFormat formater = new DecimalFormat("0.#E0");
    // create list of labesl:
    for (int i = 0; i <= num_labels; i++) {
        scale_bar_labels[i] = formater.format(min + i * display_step_size);
    }
    // create axis:
    SymbolAxis scaleAxis = new SymbolAxis(null, scale_bar_labels);
    scaleAxis.setRange(min, max);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    // set up the paint scale:
    psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setBackgroundPaint(new Color(255, 255, 255, 0)); // clear background
    // set up frame with buffer region to allow text display
    psl.setFrame(new LineBorder((Paint) Color.BLACK, new BasicStroke((float) 1.0),
            new RectangleInsets(15, 10, 15, 10)));
    psl.setAxisOffset(5.0);
    // display on right side:
    psl.setPosition(RectangleEdge.RIGHT);
    // margin around color scale:
    psl.setMargin(new RectangleInsets(20, 15, 20, 15));
    // add to the chart so it will be displayed by default:
    chart.addSubtitle(psl);

    // --------------------------------------------
    //          WINDOW-RELATED UI
    // --------------------------------------------
    // set up the generic plot UI:
    super.window_title = window_title;
    super.initUI();

    // add another menu item
    JMenuBar mb = super.getJMenuBar(); // get the menu bar
    // find menu named "Plot"
    JMenu menu_plot = null;
    for (int i = 0; i < mb.getMenuCount(); i++) {
        if (mb.getMenu(i).getText() == "Plot")
            menu_plot = mb.getMenu(i);
    }
    // Add a new checkbox for the color scale bar
    JCheckBoxMenuItem menu_plot_scalebar = new JCheckBoxMenuItem("Color Scale");
    menu_plot_scalebar.setToolTipText("Show color scale bar?");
    menu_plot_scalebar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            setScaleBar(selected);
        }
    });
    // set appropirate checkbox state:
    menu_plot_scalebar.setState(true);
    if (menu_plot != null) // sanity check
        menu_plot.add(menu_plot_scalebar);

}

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

private void createRender(PaintScale scale) {
    //      renderer = new Render2D();
    renderer = new XYBlockRenderer();
    renderer.setPaintScale(scale);/*  w w w  .  j a  va  2 s.com*/
    renderer.setBlockHeight(dataset.getYBlockSize());
    renderer.setBlockWidth(dataset.getXBlockSize());
    //      XYToolTipGenerator toolTip = new StandardXYZToolTipGenerator();
    //      renderer.setBaseToolTipGenerator(toolTip);
}