Example usage for org.jfree.chart.renderer GrayPaintScale GrayPaintScale

List of usage examples for org.jfree.chart.renderer GrayPaintScale GrayPaintScale

Introduction

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

Prototype

public GrayPaintScale(double lowerBound, double upperBound) 

Source Link

Document

Creates a new paint scale for values in the specified range.

Usage

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLowerMargin(0.0D);/*from w  w w  . j  av a 2 s. c  o  m*/
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setAxisLinePaint(Color.white);
    numberaxis.setTickMarkPaint(Color.white);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setAxisLinePaint(Color.white);
    numberaxis1.setTickMarkPaint(Color.white);
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    GrayPaintScale graypaintscale = new GrayPaintScale(-2D, 1.0D);
    xyblockrenderer.setPaintScale(graypaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setOutlinePaint(Color.blue);
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo1", xyplot);
    jfreechart.removeLegend();
    NumberAxis numberaxis2 = new NumberAxis("Scale");
    numberaxis2.setAxisLinePaint(Color.white);
    numberaxis2.setTickMarkPaint(Color.white);
    numberaxis2.setTickLabelFont(new Font("Dialog", 0, 7));
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(new GrayPaintScale(), numberaxis2);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    paintscalelegend.setFrame(new BlockBorder(Color.red));
    paintscalelegend.setPadding(new RectangleInsets(10D, 10D, 10D, 10D));
    paintscalelegend.setStripWidth(10D);
    paintscalelegend.setPosition(RectangleEdge.RIGHT);
    paintscalelegend.setBackgroundPaint(new Color(120, 120, 180));
    jfreechart.addSubtitle(paintscalelegend);
    jfreechart.setBackgroundPaint(new Color(180, 180, 250));
    return jfreechart;
}

From source file:jamel.gui.charts.InstantXYZScatterChart.java

/**
 * Sets the color scale./*from w  w  w.  ja v a  2 s .  c om*/
 * @param lowerBound the lower bound.
 * @param upperBound the upper bound.
 */
private void setColorScale(double lowerBound, double upperBound) {
    if (upperBound == lowerBound)
        upperBound++;
    GrayPaintScale colorPaintScale = new GrayPaintScale(lowerBound, upperBound) {
        public Paint getPaint(double value) {
            double v = Math.max(value, this.getLowerBound());
            v = Math.min(v, this.getUpperBound());
            int g = 255 - (int) ((v - this.getLowerBound()) * 2 / (this.getUpperBound() - this.getLowerBound())
                    * 255.0);
            if (g >= 0)
                return new Color(255, 255 - g, 0);
            return new Color(255 + g, 255, 0);
        }
    };
    XYShapeRenderer renderer = (XYShapeRenderer) this.getXYPlot().getRenderer(1);
    renderer.setPaintScale(colorPaintScale);
}

From source file:org.spantus.exp.segment.draw.DrawDtw.java

protected JFreeChart createXYZChart() {
    NumberAxis xAxis = new NumberAxis("Sample");
    NumberAxis yAxis = new NumberAxis("target");
    List<List<Double>> data = info.getDistanceMatrix();
    XYZDataset xyzset = new XYZArrayDataset(data);
    XYPlot plot = new XYPlot(xyzset, xAxis, yAxis, null);
    XYBlockRenderer r = new XYBlockRenderer();
    PaintScale ps = new GrayPaintScale(min, max);
    //      LookupPaintScale ps = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    //      ps.add(1, Color.red);
    //      ps.add(2, Color.green);
    //      ps.add(3, Color.gray);

    r.setPaintScale(ps);//from  w w  w.j  a  v  a2s  .co m
    r.setBlockHeight(1.0f);
    r.setBlockWidth(1.0f);
    plot.setRenderer(r);
    JFreeChart chart = new JFreeChart("Chart Title", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    NumberAxis scaleAxis = new NumberAxis("Scale");
    scaleAxis.setUpperBound(100);
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 12));
    //      PaintScaleLegend legend = new PaintScaleLegend(ps, scaleAxis);
    //      legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    //      legend.setPadding(new RectangleInsets(5, 5, 5, 5));
    //      legend.setStripWidth(50);
    //      legend.setPosition(RectangleEdge.RIGHT);
    //      legend.setBackgroundPaint(Color.WHITE);
    //      chart.addSubtitle(legend);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java

private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints,
        XYDataset xyData) {//from w ww  .jav a  2 s  .  c  om
    NumberAxis xAxis = new NumberAxis("X");
    xAxis.setRange(mins[0], maxs[0]);

    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setRange(mins[1], maxs[1]);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1));
    renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1));
    PaintScale scale = new GrayPaintScale(0, 1.0);
    renderer.setPaintScale(scale);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    JFreeChart chart = new JFreeChart("", plot);
    chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false);

    NumberAxis scaleAxis = new NumberAxis("Probability (class 0)");
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis);
    legend.setStripOutlineVisible(false);
    legend.setSubdivisionCount(20);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.red));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.LEFT);
    chart.addSubtitle(legend);

    ChartUtilities.applyCurrentTheme(chart);

    plot.setDataset(1, xyData);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setBaseLinesVisible(false);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}

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

/**
 * Permet de crer le graphique  partir des paramtres spcifis.
 *///from ww w  .j av a  2 s.c o  m
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.SimpleBlockChart.java

/**
 * Creates a chart for the specified dataset.
 * //from  w  w w  .j a  v a  2 s.  com
 * @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;
}