Example usage for org.jfree.util UnitType ABSOLUTE

List of usage examples for org.jfree.util UnitType ABSOLUTE

Introduction

In this page you can find the example usage for org.jfree.util UnitType ABSOLUTE.

Prototype

UnitType ABSOLUTE

To view the source code for org.jfree.util UnitType ABSOLUTE.

Click Source Link

Document

Absolute.

Usage

From source file:org.esa.beam.visat.toolviews.diag.TileCacheMonitor.java

/**
 * Creates a new monitor panel.//from  ww  w  .j  av a 2 s  .  co m
 *
 * @return the monitor panel
 */
public JPanel createPanel() {

    JPanel mainPanel = new JPanel(new BorderLayout());
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[4];
    this.datasets[0] = addSubPlot(plot, "#Tiles");
    this.datasets[1] = addSubPlot(plot, "#Hits");
    this.datasets[2] = addSubPlot(plot, "#Misses");
    this.datasets[3] = addSubPlot(plot, "Mem (kB)");

    JFreeChart chart = new JFreeChart(plot);
    LegendTitle legend = (LegendTitle) chart.getSubtitle(0);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0, 4, 0, 4));
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(60000.0); // 60 seconds

    textarea = new JTextArea();
    tableModel = new TileCacheTableModel();
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 470));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    tabbedPane = new JTabbedPane();
    tabbedPane.add(CACHE_INFO_TAB, new JScrollPane(textarea));
    tabbedPane.add(CACHE_CHART_TAB, chartPanel);
    tabbedPane.add(IMAGES_TAB, new JScrollPane(new JTable(tableModel)));
    tabbedPane.setSelectedIndex(0);

    mainPanel.add(tabbedPane);

    return mainPanel;
}

From source file:org.rdv.viz.chart.FastXYItemRenderer.java

