Example usage for org.jfree.data Range Range

List of usage examples for org.jfree.data Range Range

Introduction

In this page you can find the example usage for org.jfree.data Range Range.

Prototype

public Range(double lower, double upper) 

Source Link

Document

Creates a new range.

Usage

From source file:asl.plotmaker.PlotMaker2.java

public void writePlot(String fileName) {
    // System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle,
    // fileName);

    File outputFile = new File(fileName);

    // Check that we will be able to output the file without problems and if
    // not --> return
    if (!checkFileOut(outputFile)) {
        // System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it "
        // + " --> skip plot\n", fileName );
        logger.warn("== Request to output plot=[{}] but we are unable to create it " + " --> skip plot\n",
                fileName);//w ww. ja v a  2  s  . c o m
        return;
    }

    NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x =
    // domain

    if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("coher")
            || fileName.contains("stn")) { // NLNM or StationDeviation
        horizontalAxis = new LogarithmicAxis("Period (sec)");
        horizontalAxis.setRange(new Range(1, 11000));
        horizontalAxis.setTickUnit(new NumberTickUnit(5.0));
    } else { // EventCompareSynthetics/StrongMotion
        horizontalAxis = new NumberAxis("Time (s)");
        double x[] = panels.get(0).getTraces().get(0).getxData();
        horizontalAxis.setRange(new Range(x[0], x[x.length - 1]));
    }

    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.setGap(15.);

    // Loop over (3) panels for this plot:

    for (Panel panel : panels) {

        NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y =
        // range

        if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM
            // or
            // StationDeviation
            verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB");
            verticalAxis.setRange(new Range(-190, -80));
            verticalAxis.setTickUnit(new NumberTickUnit(5.0));
        } else if (fileName.contains("coher")) { // Coherence
            verticalAxis = new NumberAxis("Coherence, Gamma");
            verticalAxis.setRange(new Range(0, 1.2));
            verticalAxis.setTickUnit(new NumberTickUnit(0.1));
        } else { // EventCompareSynthetics/StrongMotion
            verticalAxis = new NumberAxis("Displacement (m)");
        }

        Font fontPlain = new Font("Verdana", Font.PLAIN, 14);
        Font fontBold = new Font("Verdana", Font.BOLD, 18);
        verticalAxis.setLabelFont(fontBold);
        verticalAxis.setTickLabelFont(fontPlain);
        horizontalAxis.setLabelFont(fontBold);
        horizontalAxis.setTickLabelFont(fontPlain);

        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYDotRenderer renderer = new XYDotRenderer();
        XYPlot xyplot = new XYPlot(seriesCollection, horizontalAxis, verticalAxis, renderer);
        xyplot.setDomainGridlinesVisible(true);
        xyplot.setRangeGridlinesVisible(true);
        xyplot.setRangeGridlinePaint(Color.black);
        xyplot.setDomainGridlinePaint(Color.black);

        // Plot each trace on this panel:
        int iTrace = 0;
        for (Trace trace : panel.getTraces()) {

            XYSeries series = new XYSeries(trace.getName());

            double xdata[] = trace.getxData();
            double ydata[] = trace.getyData();
            for (int k = 0; k < xdata.length; k++) {
                series.add(xdata[k], ydata[k]);
            }

            renderer.setSeriesPaint(iTrace, trace.getColor());
            renderer.setSeriesStroke(iTrace, trace.getStroke());

            seriesCollection.addSeries(series);

            iTrace++;
        }

        // Add Annotations for each trace - This is done in a separate loop
        // so that
        // the upper/lower limits for this panel will be known
        double xmin = horizontalAxis.getRange().getLowerBound();
        double xmax = horizontalAxis.getRange().getUpperBound();
        double ymin = verticalAxis.getRange().getLowerBound();
        double ymax = verticalAxis.getRange().getUpperBound();
        double delX = Math.abs(xmax - xmin);
        double delY = Math.abs(ymax - ymin);

        // Annotation (x,y) in normalized units - where upper-right corner =
        // (1,1)
        double xAnn = 0.97; // Right center coords of the trace name (e.g.,
        // "00-LHZ")
        double yAnn = 0.95;

        double yOff = 0.05; // Vertical distance between different trace
        // legends

        iTrace = 0;
        for (Trace trace : panel.getTraces()) {
            if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM")
                    && !trace.getName().contains("ALNM")) {
                // x1 > x2 > x3, e.g.:
                // o-------o 00-LHZ
                // x3 x2 x1

                double scale = .01; // Controls distance between trace label
                // and line segment
                double xL = .04; // Length of trace line segment in legend

                double xAnn2 = xAnn - scale * trace.getName().length();
                double xAnn3 = xAnn - scale * trace.getName().length() - xL;

                double x1 = xAnn * delX + xmin; // Right hand x-coord of
                // text in range units
                double x2 = xAnn2 * delX + xmin; // x-coord of line segment
                // end in range units
                double x3 = xAnn3 * delX + xmin; // x-coord of line segment
                // end in range units

                double y = (yAnn - (iTrace * yOff)) * delY + ymin;

                if (horizontalAxis instanceof LogarithmicAxis) {
                    double logMin = Math.log10(xmin);
                    double logMax = Math.log10(xmax);
                    delX = logMax - logMin;
                    x1 = Math.pow(10, xAnn * delX + logMin);
                    x2 = Math.pow(10, xAnn2 * delX + logMin);
                    x3 = Math.pow(10, xAnn3 * delX + logMin);
                }
                xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor()));
                XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y);
                xyText.setFont(new Font("Verdana", Font.BOLD, 18));
                xyText.setTextAnchor(TextAnchor.CENTER_RIGHT);
                xyplot.addAnnotation(xyText);
            }
            iTrace++;
        }

        combinedPlot.add(xyplot, 1);

    } // panel

    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18)));
    chart.removeLegend();

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400);
    } catch (IOException e) {
        // System.err.println("Problem occurred creating chart.");
        logger.error("IOException:", e);
    }

}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Creates a new <code>LogAxis</code> with the given label.
 * /*www  .  j  a  v a 2  s .com*/
 * @param label  the axis label (<code>null</code> permitted).
 */
