Example usage for org.jfree.chart.plot XYPlot addRangeMarker

List of usage examples for org.jfree.chart.plot XYPlot addRangeMarker

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot addRangeMarker.

Prototype

public void addRangeMarker(int index, Marker marker, Layer layer) 

Source Link

Document

Adds a marker for a specific dataset/renderer and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:pisco.batch.visu.BatchingChartFactory.java

public static XYPlot createBatchPlot(Batch[] batches, int capacity) {
    final XYBarRenderer renderer = new StackedXYBarRendererPaletteByItems(makePalette(batches.length));
    renderer.setShadowVisible(false);//  w w w  .  j a v  a2  s  .  c  o m
    renderer.setShadowXOffset(0);
    renderer.setDrawBarOutline(true);
    renderer.setBaseOutlineStroke(new BasicStroke(2));
    final BatchLabelToolTipGenerator lpg = new BatchLabelToolTipGenerator();
    renderer.setBaseItemLabelGenerator(lpg);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseToolTipGenerator(lpg);
    XYPlot plot = new XYPlot(new BatchProcessingDataset(batches), null, createIntegerAxis("Load"), renderer);

    if (capacity > 0) {
        Marker capaMarker = createCapacityMarker(capacity, "Capacity", B_RED);
        plot.addRangeMarker(0, capaMarker, Layer.FOREGROUND);
    }
    return plot;
}

From source file:windows.sensorWindow.java

/**
 * creates all relevant data and adds it into the corresponding maps
 * //  w ww .  j av a2s .c o  m
 * @param UID
 *            UID of the plotting sensor
 */