@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    boolean itemVisible = getItemVisible(series, item);

    // setup for collecting optional entity info...
    Shape entityArea = null;/*  ww w  . ja v a  2s.  c  o  m*/
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        itemVisible = false;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (item == 0) {
            previousDrawnItem = 1;
        }

        if (getDrawSeriesLineAsPath()) {
            State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.setLastPointGood(false);
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                if (s.getSeriesIndex() == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...
            double x0 = dataset.getXValue(series, item - previousDrawnItem);
            double y0 = dataset.getYValue(series, item - previousDrawnItem);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    int numX = dataset.getItemCount(series);
                    double minX = dataset.getXValue(series, 0);
                    double maxX = dataset.getXValue(series, numX - 1);
                    if (getGapThresholdType() == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= getGapThreshold();
                    } else {
                        drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                    }
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    // Only draw line if it is more than a pixel away from the
                    // previous one
                    if ((transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2
                            || transY1 - transY0 < -2)) {
                        previousDrawnItem = 1;

                        if (orientation == PlotOrientation.HORIZONTAL) {
                            state.workingLine.setLine(transY0, transX0, transY1, transX1);
                        } else if (orientation == PlotOrientation.VERTICAL) {
                            state.workingLine.setLine(transX0, transY0, transX1, transY1);
                        }

                        if (state.workingLine.intersects(dataArea)) {
                            g2.draw(state.workingLine);
                        }
                    } else {
                        // Increase counter for the previous drawn item.
                        previousDrawnItem++;
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    // add a cursor to indicate the position of the last data item
    if (getCursorVisible() && item == dataset.getItemCount(series) - 1) {
        Line2D cursorX = new Line2D.Double(transX1 - DEFAULT_CURSOR_SIZE, transY1,
                transX1 + DEFAULT_CURSOR_SIZE, transY1);
        g2.draw(cursorX);
        Line2D cursorY = new Line2D.Double(transX1, transY1 - DEFAULT_CURSOR_SIZE, transX1,
                transY1 + DEFAULT_CURSOR_SIZE);
        g2.draw(cursorY);
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item...
    if (entities != null && dataArea.contains(xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}

From source file:cs.gui.stats.PerformanceStats.java

private ChartPanel createChart(String axisLabel, int type) {
    int width = (screenSize.width - (screenSize.width / 35));
    int height = (int) (screenSize.height - (screenSize.height / (double) 4));

    //int width = (screenSize.width - (screenSize.width / 35)) / 2;
    //int height = (int) (screenSize.height - (screenSize.height / (double) 4)) / 2;

    lastValue = new double[SUBPLOT_COUNT];
    //================= visualise standard chart ==========================
    CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time"));

    lastValue[0] = 100D;/* w  w  w. ja v  a 2  s  .  c  o  m*/
    TimeSeries timeseries = null;
    XYPlot xyplot = null;

    //add new timeseries to modularity row
    datasets[type] = new TimeSeriesCollection();

    NumberAxis numberaxis = new NumberAxis(axisLabel);
    numberaxis.setAutoRangeIncludesZero(true);

    //fast
    StandardXYItemRenderer xyItemRender = new StandardXYItemRenderer();
    //original
    //xyItemRender = new StandardXYItemRenderer();

    xyItemRender.setSeriesStroke(0,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(1,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(2,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(3,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));

    //TODO colours need to be defined statically before the renderer is created!
    xyplot = new XYPlot(datasets[type], null, numberaxis, xyItemRender);

    switch (type) {
    case 0: {
        xyItemRender.setSeriesPaint(0, Color.BLACK);
        timeseries = new TimeSeries("Number of existing threads", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
        timeseries = new TimeSeries("Number of answered threads", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    case 1: {
        xyItemRender.setSeriesPaint(0, Color.YELLOW);
        timeseries = new TimeSeries("Mean thread answer time (per day)", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    case 2: {
        xyItemRender.setSeriesPaint(0, Color.GRAY);
        timeseries = new TimeSeries("Number of thread replies", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    case 3: {
        xyItemRender.setSeriesPaint(0, Color.GREEN);
        timeseries = new TimeSeries("New thread arrival activity change (%)", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
        xyItemRender.setSeriesPaint(1, Color.BLUE);
        timeseries = new TimeSeries("Thread reply activity change (%)", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    case 4: {
        xyItemRender.setSeriesPaint(0, Color.GREEN);
        timeseries = new TimeSeries("Mean thread aswer time (per month)", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    }

    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    combineddomainxyplot.add(xyplot);

    ChartPanel chart = null;

    switch (type) {
    case 0: {
        jfreechart1 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart1.getSubtitle(0);

        //set legend fonts
        jfreechart1.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart1.setBorderPaint(Color.black);
        jfreechart1.setBorderVisible(true);
        jfreechart1.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis1 = combineddomainxyplot.getDomainAxis();
        dateAxis1 = (DateAxis) valueAxis1;

        if (scope1 == 0) {
            valueAxis1.setAutoRange(true);
        } else {
            valueAxis1.setFixedAutoRange(scope1);
        }

        chart = new ChartPanel(jfreechart1);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis1, dateAxis1, ddlScope1));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart1.setAntiAlias(false);
    }
        break;
    case 1: {

        jfreechart2 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart2.getSubtitle(0);

        //set legend fonts
        jfreechart2.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart2.setBorderPaint(Color.black);
        jfreechart2.setBorderVisible(true);
        jfreechart2.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis2 = combineddomainxyplot.getDomainAxis();
        dateAxis2 = (DateAxis) valueAxis2;

        if (scope2 == 0) {
            valueAxis2.setAutoRange(true);
        } else {
            valueAxis2.setFixedAutoRange(scope2);
        }

        chart = new ChartPanel(jfreechart2);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis2, dateAxis2, ddlScope2));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart2.setAntiAlias(false);
    }
        break;
    case 2: {

        jfreechart3 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart3.getSubtitle(0);

        //set legend fonts
        jfreechart3.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart3.setBorderPaint(Color.black);
        jfreechart3.setBorderVisible(true);
        jfreechart3.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis3 = combineddomainxyplot.getDomainAxis();
        dateAxis3 = (DateAxis) valueAxis3;

        if (scope3 == 0) {
            valueAxis3.setAutoRange(true);
        } else {
            valueAxis3.setFixedAutoRange(scope3);
        }

        chart = new ChartPanel(jfreechart3);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis3, dateAxis3, ddlScope3));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart3.setAntiAlias(false);
    }
        break;
    case 3: {
        jfreechart4 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart4.getSubtitle(0);

        //set legend fonts
        jfreechart4.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart4.setBorderPaint(Color.black);
        jfreechart4.setBorderVisible(true);
        jfreechart4.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis4 = combineddomainxyplot.getDomainAxis();
        dateAxis4 = (DateAxis) valueAxis4;

        if (scope4 == 0) {
            valueAxis4.setAutoRange(true);
        } else {
            valueAxis4.setFixedAutoRange(scope4);
        }

        chart = new ChartPanel(jfreechart4);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis4, dateAxis4, ddlScope4));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart4.setAntiAlias(false);
    }
        break;
    case 4: {
        jfreechart5 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart5.getSubtitle(0);

        //set legend fonts
        jfreechart5.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart5.setBorderPaint(Color.black);
        jfreechart5.setBorderVisible(true);
        jfreechart5.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis5 = combineddomainxyplot.getDomainAxis();
        dateAxis5 = (DateAxis) valueAxis5;

        if (scope5 == 0) {
            valueAxis5.setAutoRange(true);
        } else {
            valueAxis5.setFixedAutoRange(scope5);
        }

        chart = new ChartPanel(jfreechart5);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis5, dateAxis5, ddlScope5));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart5.setAntiAlias(false);
    }
        break;
    }

    return chart;

}

From source file:org.trade.ui.chart.renderer.MACDItemRenderer.java

public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, double x0, double y0, double x1, double y1,
        int lastItem, int series, int item, CrosshairState crosshairState, int pass, int numX, double minX,
        double maxX, Paint color, XYDataset dataset) {

    boolean itemVisible = getItemVisible(series, item);

    // setup for collecting optional entity info...
    Shape entityArea = null;//w  ww .  java2s  .c o  m
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    paint = color;
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (this.drawSeriesLineAsPath) {
            State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.lastPointGood = false;
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == lastItem) {
                if (s.seriesIndex == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...

            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                    }
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    if (orientation == PlotOrientation.HORIZONTAL) {
                        state.workingLine.setLine(transY0, transX0, transY1, transX1);
                    } else if (orientation == PlotOrientation.VERTICAL) {
                        state.workingLine.setLine(transX0, transY0, transX1, transY1);
                    }

                    if (state.workingLine.intersects(dataArea)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}

From source file:cs.stats.gui.StatsCharts.java

private ChartPanel createChart(String axisLabel, int type) {
    int width = (screenSize.width - (screenSize.width / 35));
    int height = (int) (screenSize.height - (screenSize.height / (double) 4));

    //int width = (screenSize.width - (screenSize.width / 35)) / 2;
    //int height = (int) (screenSize.height - (screenSize.height / (double) 4)) / 2;

    lastValue = new double[SUBPLOT_COUNT];
    //================= visualise standard chart ==========================
    CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time"));

    lastValue[0] = 100D;//from ww w. j  a v a 2s  . c  om
    TimeSeries timeseries = null;
    XYPlot xyplot = null;

    //add new timeseries to modularity row
    datasets[type] = new TimeSeriesCollection();

    NumberAxis numberaxis = new NumberAxis(axisLabel);
    numberaxis.setAutoRangeIncludesZero(true);

    //fast
    StandardXYItemRenderer xyItemRender = new StandardXYItemRenderer();
    //original
    //xyItemRender = new StandardXYItemRenderer();

    xyItemRender.setSeriesStroke(0,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(1,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(2,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(3,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(4,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(5,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(6,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(7,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(8,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));
    xyItemRender.setSeriesStroke(9,
            new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0));

    //TODO colours need to be defined statically before the renderer is created!
    xyplot = new XYPlot(datasets[type], null, numberaxis, xyItemRender);

    switch (type) {
    case 0: {
        xyItemRender.setSeriesPaint(0, Color.BLACK);
        timeseries = new TimeSeries("Reply rate 1.0", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(1, Color.BLUE);
        timeseries = new TimeSeries("Reply rate 0.9", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(2, Color.ORANGE);
        timeseries = new TimeSeries("Reply rate 0.8", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(3, Color.GREEN);
        timeseries = new TimeSeries("Reply rate 0.7", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(4, Color.MAGENTA);
        timeseries = new TimeSeries("Reply rate 0.6", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(5, Color.LIGHT_GRAY);
        timeseries = new TimeSeries("Reply rate 0.5", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(6, Color.YELLOW);
        timeseries = new TimeSeries("Reply rate 0.4", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        //            xyItemRender.setSeriesPaint(7, Color.PINK);
        //            timeseries = new TimeSeries("Reply rate 0.3", org.jfree.data.time.Hour.class);
        //            datasets[type].addSeries(timeseries);
        //
        //            xyItemRender.setSeriesPaint(8, Color.RED);
        //            timeseries = new TimeSeries("Reply rate 0.2", org.jfree.data.time.Hour.class);
        //            datasets[type].addSeries(timeseries);
        //
        //            xyItemRender.setSeriesPaint(9, Color.CYAN);
        //            timeseries = new TimeSeries("Reply rate 0.1", org.jfree.data.time.Hour.class);
        //            datasets[type].addSeries(timeseries);
    }
        break;
    case 1: {
        xyItemRender.setSeriesPaint(0, Color.BLACK);
        timeseries = new TimeSeries("0% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(1, Color.BLUE);
        timeseries = new TimeSeries("1% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(2, Color.ORANGE);
        timeseries = new TimeSeries("2% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(3, Color.GREEN);
        timeseries = new TimeSeries("3% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(4, Color.MAGENTA);
        timeseries = new TimeSeries("3.5% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(5, Color.LIGHT_GRAY);
        timeseries = new TimeSeries("4% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(6, Color.YELLOW);
        timeseries = new TimeSeries("4.5% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(7, Color.PINK);
        timeseries = new TimeSeries("5% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(8, Color.RED);
        timeseries = new TimeSeries("5.5% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);

        xyItemRender.setSeriesPaint(9, Color.CYAN);
        timeseries = new TimeSeries("6% of community users removed", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    case 2: {
        xyItemRender.setSeriesPaint(0, Color.GRAY);
        timeseries = new TimeSeries("Average number of thread replies (per hour)",
                org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    case 3: {
        xyItemRender.setSeriesPaint(0, Color.GREEN);
        timeseries = new TimeSeries("New thread arrival activity change (%)", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
        xyItemRender.setSeriesPaint(1, Color.BLUE);
        timeseries = new TimeSeries("Thread reply activity change (%)", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    case 4: {
        xyItemRender.setSeriesPaint(0, Color.GREEN);
        timeseries = new TimeSeries("Mean thread aswer time", org.jfree.data.time.Hour.class);
        datasets[type].addSeries(timeseries);
    }
        break;
    }

    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    //rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setTickUnit(new NumberTickUnit(0.1));

    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    combineddomainxyplot.add(xyplot);

    ChartPanel chart = null;

    switch (type) {
    case 0: {
        jfreechart1 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart1.getSubtitle(0);

        //set legend fonts
        jfreechart1.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart1.setBorderPaint(Color.black);
        jfreechart1.setBorderVisible(true);
        jfreechart1.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis1 = combineddomainxyplot.getDomainAxis();

        dateAxis1 = (DateAxis) valueAxis1;
        dateAxis1.setTickUnit(new DateTickUnit(1, 1));

        if (scope1 == 0) {
            valueAxis1.setAutoRange(true);
        } else {
            valueAxis1.setFixedAutoRange(scope1);
        }

        chart = new ChartPanel(jfreechart1);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        //chart.add(buildPlotDisplayManagementPanel(valueAxis1, dateAxis1, ddlScope1));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart1.setAntiAlias(false);
    }
        break;
    case 1: {

        jfreechart2 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart2.getSubtitle(0);

        //set legend fonts
        jfreechart2.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart2.setBorderPaint(Color.black);
        jfreechart2.setBorderVisible(true);
        jfreechart2.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis2 = combineddomainxyplot.getDomainAxis();
        dateAxis2 = (DateAxis) valueAxis2;
        dateAxis2.setTickUnit(new DateTickUnit(1, 1));

        if (scope2 == 0) {
            valueAxis2.setAutoRange(true);
        } else {
            valueAxis2.setFixedAutoRange(scope2);
        }

        chart = new ChartPanel(jfreechart2);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart2.setAntiAlias(false);
    }
        break;
    case 2: {

        jfreechart3 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart3.getSubtitle(0);

        //set legend fonts
        jfreechart3.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart3.setBorderPaint(Color.black);
        jfreechart3.setBorderVisible(true);
        jfreechart3.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis3 = combineddomainxyplot.getDomainAxis();
        dateAxis3 = (DateAxis) valueAxis3;

        if (scope3 == 0) {
            valueAxis3.setAutoRange(true);
        } else {
            valueAxis3.setFixedAutoRange(scope3);
        }

        chart = new ChartPanel(jfreechart3);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis3, dateAxis3, ddlScope3));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart3.setAntiAlias(false);
    }
        break;
    case 3: {
        jfreechart4 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart4.getSubtitle(0);

        //set legend fonts
        jfreechart4.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart4.setBorderPaint(Color.black);
        jfreechart4.setBorderVisible(true);
        jfreechart4.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis4 = combineddomainxyplot.getDomainAxis();
        dateAxis4 = (DateAxis) valueAxis4;

        if (scope4 == 0) {
            valueAxis4.setAutoRange(true);
        } else {
            valueAxis4.setFixedAutoRange(scope4);
        }

        chart = new ChartPanel(jfreechart4);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis4, dateAxis4, ddlScope4));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart4.setAntiAlias(false);
    }
        break;
    case 4: {
        jfreechart5 = new JFreeChart("", combineddomainxyplot);
        LegendTitle legendtitle = (LegendTitle) jfreechart5.getSubtitle(0);

        //set legend fonts
        jfreechart5.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11));

        legendtitle.setPosition(RectangleEdge.BOTTOM);
        legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D));
        jfreechart5.setBorderPaint(Color.black);
        jfreechart5.setBorderVisible(true);
        jfreechart5.setBackgroundPaint(Color.white);
        combineddomainxyplot.setBackgroundPaint(Color.lightGray);
        combineddomainxyplot.setDomainGridlinePaint(Color.white);
        combineddomainxyplot.setRangeGridlinePaint(Color.white);
        combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));

        valueAxis5 = combineddomainxyplot.getDomainAxis();
        dateAxis5 = (DateAxis) valueAxis5;

        if (scope5 == 0) {
            valueAxis5.setAutoRange(true);
        } else {
            valueAxis5.setFixedAutoRange(scope5);
        }

        chart = new ChartPanel(jfreechart5);
        chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        chart.add(buildPlotDisplayManagementPanel(valueAxis5, dateAxis5, ddlScope5));
        combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10));
        chart.setPreferredSize(new Dimension(width, height));

        jfreechart5.setAntiAlias(false);
    }
        break;
    }

    return chart;

}

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

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2/*from w  w  w .j  a  v  a2s . c o m*/
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area within which the data is being drawn.
 * @param info
 *            collects information about the drawing.
 * @param plot
 *            the plot (can be used to obtain standard color information etc).
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the dataset.
 * @param series
 *            the series index (zero-based).
 * @param item
 *            the item index (zero-based).
 * @param crosshairState
 *            crosshair information for the plot (<code>null</code> permitted).
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    boolean itemVisible = getItemVisible(series, item);

    // setup for collecting optional entity info...
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    final PlotOrientation orientation = plot.getOrientation();
    final Paint paint = getItemPaint(series, item);
    final Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        itemVisible = false;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (this.drawSeriesLineAsPath) {
            final State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.lastPointGood = false;
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                if (s.seriesIndex == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...
            final double x0 = dataset.getXValue(series, item - 1);
            final double y0 = dataset.getYValue(series, item - 1);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    final int numX = dataset.getItemCount(series);
                    final double minX = dataset.getXValue(series, 0);
                    final double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold();
                    }
                }
                if (drawLine) {
                    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    if (orientation == PlotOrientation.HORIZONTAL) {
                        state.workingLine.setLine(transY0, transX0, transY1, transX1);
                    } else if (orientation == PlotOrientation.VERTICAL) {
                        state.workingLine.setLine(transX0, transY0, transX1, transY1);
                    }

                    if (state.workingLine.intersects(dataArea)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        final Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y1 < 0.0);
    }

    final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }

}

From source file:de.tudarmstadt.ukp.clarin.webanno.monitoring.page.MonitoringPage.java

private ChartImageResource createProgressChart(Map<String, Integer> chartValues, int aMaxValue,
        boolean aIsPercentage) {
    // fill dataset
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String chartValue : chartValues.keySet()) {
        dataset.setValue(chartValues.get(chartValue), "Completion", chartValue);
    }//ww w .  j  ava  2s  .  c  o m
    // create chart
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false,
            false, false);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setInsets(new RectangleInsets(UnitType.ABSOLUTE, 0, 20, 0, 20));
    plot.getRangeAxis().setRange(0.0, aMaxValue);
    ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(new DecimalFormat("0"));
    // For documents lessan 10, avoid repeating the number of documents such
    // as 0 0 1 1 1
    // NumberTickUnit automatically determin the range
    if (!aIsPercentage && aMaxValue <= 10) {
        TickUnits standardUnits = new TickUnits();
        NumberAxis tick = new NumberAxis();
        tick.setTickUnit(new NumberTickUnit(1));
        standardUnits.add(tick.getTickUnit());
        plot.getRangeAxis().setStandardTickUnits(standardUnits);
    }
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(null);

    BarRenderer renderer = new BarRenderer();
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setShadowVisible(false);
    // renderer.setGradientPaintTransformer(new
    // StandardGradientPaintTransformer(
    // GradientPaintTransformType.HORIZONTAL));
    renderer.setSeriesPaint(0, Color.BLUE);
    chart.getCategoryPlot().setRenderer(renderer);

    return new ChartImageResource(chart, CHART_WIDTH, 30 + (chartValues.size() * 18));
}