public LogAxis(String label) {
    super(label, NumberAxis.createIntegerTickUnits());
    setDefaultAutoRange(new Range(0.01, 1.0));
    this.tickUnit = new NumberTickUnit(1.0);
    this.minorTickCount = 10;
    this.setTickMarksVisible(false);
}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

@SuppressWarnings("deprecation")
public JPanel calcEthTol() throws Exception {
    super.setTitle("P vs x1");
    double T = 60;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("ethanol");
    comps[1] = db.getComp("toluene");

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setComponents(comps);/*from  w w w .ja  va 2s  .co m*/

    cosmosac.setTemperature(T + 273.15);

    double[] x1 = new double[n];
    double[] x2 = new double[n];
    double[] gamma1 = new double[n];
    double[] gamma2 = new double[n];
    double[] z = new double[2];
    double[] lnGamma = new double[2];
    z[0] = 0.00;
    int j = 0;
    while (z[0] < 1.0001) {
        z[1] = 1 - z[0];
        x1[j] = z[0];
        x2[j] = z[1];
        cosmosac.setComposition(z);
        cosmosac.activityCoefficient(lnGamma);
        gamma1[j] = Math.exp(lnGamma[0]);
        gamma2[j] = Math.exp(lnGamma[1]);
        z[0] += 0.05;
        j++;
    }

    double[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.8958;
    parAntoine[0][1] = 3795.17;
    parAntoine[0][2] = 230.918;
    parAntoine[1][0] = 13.9320;
    parAntoine[1][1] = 3056.96;
    parAntoine[1][2] = 217.625;

    double[] Psat = pSat(parAntoine, T);
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot1;
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries liq = new XYSeries("liquid");
    XYSeries vap = new XYSeries("vapor");
    XYSeries raoult = new XYSeries("Raoult's Law");
    for (int i = 0; i < n; i++) {
        liq.add(x1[i], P[i]);
        vap.add(y1[i], P[i]);
    }
    raoult.add(0, Psat[1]);
    raoult.add(1, Psat[0]);
    dataset.addSeries(liq);
    dataset.addSeries(vap);
    dataset.addSeries(raoult);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot1 = (XYPlot) chart.getPlot();
    plot1.getDomainAxis().setRange(new Range(0.0, 1.0));
    plot1.getRangeAxis().setRange(new Range(15.0, 50.0));

    plot1.setDataset(dataset);

    XYSplineRenderer r = new XYSplineRenderer();
    BasicStroke stroke = new BasicStroke(2f);
    r.setStroke(stroke);
    plot1.setRenderer(r);
    r.setBaseShapesVisible(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp = new JPanel(new BorderLayout());
    jp.add(chartPanel);

    add(jp, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp;
}

From source file:com.epiq.bitshark.ui.IVQPanel.java

public IVQPanel() {

    initComponents();//from w w w .ja  v a  2 s  . c o  m

    initGraph();

    JPanel holderPanel = new JPanel() {

        @Override
        public void paint(Graphics g) {

            Range newDomain = null; // x
            Range newRange = null; // y

            Range currentDomainRange = plot.getDomainAxis().getRange();
            Range currentRangeRange = plot.getRangeAxis().getRange();

            if (plot.getDomainAxis().isAutoRange()) {
                plot.getDomainAxis().setAutoRange(false);
            }

            if (plot.getRangeAxis().isAutoRange()) {
                plot.getRangeAxis().setAutoRange(false);
            }

            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            double width = dataArea.getWidth();
            double height = dataArea.getHeight();

            double domainScale = 1;
            double rangeScale = 1;

            // scale the domain values up to match the pixels
            if (width > height) {
                domainScale = width / height;
                double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound();
                newDomain = new Range(-(extent * domainScale) / 2, (extent * domainScale) / 2);

            } else if (height > width) {
                rangeScale = height / width;
                double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound();
                newRange = new Range(-(extent * rangeScale) / 2, (extent * rangeScale) / 2);
            }

            if (newDomain == null) {
                double extent = currentDomainRange.getUpperBound() - currentDomainRange.getLowerBound();
                newDomain = new Range(-(extent) / 2, (extent) / 2);
            }

            if (newRange == null) {
                double extent = currentRangeRange.getUpperBound() - currentRangeRange.getLowerBound();
                newRange = new Range(-(extent) / 2, (extent) / 2);
            }

            if (newDomain != null) {
                plot.getDomainAxis().setRange(newDomain, true, false);
            }

            if (newRange != null) {
                plot.getRangeAxis().setRange(newRange, true, false);
            }

            Graphics2D g2 = (Graphics2D) g.create();
            super.paint(g2);

            g2.dispose();
        }
    };

    holderPanel.setLayout(new BorderLayout());
    holderPanel.add(chartPanel, BorderLayout.CENTER);
    mainPanel.add(holderPanel, BorderLayout.CENTER);

    headerPanel.setBackgroundPainter(Common.getHeaderPainter());

    chartLabel.setUI(new BasicLabelUI());
}

From source file:com.liferay.server.admin.web.internal.portlet.action.ViewChartMVCResourceCommand.java

protected MeterPlot getMeterPlot(ThemeDisplay themeDisplay, ValueDataset valueDataset) {

    MeterPlot meterPlot = new MeterPlot(valueDataset);

    meterPlot.addInterval(new MeterInterval(themeDisplay.translate("normal"), new Range(0.0D, 75D),
            Color.lightGray, new BasicStroke(2.0F), new Color(0, 255, 0, 64)));

    meterPlot.addInterval(new MeterInterval(themeDisplay.translate("warning"), new Range(75D, 90D),
            Color.lightGray, new BasicStroke(2.0F), new Color(255, 255, 0, 64)));

    meterPlot.addInterval(new MeterInterval(themeDisplay.translate("critical"), new Range(90D, 100D),
            Color.lightGray, new BasicStroke(2.0F), new Color(255, 0, 0, 128)));

    meterPlot.setDialBackgroundPaint(Color.white);
    meterPlot.setDialShape(DialShape.PIE);
    meterPlot.setDialOutlinePaint(Color.gray);
    meterPlot.setTickLabelFont(new Font(null, Font.PLAIN, 10));
    meterPlot.setTickLabelPaint(Color.darkGray);
    meterPlot.setTickLabelsVisible(true);
    meterPlot.setTickPaint(Color.lightGray);
    meterPlot.setTickSize(5D);/*from ww  w  .ja  v a  2  s  .  c  o m*/
    meterPlot.setMeterAngle(180);
    meterPlot.setNeedlePaint(Color.darkGray);
    meterPlot.setRange(new Range(0.0D, 100D));
    meterPlot.setValueFont(new Font(null, Font.PLAIN, 10));
    meterPlot.setValuePaint(Color.black);
    meterPlot.setUnits("%");

    return meterPlot;
}

From source file:org.jfree.data.RangeTest.java

/**
 * Tests the constrain() method for various values.
 *///from  ww w.  ja  v a2 s .com
@Test
public void testConstrain() {
    Range r1 = new Range(0.0, 1.0);

    double d = r1.constrain(0.5);
    assertEquals(0.5, d, 0.0000001);

    d = r1.constrain(0.0);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(1.0);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(-1.0);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(2.0);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(Double.POSITIVE_INFINITY);
    assertEquals(1.0, d, 0.0000001);

    d = r1.constrain(Double.NEGATIVE_INFINITY);
    assertEquals(0.0, d, 0.0000001);

    d = r1.constrain(Double.NaN);
    assertTrue(Double.isNaN(d));
}

From source file:com.hmsinc.epicenter.webapp.chart.ChartService.java

/**
 * @param adapter//from  w  w  w.  j a  v a 2s.  c om
 * @param annotations
 * @return
 */
private static JFreeChart createChart(final AbstractChart adapter, final List<XYAnnotation> annotations) {

    final JFreeChart chart;
    if (adapter.getItems() instanceof XYDataset) {

        chart = ChartFactory.createTimeSeriesChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (XYDataset) adapter.getItems(), true, false, false);
        final ValueAxis domainAxis = new DateAxis();
        domainAxis.setLabelFont(LABEL_FONT);
        domainAxis.setTickLabelFont(LABEL_FONT);
        domainAxis.setLowerMargin(0.0);
        domainAxis.setUpperMargin(0.0);

        chart.getXYPlot().setDomainAxis(domainAxis);
        chart.getXYPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);
        chart.getXYPlot().getRangeAxis().setStandardTickUnits(adapter.getRangeTickUnits());

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getXYPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.2));
            chart.getXYPlot().getRangeAxis().setRange(range);
        }

        for (Marker marker : adapter.getMarkers()) {
            chart.getXYPlot().addDomainMarker(marker);
        }

        if (annotations != null) {
            for (XYAnnotation annotation : annotations) {
                if (annotation instanceof XYPointerAnnotation) {
                    ((XYPointerAnnotation) annotation).setFont(ANNOTATION_FONT);
                }
                chart.getXYPlot().addAnnotation(annotation);
            }
        }

        // Add any bands to the chart
        if (adapter instanceof TimeSeriesChart) {
            final TimeSeriesChart tsc = (TimeSeriesChart) adapter;
            for (int i = 0; i < tsc.getBands().size(); i++) {

                final Color c = tsc.getBandColors().get(i);
                final Color fill = tsc.getBandFillColors().get(i);
                final XYDifferenceRenderer renderer = new XYDifferenceRenderer(fill, fill, false);
                renderer.setSeriesPaint(0, c);
                renderer.setSeriesPaint(1, c);
                renderer.setSeriesStroke(0, LineStyle.THICK.getStroke());
                renderer.setSeriesStroke(1, LineStyle.THICK.getStroke());

                chart.getXYPlot().setDataset(i + 1, tsc.getBands().get(i));
                chart.getXYPlot().setRenderer(i + 1, renderer);
            }
        }

    } else if (adapter.getItems() instanceof CategoryDataset) {

        chart = ChartFactory.createBarChart(adapter.getTitle(), adapter.getXLabel(), adapter.getYLabel(),
                (CategoryDataset) adapter.getItems(), PlotOrientation.VERTICAL, true, false, false);
        chart.getCategoryPlot().getDomainAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getDomainAxis().setTickLabelFont(LABEL_FONT);
        chart.getCategoryPlot().getRangeAxis().setTickLabelFont(LABEL_FONT);

        if (adapter.isAlwaysScaleFromZero()) {
            final double upperBound = chart.getCategoryPlot().getRangeAxis().getRange().getUpperBound();
            final Range range = new Range(0, upperBound + (upperBound * 0.1));
            chart.getCategoryPlot().getRangeAxis().setRange(range);
        }

    } else {
        throw new UnsupportedOperationException("Unsupported chart type: " + adapter.getItems().getClass());
    }

    chart.getPlot().setNoDataMessage(NO_DATA_MESSAGE);

    return chart;
}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java