@SuppressWarnings("deprecation")
public static void addPlot(Brick newBrick) {
    // create series
    TimeSeries newSeries = new TimeSeries("" + 0, Millisecond.class);
    TimeSeries newSeries2 = new TimeSeries("" + 0, Millisecond.class);
    TimeSeries newSeries3 = new TimeSeries("" + 0, Millisecond.class);
    TimeSeries newSeries4 = new TimeSeries("" + 0, Millisecond.class);
    TimeSeries newSeries5 = new TimeSeries("" + 0, Millisecond.class);
    TimeSeries newSeries6 = new TimeSeries("" + 0, Millisecond.class);

    Measurement m1 = new Measurement(maxValues, maxCycles, newBrick.uid, 0);
    valuesMap.put(newBrick.uid, m1);
    if (newBrick.checked3 == true) {
        Measurement m2 = new Measurement(maxValues, maxCycles, newBrick.uid, 1);
        values2Map.put(newBrick.uid, m2);
    }

    // create entry in state map
    plot1StateMap.put(newBrick.uid, 0);
    plot2StateMap.put(newBrick.uid, 0);

    // create index map entry
    tmplindex.put(newBrick.uid, 0);

    // create avrgCtrlEnabled maps
    if (newBrick.controlAverage == true)
        avrgCtrl1Enabled.put(newBrick.uid, true);
    else
        avrgCtrl1Enabled.put(newBrick.uid, false);
    if (newBrick.controlAverage2 == true)
        avrgCtrl2Enabled.put(newBrick.uid, true);
    else
        avrgCtrl2Enabled.put(newBrick.uid, false);

    // create series map entry
    seriesMap.put(newBrick.uid, newSeries);
    seriesMap2.put(newBrick.uid, newSeries2);
    seriesMap3.put(newBrick.uid, newSeries3);
    seriesMap4.put(newBrick.uid, newSeries4);
    seriesMap5.put(newBrick.uid, newSeries3);
    seriesMap6.put(newBrick.uid, newSeries4);

    // create collection map entry
    seriesCollectionMap.put(newBrick.uid, new TimeSeriesCollection(newSeries));
    seriesCollectionMap2.put(newBrick.uid, new TimeSeriesCollection(newSeries2));
    tmplCollection1_1.put(newBrick.uid, new TimeSeriesCollection(newSeries3));
    tmplCollection1_2.put(newBrick.uid, new TimeSeriesCollection(newSeries4));
    tmplCollection2_1.put(newBrick.uid, new TimeSeriesCollection(newSeries5));
    tmplCollection2_2.put(newBrick.uid, new TimeSeriesCollection(newSeries6));

    // create plot map entry, special case for current/voltage brick, since
    // it has 2 parallel measurements and therefore 2 graphs must be treated
    XYPlot tmpSubPlot;
    tmpSubPlot = new XYPlot(seriesCollectionMap.get(newBrick.uid), null, null, new StandardXYItemRenderer());

    // create the 1st graph
    if (newBrick.checked2 == true) {
        // create plot map entry
        NumberAxis rangeAxis = new NumberAxis(
                String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)));
        rangeAxis.setAutoRangeIncludesZero(true);
        tmpSubPlot.setRangeAxis(0, rangeAxis);
        rangeAxis.setLabelPaint(Color.BLUE);
        rangeAxis.setVisible(newBrick.checked2);
        tmpSubPlot.setDataset(0, seriesCollectionMap.get(newBrick.uid));

        // set dot - shape
        // Shape cross = ShapeUtilities.createDiagonalCross(3, 1);

        // create and store renderer
        XYItemRenderer renderer1 = new XYLineAndShapeRenderer();
        renderer1 = tmpSubPlot.getRenderer();
        renderer1.setSeriesPaint(0, Color.BLUE);
        renderer1.setSeriesStroke(0, new BasicStroke(3));
        // line = dashes:
        // float dash[] = {5.0f};
        // renderer1.setSeriesStroke( 0, new
        // BasicStroke(3,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
        // 10.0f, dash, 0.0f));
        // renderer1.setSeriesShape(0, cross);
        tmpSubPlot.setRenderer(0, renderer1);

        // set colors
        tmpSubPlot.setBackgroundPaint(Color.white);
        tmpSubPlot.setDomainGridlinePaint(Color.lightGray);
        tmpSubPlot.setRangeGridlinePaint(Color.lightGray);
        // tmpSubPlot.setRenderer(renderer2);

        // set font
        rangeAxis.setLabelFont(customFonts.get("axisLabelFont"));
        rangeAxis.setTickLabelFont(customFonts.get("axisValueFont"));

        // create template graph
        // if (newBrick.ctrlTmpl[0] == true)
        // {
        tmpSubPlot.setDataset(2, tmplCollection1_1.get(newBrick.uid));

        XYItemRenderer renderer3 = new XYLineAndShapeRenderer();
        int width = computeTmplPlotWidth(newBrick.tmpl1Width);
        BasicStroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);// , 10.0f, dash, 0.0f);
        renderer3.setSeriesPaint(0, Color.GREEN);
        // renderer3.setSeriesStroke( 0, new BasicStroke( 1 ) );
        renderer3.setSeriesStroke(0, stroke);
        renderer3.setSeriesVisible(0, newBrick.ctrlTmpl[0]);
        rendererMap3.put(newBrick.uid, renderer3);
        tmpSubPlot.setRenderer(2, rendererMap3.get(newBrick.uid));
        // }

        // put everything to the maps
        rendererMap.put(newBrick.uid, renderer1);
        plotMap.put(newBrick.uid, tmpSubPlot);
        axisMap.put(newBrick.uid, rangeAxis);
    }

    // create the 2nd graph
    if (newBrick.checked3 == true) {
        // set second axis for voltage/ampere brick
        NumberAxis secondaryAxis = new NumberAxis(
                String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)));
        secondaryAxis.setAutoRangeIncludesZero(true);
        tmpSubPlot.setRangeAxis(1, secondaryAxis);
        secondaryAxis.setLabelPaint(Color.RED);
        secondaryAxis.setVisible(newBrick.checked3);
        tmpSubPlot.setDataset(1, seriesCollectionMap2.get(newBrick.uid));
        tmpSubPlot.mapDatasetToRangeAxis(1, 1);

        // set font
        secondaryAxis.setLabelFont(customFonts.get("axisLabelFont"));
        secondaryAxis.setTickLabelFont(customFonts.get("axisValueFont"));

        // create and store renderer
        XYItemRenderer renderer2 = new StandardXYItemRenderer();
        // renderer2 = tmpSubPlot.getRenderer();
        renderer2.setSeriesPaint(1, Color.RED);
        renderer2.setSeriesStroke(0, new BasicStroke(3));
        tmpSubPlot.setRenderer(1, renderer2);

        // set colors
        tmpSubPlot.setBackgroundPaint(Color.white);
        tmpSubPlot.setDomainGridlinePaint(Color.lightGray);
        tmpSubPlot.setRangeGridlinePaint(Color.lightGray);

        // ----------------------------------------------------------------------------------
        // create min1 critical map value
        ValueMarker vm5 = new ValueMarker(newBrick.tresholdMin2);
        markerMapMin2Critical.put(newBrick.uid, vm5);
        // set critical line
        markerMapMin2Critical.get(newBrick.uid).setPaint(Color.red);
        markerMapMin2Critical.get(newBrick.uid).setLabel(
                String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " critical min");
        markerMapMin2Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerMapMin2Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        tmpSubPlot.addRangeMarker(1, markerMapMin2Critical.get(newBrick.uid), Layer.BACKGROUND);

        // create min1 warning map value
        ValueMarker vm6 = new ValueMarker(
                newBrick.tresholdMin2 + newBrick.tresholdMin2 * warningPercentage / 100);
        markerMapMin2Warning.put(newBrick.uid, vm6);
        // set warning line
        markerMapMin2Warning.get(newBrick.uid).setPaint(Color.orange);
        markerMapMin2Warning.get(newBrick.uid).setLabel(
                String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " warning min");
        markerMapMin2Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerMapMin2Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        // tmpSubPlot.addRangeMarker(markerMapMin2Warning.get(newBrick.uid));
        tmpSubPlot.addRangeMarker(1, markerMapMin2Warning.get(newBrick.uid), Layer.BACKGROUND);

        // create max1 critical map value
        ValueMarker vm7 = new ValueMarker(newBrick.tresholdMax2);
        markerMapMax2Critical.put(newBrick.uid, vm7);
        // set critical line
        markerMapMax2Critical.get(newBrick.uid).setPaint(Color.red);
        markerMapMax2Critical.get(newBrick.uid).setLabel(
                String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " critical max");
        markerMapMax2Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerMapMax2Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        tmpSubPlot.addRangeMarker(1, markerMapMax2Critical.get(newBrick.uid), Layer.BACKGROUND);

        // create max1 warning map value
        ValueMarker vm8 = new ValueMarker(
                newBrick.tresholdMax2 + newBrick.tresholdMax2 * warningPercentage / 100);
        markerMapMax2Warning.put(newBrick.uid, vm8);
        // set warning line
        markerMapMax2Warning.get(newBrick.uid).setPaint(Color.orange);
        markerMapMax2Warning.get(newBrick.uid).setLabel(
                String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " warning max");
        markerMapMax2Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerMapMax2Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        tmpSubPlot.addRangeMarker(1, markerMapMax2Warning.get(newBrick.uid), Layer.BACKGROUND);

        // create and add min, max and average markers
        // create maxima marker
        ValueMarker vmMax = new ValueMarker(0);
        vmMax.setPaint(Color.orange);
        vmMax.setLabel("max");
        vmMax.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        vmMax.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        // create minima marker
        ValueMarker vmMin = new ValueMarker(0);
        vmMin.setPaint(Color.orange);
        vmMin.setLabel("min");
        vmMin.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        vmMin.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        // create average marker
        ValueMarker vmAvg = new ValueMarker(0);
        vmAvg.setPaint(Color.red);
        vmAvg.setLabel("average");
        vmAvg.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        vmAvg.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        // add to maps
        marker2Maxima.put(newBrick.uid, vmMax);
        marker2Minima.put(newBrick.uid, vmMin);
        marker2Average.put(newBrick.uid, vmAvg);
        // add to plot
        tmpSubPlot.addRangeMarker(1, vmMax, Layer.BACKGROUND);
        tmpSubPlot.addRangeMarker(1, vmMin, Layer.BACKGROUND);
        tmpSubPlot.addRangeMarker(1, vmAvg, Layer.BACKGROUND);

        // create and add avrgCntrMarkers
        // create upper marker
        ValueMarker avrgCtrl2high = new ValueMarker(newBrick.getAvg2high());
        avrgCtrl2high.setPaint(Color.orange);
        avrgCtrl2high.setLabel("avrg high");
        avrgCtrl2high.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        avrgCtrl2high.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        // create lower marker
        ValueMarker avrgCtrl2low = new ValueMarker(newBrick.getAvg2low());
        avrgCtrl2low.setPaint(Color.orange);
        avrgCtrl2low.setLabel("avrg low");
        avrgCtrl2low.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        avrgCtrl2low.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        // add both markers
        avrg2High.put(newBrick.uid, avrgCtrl2high);
        avrg2Low.put(newBrick.uid, avrgCtrl2low);
        // add both to plot
        if (newBrick.controlAverage2) {
            tmpSubPlot.addRangeMarker(1, avrgCtrl2high, Layer.BACKGROUND);
            tmpSubPlot.addRangeMarker(1, avrgCtrl2low, Layer.BACKGROUND);
        }
        // ----------------------------------------------------------------------------------

        // put everything to the map
        rendererMap2.put(newBrick.uid, renderer2);
        plotMap.put(newBrick.uid, tmpSubPlot);
        axisMap2.put(newBrick.uid, secondaryAxis);
    }

    // 1st graph
    // markers--------------------------------------------------------------------------------------------------
    // create min1 critical map value
    ValueMarker vm1 = new ValueMarker(newBrick.tresholdMin1);
    markerMapMin1Critical.put(newBrick.uid, vm1);
    // set critical line
    markerMapMin1Critical.get(newBrick.uid).setPaint(Color.red);
    // / .setLabel("critical");
    // markerMapMin1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.BOTTOM);
    markerMapMin1Critical.get(newBrick.uid)
            .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " critical min");
    markerMapMin1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT);
    markerMapMin1Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plotMap.get(newBrick.uid).addRangeMarker(markerMapMin1Critical.get(newBrick.uid));

    // create min1 warning map value
    ValueMarker vm2 = new ValueMarker(newBrick.tresholdMin1 + newBrick.tresholdMin1 * warningPercentage / 100);
    markerMapMin1Warning.put(newBrick.uid, vm2);
    // set warning line
    markerMapMin1Warning.get(newBrick.uid).setPaint(Color.orange);
    // marker2Map.get(newBrick.uid).setPaint(Color.);
    // / marker2Map.get(newBrick.uid).setLabel("warning");
    markerMapMin1Warning.get(newBrick.uid)
            .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " warning min");
    markerMapMin1Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT);
    markerMapMin1Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plotMap.get(newBrick.uid).addRangeMarker(markerMapMin1Warning.get(newBrick.uid));

    // create max1 critical map value
    ValueMarker vm3 = new ValueMarker(newBrick.tresholdMax1);
    markerMapMax1Critical.put(newBrick.uid, vm3);
    // set critical line
    markerMapMax1Critical.get(newBrick.uid).setPaint(Color.red);
    // / .setLabel("critical");
    // markerMapMax1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.BOTTOM);
    markerMapMax1Critical.get(newBrick.uid)
            .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " critical max");
    markerMapMax1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT);
    markerMapMax1Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plotMap.get(newBrick.uid).addRangeMarker(markerMapMax1Critical.get(newBrick.uid));

    // create max1 warning map value
    ValueMarker vm4 = new ValueMarker(newBrick.tresholdMax1 + newBrick.tresholdMax1 * warningPercentage / 100);
    markerMapMax1Warning.put(newBrick.uid, vm4);
    // set warning line
    markerMapMax1Warning.get(newBrick.uid).setPaint(Color.orange);
    markerMapMax1Warning.get(newBrick.uid)
            .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " warning max");
    markerMapMax1Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT);
    markerMapMax1Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plotMap.get(newBrick.uid).addRangeMarker(markerMapMax1Warning.get(newBrick.uid));

    // create and add min, max and average markers
    // create maxima marker
    ValueMarker vmMax = new ValueMarker(0);
    vmMax.setPaint(Color.cyan);
    vmMax.setLabel("max");
    vmMax.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    vmMax.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    // create minima marker
    ValueMarker vmMin = new ValueMarker(0);
    vmMin.setPaint(Color.cyan);
    vmMin.setLabel("min");
    vmMin.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    vmMin.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    // create average marker
    ValueMarker vmAvg = new ValueMarker(0);
    vmAvg.setPaint(Color.blue);
    vmAvg.setLabel("average");
    vmAvg.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    vmAvg.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    // add to maps
    markerMaxima.put(newBrick.uid, vmMax);
    markerMinima.put(newBrick.uid, vmMin);
    markerAverage.put(newBrick.uid, vmAvg);
    // add to plot
    plotMap.get(newBrick.uid).addRangeMarker(vmMax);
    plotMap.get(newBrick.uid).addRangeMarker(vmMin);
    plotMap.get(newBrick.uid).addRangeMarker(vmAvg);

    // create and add avrgCntrMarkers
    // create upper marker
    ValueMarker avrgCtrl1high = new ValueMarker(newBrick.getAvg1high());
    avrgCtrl1high.setPaint(Color.orange);
    avrgCtrl1high.setLabel("avrg high");
    avrgCtrl1high.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    avrgCtrl1high.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    // create lower marker
    ValueMarker avrgCtrl1low = new ValueMarker(newBrick.getAvg1low());
    avrgCtrl1low.setPaint(Color.orange);
    avrgCtrl1low.setLabel("avrg low");
    avrgCtrl1low.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    avrgCtrl1low.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    // add both markers
    avrg1High.put(newBrick.uid, avrgCtrl1high);
    avrg1Low.put(newBrick.uid, avrgCtrl1low);
    // add both to plot
    if (newBrick.controlAverage) {
        plotMap.get(newBrick.uid).addRangeMarker(avrgCtrl1high);
        plotMap.get(newBrick.uid).addRangeMarker(avrgCtrl1low);
    }
    // -----------------------------------------------------------------------------------------------------

    // set title
    NumberAxis axisForTitleOnly = new NumberAxis(
            data.constants.brickIdMap.get(newBrick.deviceIdentifier) + " (" + newBrick.uid + ")");
    axisForTitleOnly.setLabelFont(customFonts.get("titleFont"));
    axisForTitleOnly.setTickLabelsVisible(false);
    axisForTitleOnly.setTickMarksVisible(false);
    axisForTitleOnly.setMinorTickMarksVisible(false);
    axisForTitleOnly.setAxisLineVisible(false);
    plotMap.get(newBrick.uid).setDomainAxis(1, axisForTitleOnly);

    // add subplot to the main plot
    plot.add(plotMap.get(newBrick.uid));
}