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

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

Introduction

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

Prototype

public LookupPaintScale(double lowerBound, double upperBound, Paint defaultPaint) 

Source Link

Document

Creates a new paint scale with the specified default paint.

Usage

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    XYShapeRenderer xyshaperenderer = new XYShapeRenderer();
    LookupPaintScale lookuppaintscale = new LookupPaintScale(1.0D, 4D, new Color(0, 0, 255));
    lookuppaintscale.add(2D, new Color(100, 100, 255));
    lookuppaintscale.add(3D, new Color(200, 200, 255));
    xyshaperenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyshaperenderer);
    xyplot.setDomainPannable(true);/*from   ww w .j  a  v a2s. c  om*/
    xyplot.setRangePannable(true);
    JFreeChart jfreechart = new JFreeChart("XYShapeRendererDemo1", xyplot);
    jfreechart.removeLegend();
    NumberAxis numberaxis2 = new NumberAxis("Score");
    numberaxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, numberaxis2);
    paintscalelegend.setPosition(RectangleEdge.RIGHT);
    paintscalelegend.setMargin(4D, 4D, 40D, 4D);
    paintscalelegend.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    jfreechart.addSubtitle(paintscalelegend);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    NumberAxis numberaxis = new NumberAxis("X");
    numberaxis.setLowerMargin(0.0D);/*from   w w w .  jav a  2 s  .c  om*/
    numberaxis.setUpperMargin(0.0D);
    NumberAxis numberaxis1 = new NumberAxis("Y");
    numberaxis1.setAutoRangeIncludesZero(false);
    numberaxis1.setInverted(true);
    numberaxis1.setLowerMargin(0.0D);
    numberaxis1.setUpperMargin(0.0D);
    numberaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 3.5D, Color.black);
    lookuppaintscale.add(0.5D, Color.green);
    lookuppaintscale.add(1.5D, Color.orange);
    lookuppaintscale.add(2.5D, Color.red);
    xyblockrenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, numberaxis, numberaxis1, xyblockrenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setForegroundAlpha(0.66F);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo3", xyplot);
    jfreechart.removeLegend();
    jfreechart.setBackgroundPaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis(null, new String[] { "", "OK", "Uncertain", "Bad" });
    symbolaxis.setRange(0.5D, 3.5D);
    symbolaxis.setPlot(new PiePlot());
    symbolaxis.setGridBandsVisible(false);
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis);
    paintscalelegend.setAxisOffset(5D);
    paintscalelegend.setPosition(RectangleEdge.BOTTOM);
    paintscalelegend.setMargin(new RectangleInsets(5D, 5D, 5D, 5D));
    jfreechart.addSubtitle(paintscalelegend);
    return jfreechart;
}

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

private static JFreeChart createChart(XYZDataset xyzdataset) {
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setLowerMargin(0.0D);/*from   w w w.ja va 2  s.c om*/
    dateaxis.setUpperMargin(0.0D);
    dateaxis.setInverted(true);
    NumberAxis numberaxis = new NumberAxis("Hour");
    numberaxis.setUpperMargin(0.0D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYBlockRenderer xyblockrenderer = new XYBlockRenderer();
    xyblockrenderer.setBlockWidth(86400000D);
    xyblockrenderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);
    LookupPaintScale lookuppaintscale = new LookupPaintScale(0.5D, 4.5D, Color.white);
    lookuppaintscale.add(0.5D, Color.red);
    lookuppaintscale.add(1.5D, Color.green);
    lookuppaintscale.add(2.5D, Color.blue);
    lookuppaintscale.add(3.5D, Color.yellow);
    xyblockrenderer.setPaintScale(lookuppaintscale);
    XYPlot xyplot = new XYPlot(xyzdataset, dateaxis, numberaxis, xyblockrenderer);
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    JFreeChart jfreechart = new JFreeChart("XYBlockChartDemo2", xyplot);
    jfreechart.removeLegend();
    jfreechart.setBackgroundPaint(Color.white);
    SymbolAxis symbolaxis = new SymbolAxis(null,
            new String[] { "", "Unavailable", "Free", "Group 1", "Group 2" });
    symbolaxis.setRange(0.5D, 4.5D);
    symbolaxis.setPlot(new PiePlot());
    symbolaxis.setGridBandsVisible(false);
    PaintScaleLegend paintscalelegend = new PaintScaleLegend(lookuppaintscale, symbolaxis);
    paintscalelegend.setMargin(new RectangleInsets(3D, 10D, 3D, 10D));
    paintscalelegend.setPosition(RectangleEdge.BOTTOM);
    paintscalelegend.setAxisOffset(5D);
    jfreechart.addSubtitle(paintscalelegend);
    return jfreechart;
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.XyBlockRendererCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    chart.getXYPlot().getDomainAxis().setUpperMargin(0);
    chart.getXYPlot().getRangeAxis().setUpperMargin(0);

    XYBlockRenderer renderer = new XYBlockRenderer();
    if (xyBlockPlot.getBlockWidth() != null) {
        renderer.setBlockWidth(xyBlockPlot.getBlockWidth());
    }/*  w  w  w. j a  v  a2s .c om*/
    if (xyBlockPlot.getBlockHeight() != null) {
        renderer.setBlockHeight(xyBlockPlot.getBlockHeight());
    }
    if (xyBlockPlot.getBlockAnchor() != null) {
        renderer.setBlockAnchor(ConstantTransform.rectangleAnchor(xyBlockPlot.getBlockAnchor()));
    }
    LookupPaintScale paintScale = new LookupPaintScale(xyBlockPlot.getDefaultLowerBound(),
            xyBlockPlot.getDefaultUpperBound(), xyBlockPlot.getDefaultPaint());
    for (DRIPaintScale scale : xyBlockPlot.getPaintScales()) {
        paintScale.add(scale.getValue(), scale.getPaint());
    }
    renderer.setPaintScale(paintScale);

    chart.getXYPlot().setRenderer(renderer);

    LegendItemCollection legendItems = new LegendItemCollection();
    for (DRIPaintScale scale : xyBlockPlot.getPaintScales()) {
        legendItems.add(new LegendItem(scale.getLabel(), scale.getPaint()));
    }
    chart.getXYPlot().setFixedLegendItems(legendItems);
}

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PaintScaleFactory.java