public JPanel calcAcetoneWater() throws Exception {
    super.setTitle("P vs x1");
    double T = 298.15;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();
    COSMOSACCompound c1 = db.getComp("ethyl-acetate");
    COSMOSACCompound c2 = db.getComp("water");

    double[] cavityVolume = new double[2];
    cavityVolume[0] = c1.Vcosmo;//  w  ww  .j  av a  2s.co  m
    cavityVolume[1] = c2.Vcosmo;

    double[][] sigma = new double[2][];

    sigma[0] = c1.sigma;
    sigma[1] = c2.sigma;

    SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS,
            c1.name.toLowerCase() + ".log");
    SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS,
            c2.name.toLowerCase() + ".log");
    sigma[0] = c1Sigma.getSigmaProfile();
    sigma[1] = c2Sigma.getSigmaProfile();

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setParameters(cavityVolume, c1.charge, sigma);
    cosmosac.setIgnoreSG(true);
    cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2);

    cosmosac.setTemperature(T);

    double[] x1 = new double[n];
    double[] x2 = new double[n];
    double[] gamma1 = new double[n];
    double[] gamma2 = new double[n];
    double[] z = new double[2];
    double[] lnGamma = new double[2];
    z[0] = 0.00;
    int j = 0;
    while (z[0] < 1.0001) {
        z[1] = 1 - z[0];
        x1[j] = z[0];
        x2[j] = z[1];
        cosmosac.setComposition(z);
        cosmosac.activityCoefficient(lnGamma);
        gamma1[j] = Math.exp(lnGamma[0]);
        gamma2[j] = Math.exp(lnGamma[1]);
        z[0] += 0.05;
        j++;
    }

    double[] Psat = new double[2];
    Psat[0] = 13000;
    Psat[1] = 3000;
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot1;
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries liq = new XYSeries("liquid");
    XYSeries vap = new XYSeries("vapor");
    XYSeries raoult = new XYSeries("Raoult's Law");
    for (int i = 0; i < n; i++) {
        liq.add(x1[i], P[i]);
        vap.add(y1[i], P[i]);
    }
    raoult.add(0, Psat[1]);
    raoult.add(1, Psat[0]);
    dataset.addSeries(liq);
    dataset.addSeries(vap);
    dataset.addSeries(raoult);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot1 = (XYPlot) chart.getPlot();
    plot1.getDomainAxis().setRange(new Range(0.0, 1.0));

    plot1.setDataset(dataset);

    //      XYSplineRenderer r = new XYSplineRenderer();
    //      BasicStroke stroke = new BasicStroke(2f);
    //      r.setStroke(stroke);
    //      plot1.setRenderer(r);
    //      r.setBaseShapesVisible(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp1 = new JPanel(new BorderLayout());
    jp1.add(chartPanel);

    add(jp1, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp1;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java

/**
 * Returns the range of values the renderer requires to display all the items from the specified dataset.
 *
 * @param dataset the dataset (<code>null</code> not permitted).
 * @return The range (or <code>null</code> if the dataset is empty).
 *///from   ww w . java 2 s.  c  o  m
public Range findRangeBounds(final CategoryDataset dataset) {
    if (dataset == null) {
        return null;
    }
    if (this.renderAsPercentages) {
        return new Range(0.0, 1.0);
    } else {
        return DatasetUtilities.findStackedRangeBounds(dataset);
    }
}

From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java

protected static XYPlot createXYPlot(XYDataset dataset, Color[] colors) {
    // break up into two datasets, one for bars one for lines
    //LinkedList lines =new LinkedList();
    //LinkedList bars = new LinkedList();
    XYDataset seriesLines = new XYSeriesCollection();
    XYDataset seriesBars = new XYSeriesCollection();
    ((XYSeriesCollection) seriesBars).setIntervalWidth(0.0);

    if (dataset instanceof XYSeriesCollection) {
        while (0 < dataset.getSeriesCount()) {
            XYSeries s = ((XYSeriesCollection) dataset).getSeries(0);
            ((XYSeriesCollection) dataset).removeSeries(0);
            Comparable key = s.getKey();
            boolean lines = false;
            if (key instanceof String)
                lines = ((String) key).startsWith("-");
            if (lines)
                ((XYSeriesCollection) seriesLines).addSeries(s);
            else/*from  www.j av  a2 s . c  o  m*/
                ((XYSeriesCollection) seriesBars).addSeries(s);
        }
    } else {
        seriesBars = dataset;
    }

    NumberAxis axisDomain = new NumberAxis();
    axisDomain.setAutoRange(true);
    axisDomain.setAutoRangeIncludesZero(false);
    //      axisDomain.setRange(400.0, 1600.0);
    // NOTE: zooming in too far kills the chart, prevent this
    axisDomain.addChangeListener(new AxisChangeListener() {
        public void axisChanged(AxisChangeEvent event) {
            NumberAxis axis = (NumberAxis) event.getSource();
            Range range = axis.getRange();
            if (range.getLength() < 2.0) {
                //_log.info("AxisChangeListener " + range.getLength() + " " + range.toString());
                double middle = range.getLowerBound() + range.getLength() / 2.0;
                axis.setRange(new Range(middle - 1.1, middle + 1.1));
            }
        }
    });

    NumberAxis axisRange = new NumberAxis();
    axisRange.setAutoRange(true);
    axisRange.setAutoRangeIncludesZero(true);

    XYToolTipGenerator toolTipGenerator = new XYToolTipGenerator() {
        public String generateToolTip(XYDataset xyDataset, int s, int i) {
            double X = Math.round(xyDataset.getXValue(s, i) * 1000.0) / 1000.0;
            double Y = Math.round(xyDataset.getYValue(s, i) * 1000.0) / 1000.0;
            return "(" + X + ", " + Y + ")";
        }
    };

    XYBarRenderer barRenderer = new XYBarRenderer();
    //dhmay adding 2009/09/14.  As of jfree 1.0.13, shadows on by default        
    barRenderer.setShadowVisible(false);

    //dhmay adding for jfreechart 1.0.6 upgrade.  If this isn't here, we get a
    //nullPointerException in XYBarRenderer.drawItemLabel
    barRenderer.setBaseItemLabelGenerator(new NullLabelGenerator());

    barRenderer.setSeriesItemLabelsVisible(0, true);
    barRenderer.setBaseToolTipGenerator(toolTipGenerator);

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setBaseToolTipGenerator(toolTipGenerator);

    XYPlot xy = new XYPlot(null, axisDomain, axisRange, null);

    int ds = 0;
    if (seriesLines.getSeriesCount() > 0) {
        xy.setDataset(ds, seriesLines);
        xy.setRenderer(ds, lineRenderer);
        xy.mapDatasetToRangeAxis(ds, 0);
        ds++;
        for (int i = 0; i < seriesLines.getSeriesCount(); i++) {
            Comparable key = ((XYSeriesCollection) seriesLines).getSeriesKey(i);
            boolean lines = false;
            if (key instanceof String)
                lines = ((String) key).startsWith("-");
            lineRenderer.setSeriesLinesVisible(i, lines);
            lineRenderer.setSeriesShapesVisible(i, !lines);
        }
    }
    if (seriesBars.getSeriesCount() > 0) {
        xy.setDataset(ds, seriesBars);
        xy.setRenderer(ds, barRenderer);
        xy.mapDatasetToRangeAxis(ds, 0);
        ds++;
    }

    setColors(xy, colors);

    return xy;
}