public static LookupPaintScale getLookupPaintScale(int type, double lower, double upper, double maxValue) {
    LookupPaintScale lps = new LookupPaintScale(lower, upper, defaultColor);
    double inc = maxColor / maxDivisions;
    double cinc = inc * 2.0;
    int half = maxDivisions / 2;
    double cdiv = maxValue / maxDivisions;

    lps.add(0, Color.black);//from  w w w  .  java 2s  .c o m

    if (type == 0) {
        Color[] gColors = generateColors(maxDivisions - 1);
        for (int i = 1; i < maxDivisions; i++) {
            double cval = (double) i * cdiv;
            lps.add(cval, gColors[i - 1]);
        }
    } else if (type == 1) {
        for (int i = 1; i < maxDivisions; i++) {
            //
            boolean firstHalf = i < half;
            int rval = firstHalf ? 0 : (int) ((i - half) * cinc);
            int gval = firstHalf ? (int) (i * cinc) : 510 - (int) (i * cinc);
            int bval = firstHalf ? 255 - (int) (i * cinc) : 0;
            double cval = (double) i * cdiv;
            lps.add(cval, new Color(rval, gval, bval));
            //        System.err.println(i + ") V:" + cval + ", R:" + rval + ", G:" + gval + ", B:" + bval);
        }
    } else {
        for (int i = 1; i < maxDivisions; i++) {
            // red slowly ramps up, and blue slowly ramps down
            boolean firstHalf = i < half;
            int rval = (int) (i * inc);
            int gval = firstHalf ? (int) (i * cinc) : 510 - (int) (i * cinc);
            int bval = 255 - rval;
            double cval = (double) i * cdiv;
            lps.add(cval, new Color(rval, gval, bval));
            //        System.err.println(i + ") V:" + cval + ", R:" + rval + ", G:" + gval + ", B:" + bval);
        }
    }
    //    System.err.println("Color type: " + type);
    return lps;
}

From source file:org.esa.beam.smos.visat.GridPointBtDataFlagmatrixToolView.java

@Override
protected JComponent createGridPointComponent() {
    dataset = new DefaultXYZDataset();

    final NumberAxis xAxis = new NumberAxis("Record #");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);//from ww w. ja  v  a2 s . co m
    xAxis.setUpperMargin(0.0);

    flagNames = createFlagNames(Dddb.getInstance().getFlagDescriptors(DEFAULT_FLAG_DESCRIPTOR_IDENTIFIER));
    final NumberAxis yAxis = createRangeAxis(flagNames);

    final LookupPaintScale paintScale = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    paintScale.add(0.0, Color.BLACK);
    paintScale.add(1.0, Color.RED);
    paintScale.add(2.0, Color.GREEN);
    paintScale.add(3.0, Color.BLUE);
    paintScale.add(4.0, Color.YELLOW);

    final XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    renderer.setBaseToolTipGenerator(new FlagToolTipGenerator(flagNames));

    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setForegroundAlpha(0.5f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage("No data");

    chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chartPanel = new ChartPanel(chart);

    return chartPanel;
}

From source file:inflor.core.utils.PlotUtils.java

public static LookupPaintScale createPaintScale(double zMax, ColorSchemes colorScheme) {
    PaintModel pm = new PaintModel(colorScheme, zMax);
    Paint[] paints = pm.getPaints();
    double[] levels = pm.getLevels();
    LookupPaintScale paintScale = new LookupPaintScale(0, pm.getThreshold(), Color.GRAY);
    for (int i = 0; i < levels.length; i++) {
        paintScale.add(levels[i], paints[i]);
    }//w ww. j a  va 2s .com
    return paintScale;
}

From source file:org.esa.smos.gui.gridpoint.GridPointBtDataFlagmatrixTopComponent.java

@Override
protected JComponent createGridPointComponent() {
    dataset = new DefaultXYZDataset();

    final NumberAxis xAxis = new NumberAxis("Record #");
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);/*from  w w  w. jav a  2s .c om*/
    xAxis.setUpperMargin(0.0);

    final List<FlagDescriptor> flagDescriptorList = Dddb.getInstance()
            .getFlagDescriptors(DEFAULT_FLAG_DESCRIPTOR_IDENTIFIER).asList();
    flagDescriptors = flagDescriptorList.toArray(new FlagDescriptor[flagDescriptorList.size()]);
    final String[] flagNames = createFlagNames(flagDescriptors);
    final NumberAxis yAxis = createRangeAxis(flagNames);

    final LookupPaintScale paintScale = new LookupPaintScale(0.0, 4.0, Color.WHITE);
    paintScale.add(0.0, Color.BLACK);
    paintScale.add(1.0, Color.RED);
    paintScale.add(2.0, Color.GREEN);
    paintScale.add(3.0, Color.BLUE);
    paintScale.add(4.0, Color.YELLOW);

    renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    renderer.setBaseToolTipGenerator(new FlagToolTipGenerator(flagNames));

    plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setForegroundAlpha(0.5f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setNoDataMessage("No data");

    chart = new JFreeChart(null, plot);
    chart.removeLegend();
    chartPanel = new ChartPanel(chart);

    return chartPanel;
}

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

/**
 * Permet de modifier l'chelle de couleur utilise par le graphique. Cela
 * va crer un gradient de couleur entre les deux couleurs spcifies, la
 * premire couleur correspondant aux valeurs les plus fortes de l'chelle
 * des donnes  reprsenter. Les bornes infrieure et suprieure permettent
 * de prciser l'tendue des donnes reprsentes par cette chelle de
 * couleur.//from ww w  .j  a va 2s.c om
 * 
 * @param colorMin
 *            Couleur d'arrive du gradient reprsentant les plus faibles
 *            valeurs de l'chelle.
 * @param colorMax
 *            Couleur de dpart du gradient reprsentant les plus fortes
 *            valeurs de l'chelle.
 * @param lowerBound
 *            Borne infrieure de l'chelle des donnes reprsentes.
 * @param upperBound
 *            Bornes suprieure de l'chelle des donnes reprsentes.
 */
public void setColorGradient(Color colorMin, Color colorMax, double lowerBound, double upperBound) {
    LookupPaintScale scale = new LookupPaintScale(lowerBound, upperBound, Color.lightGray);
    double r1, r2, dr, g1, g2, dg, b1, b2, db;
    int nbVal = (int) (upperBound - lowerBound + 0.5);

    // Acquisition des composantes
    r1 = colorMax.getRed();
    g1 = colorMax.getGreen();
    b1 = colorMax.getBlue();
    r2 = colorMin.getRed();
    g2 = colorMin.getGreen();
    b2 = colorMin.getBlue();

    // Calcul du delta entre les composantes
    dr = (r2 - r1) / nbVal;
    dg = (g2 - g1) / nbVal;
    db = (b2 - b1) / nbVal;

    // Cration du gradient
    for (int i = 0; i < nbVal; i++) {
        scale.add(lowerBound + i, new Color((int) r2, (int) g2, (int) b2));
        r2 = r2 - dr;
        g2 = g2 - dg;
        b2 = b2 - db;
    }

    // Mise  jour du graphique
    this.renderer.setPaintScale(scale);
    this.scaleLegend.setScale(scale);

    // Du fait que la lgende n'est pas lie aux modifications de la courbe,
    // il faut rcrer la lgende  la main.
    this.chart.removeSubtitle(this.scaleLegend);
    createPaintScaleLegend(scale);
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

protected static final LookupPaintScale createLUT(final int ncol, final float vmin, final float vmax,
        final Color start, final Color med, final Color end) {
    final float[][] colors = new float[][] {
            { start.getRed() / 255f, start.getGreen() / 255f, start.getBlue() / 255f, start.getAlpha() / 255f },
            { med.getRed() / 255f, med.getGreen() / 255f, med.getBlue() / 255f, med.getAlpha() / 255f },
            { end.getRed() / 255f, end.getGreen() / 255f, end.getBlue() / 255f, end.getAlpha() / 255f } };
    final float[] limits = new float[] { 0, 0.5f, 1 };
    final LookupPaintScale lut = new LookupPaintScale(vmin, vmax, med);
    float val;
    float r, g, b, a;
    for (int j = 0; j < ncol; j++) {
        val = j / (ncol - 0.99f);
        int i = 0;
        for (i = 0; i < limits.length; i++) {
            if (val < limits[i]) {
                break;
            }/*  w ww.  j  a v a 2  s .c  om*/
        }
        i = i - 1;
        r = colors[i][0] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][0] - colors[i][0]);
        g = colors[i][1] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][1] - colors[i][1]);
        b = colors[i][2] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][2] - colors[i][2]);
        a = colors[i][3] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][3] - colors[i][3]);
        lut.add(val * (vmax - vmin) + vmin, new Color(r, g, b, a));
    }
    return lut;
}