Example usage for org.jfree.chart.renderer.xy XYItemRenderer setBaseItemLabelsVisible

List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setBaseItemLabelsVisible

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYItemRenderer setBaseItemLabelsVisible.

Prototype

public void setBaseItemLabelsVisible(Boolean visible);

Source Link

Document

Sets the base setting for item label visibility.

Usage

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

JFreeChart labChart(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {//from   w  w  w  . java 2s. c  o  m
    org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection();
    ArrayList<EctMeasurementsDataBean> list = getList(demographicNo, typeIdName);
    String typeYAxisName = "";

    if (typeIdName.equals("BP")) {
        log.debug("Using BP LOGIC FOR type 1 ");
        EctMeasurementsDataBean sampleLine = list.get(0);
        typeYAxisName = sampleLine.getTypeDescription();
        TimeSeries systolic = new TimeSeries("Systolic", Day.class);
        TimeSeries diastolic = new TimeSeries("Diastolic", Day.class);
        for (EctMeasurementsDataBean mdb : list) { // dataVector) {
            String[] str = mdb.getDataField().split("/");

            systolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[0]));
            diastolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[1]));
        }
        dataset.addSeries(diastolic);
        dataset.addSeries(systolic);
    } else {
        log.debug("Not Using BP LOGIC FOR type 1 ");
        // get the name from the TimeSeries
        EctMeasurementsDataBean sampleLine = list.get(0);
        String typeLegendName = sampleLine.getTypeDisplayName();
        typeYAxisName = sampleLine.getTypeDescription(); // this should be the type of measurement
        TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class);
        for (EctMeasurementsDataBean mdb : list) { //dataVector) {
            newSeries.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(mdb.getDataField()));
        }
        dataset.addSeries(newSeries);
    }

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true,
            true, true);

    XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setAutoRange(true);

    log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin()
            + " eee " + plot.getDomainAxis().getLowerMargin());
    plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin() * 6);
    plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin() * 6);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 1.7);

    plot.getDomainAxis().setUpperMargin(0.9);
    plot.getDomainAxis().setLowerMargin(0.9);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4);

    ValueAxis va = plot.getRangeAxis();
    va.setAutoRange(true);
    XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance()
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}",
            new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00"));
    renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator);

    renderer.setBaseItemLabelsVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);

    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer;
        rend.setBaseShapesVisible(true);
        rend.setBaseShapesFilled(true);
    }

    plot.setRenderer(renderer);
    return chart;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

JFreeChart actualLabChartRef(String demographicNo, String labType, String identifier, String testName,
        String patientName, String chartTitle) {
    org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection();

    ArrayList<Map<String, Serializable>> list = CommonLabTestValues.findValuesForTest(labType, demographicNo,
            testName, identifier);//from w  ww . j ava  2s  .  com

    String typeYAxisName = "";
    ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>();

    String typeLegendName = "Lab Value";
    typeYAxisName = "type Y";

    boolean nameSet = false;
    TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class);
    for (Map mdb : list) {
        if (!nameSet) {
            typeYAxisName = (String) mdb.get("units");
            typeLegendName = (String) mdb.get("testName");
            newSeries.setKey(typeLegendName);
            nameSet = true;
        }
        newSeries.addOrUpdate(new Day((Date) mdb.get("collDateDate")),
                Double.parseDouble("" + mdb.get("result")));
        log.debug("RANGE " + mdb.get("range"));

        if (mdb.get("range") != null) {
            String range = (String) mdb.get("range");
            if (range.indexOf("-") != -1) {
                String[] sp = range.split("-");
                double open = Double.parseDouble(sp[0]);
                double high = Double.parseDouble(sp[1]);
                double low = Double.parseDouble(sp[0]);
                double close = Double.parseDouble(sp[1]);
                double volume = 1045;
                dataItems.add(new OHLCDataItem(new Day((Date) mdb.get("collDateDate")).getStart(), open, high,
                        low, close, volume));
            }
        }

    }
    dataset.addSeries(newSeries);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true,
            true, true);

    XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setAutoRange(true);

    log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin()
            + " eee " + plot.getDomainAxis().getLowerMargin());
    plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin() * 6);
    plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin() * 6);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 1.7);

    plot.getDomainAxis().setUpperMargin(0.9);
    plot.getDomainAxis().setLowerMargin(0.9);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4);

    ValueAxis va = plot.getRangeAxis();
    va.setAutoRange(true);
    XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance()
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}",
            new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00"));
    renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator);

    renderer.setBaseItemLabelsVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);

    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer;
        rend.setBaseShapesVisible(true);
        rend.setBaseShapesFilled(true);
    }

    plot.setRenderer(renderer);

    if (dataItems != null && dataItems.size() > 0) {
        OHLCDataItem[] ohlc = dataItems.toArray(new OHLCDataItem[dataItems.size()]);
        XYDataset referenceRangeDataset = new DefaultOHLCDataset("Normal Reference Range", ohlc);
        plot.setDataset(1, referenceRangeDataset);
        plot.mapDatasetToRangeAxis(1, 0);
        plot.setRenderer(1, new HighLowRenderer());

    }

    return chart;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

JFreeChart labChartRef(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {/* w  ww  . ja v  a 2  s  . c om*/
    org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection();
    ArrayList<EctMeasurementsDataBean> list = getList(demographicNo, typeIdName);
    String typeYAxisName = "";
    ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>();
    if (typeIdName.equals("BP")) {
        log.debug("Using BP LOGIC FOR type 1 ");
        EctMeasurementsDataBean sampleLine = list.get(0);
        typeYAxisName = sampleLine.getTypeDescription();
        TimeSeries systolic = new TimeSeries("Systolic", Day.class);
        TimeSeries diastolic = new TimeSeries("Diastolic", Day.class);
        for (EctMeasurementsDataBean mdb : list) { // dataVector) {
            String[] str = mdb.getDataField().split("/");

            systolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[0]));
            diastolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[1]));
        }
        dataset.addSeries(diastolic);
        dataset.addSeries(systolic);
    } else {
        log.debug("Not Using BP LOGIC FOR type 1 ");
        // get the name from the TimeSeries
        EctMeasurementsDataBean sampleLine = list.get(0);
        String typeLegendName = sampleLine.getTypeDisplayName();
        typeYAxisName = sampleLine.getTypeDescription(); // this should be the type of measurement
        TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class);
        for (EctMeasurementsDataBean mdb : list) { //dataVector) {
            newSeries.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(mdb.getDataField()));
            try {
                Hashtable h = getMeasurementsExt(mdb.getId());
                if (h != null && h.containsKey("minimum")) {
                    String min = (String) h.get("minimum");
                    String max = (String) h.get("maximum");
                    double open = Double.parseDouble(min.trim());
                    double high = Double.parseDouble(max.trim());
                    double low = Double.parseDouble(min.trim());
                    double close = Double.parseDouble(max.trim());
                    double volume = 1045;
                    dataItems
                            .add(new OHLCDataItem(mdb.getDateObservedAsDate(), open, high, low, close, volume));
                }
            } catch (Exception et) {
                MiscUtils.getLogger().error("Error", et);
            }
        }
        dataset.addSeries(newSeries);
    }

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true,
            true, true);

    XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setAutoRange(true);

    log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin()
            + " eee " + plot.getDomainAxis().getLowerMargin());
    plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin() * 6);
    plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin() * 6);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 1.7);

    plot.getDomainAxis().setUpperMargin(0.9);
    plot.getDomainAxis().setLowerMargin(0.9);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4);

    ValueAxis va = plot.getRangeAxis();
    va.setAutoRange(true);
    XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance()
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}",
            new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00"));
    renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator);

    renderer.setBaseItemLabelsVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);

    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer;
        rend.setBaseShapesVisible(true);
        rend.setBaseShapesFilled(true);
    }

    plot.setRenderer(renderer);

    if (dataItems != null && dataItems.size() > 0) {
        OHLCDataItem[] ohlc = dataItems.toArray(new OHLCDataItem[dataItems.size()]);
        XYDataset referenceRangeDataset = new DefaultOHLCDataset("Reference Range", ohlc);
        plot.setRenderer(1, setAxisAndDataSet(1, plot, plot.getRangeAxis(), referenceRangeDataset, Color.GREEN,
                new HighLowRenderer()));
    }

    /////

    return chart;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

JFreeChart referenceRangeChart(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {/*from   ww  w.  j av  a2s .c o  m*/
    org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection();

    ArrayList<EctMeasurementsDataBean> list = getList(demographicNo, typeIdName);
    ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>();
    String typeYAxisName = "";

    if (typeIdName.equals("BP")) {
        log.debug("Using BP LOGIC FOR type 1 ");
        EctMeasurementsDataBean sampleLine = list.get(0);
        typeYAxisName = sampleLine.getTypeDescription();
        TimeSeries systolic = new TimeSeries("Systolic", Day.class);
        TimeSeries diastolic = new TimeSeries("Diastolic", Day.class);
        for (EctMeasurementsDataBean mdb : list) { // dataVector) {
            String[] str = mdb.getDataField().split("/");

            systolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[0]));
            diastolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[1]));
        }
        dataset.addSeries(diastolic);
        dataset.addSeries(systolic);

    } else {
        log.debug("Not Using BP LOGIC FOR type 1 ");
        // get the name from the TimeSeries
        EctMeasurementsDataBean sampleLine = list.get(0);
        String typeLegendName = sampleLine.getTypeDisplayName();
        typeYAxisName = sampleLine.getTypeDescription(); // this should be the type of measurement
        TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class);
        for (EctMeasurementsDataBean mdb : list) { //dataVector) {
            newSeries.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(mdb.getDataField()));

            try {
                Hashtable h = getMeasurementsExt(mdb.getId());
                if (h != null && h.containsKey("minimum")) {
                    String min = (String) h.get("minimum");
                    String max = (String) h.get("maximum");
                    double open = Double.parseDouble(min.trim());
                    double high = Double.parseDouble(max.trim());
                    double low = Double.parseDouble(min.trim());
                    double close = Double.parseDouble(max.trim());
                    double volume = 1045;
                    dataItems
                            .add(new OHLCDataItem(mdb.getDateObservedAsDate(), open, high, low, close, volume));
                }
            } catch (Exception et) {
                MiscUtils.getLogger().error("Error", et);
            }

        }
        dataset.addSeries(newSeries);
    }

    OHLCDataItem[] ohlc = dataItems.toArray(new OHLCDataItem[dataItems.size()]);
    JFreeChart chart = ChartFactory.createHighLowChart("HighLowChartDemo2", "Time", "Value",
            new DefaultOHLCDataset("DREFERENCE RANGE", ohlc), true);
    XYPlot plot = (XYPlot) chart.getPlot();

    //        HighLowRenderer renderer = (HighLowRenderer) plot.getRenderer();
    //        renderer.
    //        renderer.setOpenTickPaint(Color.green);
    //        renderer.setCloseTickPaint(Color.black);

    plot.setDataset(1, dataset);

    plot.getDomainAxis().setAutoRange(true);

    log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin()
            + " eee " + plot.getDomainAxis().getLowerMargin());
    //plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin()*6);
    //plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin()*6);
    // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin()*1.7);

    plot.getDomainAxis().setUpperMargin(0.9);
    plot.getDomainAxis().setLowerMargin(0.9);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4);

    ValueAxis va = plot.getRangeAxis();
    va.setAutoRange(true);
    XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance()
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}",
            new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00"));
    renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator);

    renderer.setBaseItemLabelsVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);

    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer;
        rend.setBaseShapesVisible(true);
        rend.setBaseShapesFilled(true);
    }

    plot.setRenderer(renderer);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

JFreeChart rxAndLabChart(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {/*from   w  ww. ja  v  a  2  s. c  om*/
    org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection();

    ArrayList<EctMeasurementsDataBean> list = getList(demographicNo, typeIdName);

    String typeYAxisName = "";

    if (typeIdName.equals("BP")) {
        log.debug("Using BP LOGIC FOR type 1 ");
        EctMeasurementsDataBean sampleLine = list.get(0);
        typeYAxisName = sampleLine.getTypeDescription();
        TimeSeries systolic = new TimeSeries("Systolic", Day.class);
        TimeSeries diastolic = new TimeSeries("Diastolic", Day.class);
        for (EctMeasurementsDataBean mdb : list) { // dataVector) {
            String[] str = mdb.getDataField().split("/");

            systolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[0]));
            diastolic.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(str[1]));
        }
        dataset.addSeries(diastolic);
        dataset.addSeries(systolic);

    } else {
        log.debug("Not Using BP LOGIC FOR type 1 ");
        // get the name from the TimeSeries
        EctMeasurementsDataBean sampleLine = list.get(0);
        String typeLegendName = sampleLine.getTypeDisplayName();
        typeYAxisName = sampleLine.getTypeDescription(); // this should be the type of measurement
        TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class);
        for (EctMeasurementsDataBean mdb : list) { //dataVector) {
            newSeries.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(mdb.getDataField()));
        }
        dataset.addSeries(newSeries);
    }

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true,
            true, true);
    chart.setBackgroundPaint(Color.decode("#ccccff"));

    XYPlot plot = chart.getXYPlot();

    plot.getDomainAxis().setAutoRange(true);

    log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin()
            + " eee " + plot.getDomainAxis().getLowerMargin());
    //plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin()*6);
    //plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin()*6);
    // plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin()*1.7);

    plot.getDomainAxis().setUpperMargin(0.9);
    plot.getDomainAxis().setLowerMargin(0.9);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4);

    ValueAxis va = plot.getRangeAxis();
    va.setAutoRange(true);
    XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance()
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}",
            new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00"));
    renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator);

    renderer.setBaseItemLabelsVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);

    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer;
        rend.setBaseShapesVisible(true);
        rend.setBaseShapesFilled(true);
    }

    plot.setRenderer(renderer);

    ///////

    TaskSeriesCollection datasetDrug = new TaskSeriesCollection();
    TaskSeries s1 = new TaskSeries("WARFARIN");
    TaskSeries s2 = new TaskSeries("ALLOPUINOL");
    TaskSeries s3 = new TaskSeries("LIPITOR");

    s1.add(new Task("WARFARIN", UtilDateUtilities.StringToDate("2007-01-01"),
            UtilDateUtilities.StringToDate("2009-01-01")));
    s2.add(new Task("ALLOPUINOL", UtilDateUtilities.StringToDate("2008-01-01"), new Date()));
    s3.add(new Task("LIPITOR", UtilDateUtilities.StringToDate("2007-01-01"),
            UtilDateUtilities.StringToDate("2008-01-01")));

    datasetDrug.add(s1);
    datasetDrug.add(s2);
    datasetDrug.add(s3);

    XYTaskDataset dataset2 = new XYTaskDataset(datasetDrug);
    dataset2.setTransposed(true);
    dataset2.setSeriesWidth(0.6);

    DateAxis xAxis = new DateAxis("Date/Time");
    SymbolAxis yAxis = new SymbolAxis("Meds", new String[] { "WARFARIN", "ALLOPURINOL", "LIPITOR" });
    yAxis.setGridBandsVisible(false);
    XYBarRenderer xyrenderer = new XYBarRenderer();
    xyrenderer.setUseYInterval(true);
    xyrenderer.setBarPainter(new StandardXYBarPainter());

    xyrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator("HAPPY{1} \n {2}",
            new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(dataset2, xAxis, yAxis, xyrenderer);

    xyplot.getDomainAxis().setUpperMargin(0.9);
    xyplot.getDomainAxis().setLowerMargin(0.9);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(new DateAxis("Date/Time"));
    cplot.add(plot);
    cplot.add(xyplot);

    ///////

    chart = new JFreeChart("MED + LAB CHART", cplot);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

JFreeChart actualLabChartRefPlusMeds(String demographicNo, String labType, String identifier, String testName,
        String patientName, String chartTitle, String[] drugs) {
    org.jfree.data.time.TimeSeriesCollection dataset = new org.jfree.data.time.TimeSeriesCollection();

    ArrayList<Map<String, Serializable>> list = null;
    MiscUtils.getLogger().debug(//from  w w w.  j  ava 2  s.  com
            " lab type >" + labType + "< >" + labType.equals("loinc") + "<" + testName + " " + identifier);
    if (labType.equals("loinc")) {
        try {

            Connection conn = DbConnectionFilter.getThreadLocalDbConnection();
            list = CommonLabTestValues.findValuesByLoinc2(demographicNo, identifier, conn);
            MiscUtils.getLogger().debug("List ->" + list.size());
            conn.close();
        } catch (Exception ed) {
            MiscUtils.getLogger().error("Error", ed);
        }
    } else {
        list = CommonLabTestValues.findValuesForTest(labType, demographicNo, testName, identifier);
    }
    String typeYAxisName = "";
    ArrayList<OHLCDataItem> dataItems = new ArrayList<OHLCDataItem>();

    String typeLegendName = "Lab Value";
    typeYAxisName = "type Y";

    boolean nameSet = false;
    TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class);
    for (Map mdb : list) {
        if (!nameSet) {
            typeYAxisName = (String) mdb.get("units");
            typeLegendName = (String) mdb.get("testName");
            if (typeLegendName == null) {
                typeLegendName = testName;
            }

            newSeries.setKey(typeLegendName);
            nameSet = true;
        }
        newSeries.addOrUpdate(new Day((Date) mdb.get("collDateDate")),
                Double.parseDouble("" + mdb.get("result")));
        log.debug("RANGE " + mdb.get("range"));

        if (mdb.get("range") != null) {
            String range = (String) mdb.get("range");
            if (range.indexOf("-") != -1) {
                String[] sp = range.split("-");
                double open = Double.parseDouble(sp[0]);
                double high = Double.parseDouble(sp[1]);
                double low = Double.parseDouble(sp[0]);
                double close = Double.parseDouble(sp[1]);
                double volume = 1045;
                dataItems.add(new OHLCDataItem(new Day((Date) mdb.get("collDateDate")).getStart(), open, high,
                        low, close, volume));
            }
        }

    }
    dataset.addSeries(newSeries);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Days", typeYAxisName, dataset, true,
            true, true);

    XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setAutoRange(true);

    log.debug("LEN " + plot.getDomainAxis().getLowerBound() + " ddd " + plot.getDomainAxis().getUpperMargin()
            + " eee " + plot.getDomainAxis().getLowerMargin());
    plot.getDomainAxis().setUpperMargin(plot.getDomainAxis().getUpperMargin() * 6);
    plot.getDomainAxis().setLowerMargin(plot.getDomainAxis().getLowerMargin() * 6);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 1.7);

    plot.getDomainAxis().setUpperMargin(0.9);
    plot.getDomainAxis().setLowerMargin(0.9);
    plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() * 4);

    ValueAxis va = plot.getRangeAxis();
    va.setAutoRange(true);
    XYItemRenderer renderer = plot.getRenderer(); //DateFormat.getInstance()
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator("{1} \n {2}",
            new SimpleDateFormat("yyyy.MM.dd"), new DecimalFormat("0.00"));
    renderer.setSeriesItemLabelGenerator(0, generator);//setLabelGenerator(generator);

    renderer.setBaseItemLabelsVisible(true);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);

    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer rend = (XYLineAndShapeRenderer) renderer;
        rend.setBaseShapesVisible(true);
        rend.setBaseShapesFilled(true);
    }

    plot.setRenderer(renderer);

    if (dataItems != null && dataItems.size() > 0) {
        OHLCDataItem[] ohlc = dataItems.toArray(new OHLCDataItem[dataItems.size()]);
        XYDataset referenceRangeDataset = new DefaultOHLCDataset("Normal Reference Range", ohlc);
        plot.setDataset(1, referenceRangeDataset);
        plot.mapDatasetToRangeAxis(1, 0);
        plot.setRenderer(1, new HighLowRenderer());

    }

    XYTaskDataset drugDataset = getDrugDataSet(demographicNo, drugs);

    //DateAxis xAxis = new DateAxis("Date/Time");
    //DateAxis xAxis = plot.getRangeAxis();
    SymbolAxis yAxis = new SymbolAxis("Meds", getDrugSymbol(demographicNo, drugs));
    yAxis.setGridBandsVisible(false);
    XYBarRenderer xyrenderer = new XYBarRenderer();
    xyrenderer.setUseYInterval(true);
    xyrenderer.setBarPainter(new StandardXYBarPainter());

    //XYPlot xyplot = new XYPlot(drugDataset, xAxis, yAxis, xyrenderer);
    XYPlot xyplot = new XYPlot(drugDataset, plot.getDomainAxis(), yAxis, xyrenderer);

    xyplot.getDomainAxis().setUpperMargin(0.9);
    xyplot.getDomainAxis().setLowerMargin(0.9);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(new DateAxis("Date/Time"));
    cplot.add(plot);
    cplot.add(xyplot);

    ///////
    chart = new JFreeChart(chartTitle, cplot);
    chart.setBackgroundPaint(Color.white);

    return chart;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();
    final XYItemRenderer renderer = plot.getRenderer();

    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        renderer.setBaseToolTipGenerator(new FormulaXYZTooltipGenerator(getRuntime(), getTooltipFormula()));
    }//from w w  w  .  j  ava 2  s  .c  om
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        renderer.setURLGenerator(new FormulaXYZURLGenerator(getRuntime(), getUrlFormula()));
    }

    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null) {
        renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    plot.setOrientation(computePlotOrientation());

    // May be an axis that supports dates
    final ValueAxis domainAxis = plot.getDomainAxis();
    if (domainAxis instanceof NumberAxis) {
        final NumberAxis numberAxis = (NumberAxis) domainAxis;
        numberAxis.setAutoRangeIncludesZero(isDomainIncludesZero());
        numberAxis.setAutoRangeStickyZero(isDomainStickyZero());
        if (getDomainPeriodCount() > 0) {
            if (getDomainTickFormat() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(getDomainPeriodCount(), getDomainTickFormat()));
            } else if (getDomainTickFormatString() != null) {
                final FastDecimalFormat formatter = new FastDecimalFormat(getDomainTickFormatString(),
                        getResourceBundleFactory().getLocale());
                numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount()));
            }
        } else {
            if (getDomainTickFormat() != null) {
                numberAxis.setNumberFormatOverride(getDomainTickFormat());
            } else if (getDomainTickFormatString() != null) {
                final DecimalFormat formatter = new DecimalFormat(getDomainTickFormatString(),
                        new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setNumberFormatOverride(formatter);
            }
        }
    } else if (domainAxis instanceof DateAxis) {
        final DateAxis numberAxis = (DateAxis) domainAxis;

        if (getDomainPeriodCount() > 0 && getDomainTimePeriod() != null) {
            if (getDomainTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getDomainTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()),
                        (int) getDomainPeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()),
                        (int) getDomainPeriodCount()));
            }
        }
    }

    if (domainAxis != null) {
        domainAxis.setLabel(getDomainTitle());
        if (getDomainTitleFont() != null) {
            domainAxis.setLabelFont(getDomainTitleFont());
        }
        domainAxis.setVerticalTickLabels(isDomainVerticalTickLabels());
        if (getDomainTickFont() != null) {
            domainAxis.setTickLabelFont(getDomainTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
            if (getDomainMinimum() != 0) {
                domainAxis.setLowerBound(getDomainMinimum());
            }
            if (getDomainMaximum() != 1) {
                domainAxis.setUpperBound(getDomainMaximum());
            }
            if (getDomainMinimum() == 0 && getDomainMaximum() == 0) {
                domainAxis.setLowerBound(0);
                domainAxis.setUpperBound(1);
                domainAxis.setAutoRange(true);
            }
        } else {
            domainAxis.setLowerBound(getDomainMinimum());
            domainAxis.setUpperBound(getDomainMaximum());
            domainAxis.setAutoRange(isDomainAxisAutoRange());
        }
    }

    final ValueAxis rangeAxis = plot.getRangeAxis();
    if (rangeAxis instanceof NumberAxis) {
        final NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero());
        numberAxis.setAutoRangeStickyZero(isRangeStickyZero());

        if (getRangePeriodCount() > 0) {
            if (getRangeTickFormat() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat()));
            } else if (getRangeTickFormatString() != null) {
                final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(),
                        getResourceBundleFactory().getLocale());
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount()));
            }
        } else {
            if (getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(getRangeTickFormat());
            } else if (getRangeTickFormatString() != null) {
                final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(),
                        new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setNumberFormatOverride(formatter);
                standardTickUnitsApplyFormat(numberAxis, formatter);
            }
        }
    } else if (rangeAxis instanceof DateAxis) {
        final DateAxis numberAxis = (DateAxis) rangeAxis;

        if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) {
            if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()),
                        (int) getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(
                        new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount()));
            }
        } else {
            if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setDateFormatOverride(formatter);
            }
        }
    }

    if (rangeAxis != null) {
        rangeAxis.setLabel(getRangeTitle());
        if (getRangeTitleFont() != null) {
            rangeAxis.setLabelFont(getRangeTitleFont());
        }
        if (getRangeTickFont() != null) {
            rangeAxis.setTickLabelFont(getRangeTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
            if (getRangeMinimum() != 0) {
                rangeAxis.setLowerBound(getRangeMinimum());
            }
            if (getRangeMaximum() != 1) {
                rangeAxis.setUpperBound(getRangeMaximum());
            }
            if (getRangeMinimum() == 0 && getRangeMaximum() == 0) {
                rangeAxis.setLowerBound(0);
                rangeAxis.setUpperBound(1);
                rangeAxis.setAutoRange(true);
            }
        } else {
            rangeAxis.setLowerBound(getRangeMinimum());
            rangeAxis.setUpperBound(getRangeMaximum());
            rangeAxis.setAutoRange(isRangeAxisAutoRange());
        }
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }
}

From source file:beproject.MainGUI.java

void liveTweetAnalysis() {
    new DataGenerator(1000).start();
    rate = new TimeSeries("Total count", Second.class);
    rate.setMaximumItemAge(15);//from w ww .ja  v  a 2 s .c om
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(rate);
    DateAxis domain = new DateAxis("Time");
    NumberAxis range = new NumberAxis("Tweet Count");
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesStroke(1, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    range.setTickLabelsVisible(true);

    plot.setDomainGridlinesVisible(false);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelsVisible(true);

    JFreeChart liveTweetAnalysisChart = new JFreeChart("Tweets Per Second", new Font("Tahoma", Font.BOLD, 24),
            plot, true);
    liveTweetAnalysisChart.setBorderVisible(false);
    liveTweetAnalysisChart.setBorderPaint(null);

    ChartUtilities.applyCurrentTheme(liveTweetAnalysisChart);

    domain.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    range.setTickMarksVisible(false);
    range.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    domain.setTickMarksVisible(false);
    liveTweetAnalysisChart.setPadding(RectangleInsets.ZERO_INSETS);

    ChartPanel liveTweetAnalysisChartPanel = new ChartPanel(liveTweetAnalysisChart, true);
    liveTweetAnalysisChartPanel.setBorder(null);

    liveTweetsAnalysisPanel.add(liveTweetAnalysisChartPanel, BorderLayout.CENTER);
    liveTweetsAnalysisPanel.validate();
}

From source file:beproject.MainGUI.java

void createTimeLine() throws SQLException {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    getTimeLineData(dataset);//from  w ww .ja v  a 2 s .  c o m
    DateAxis domain = new DateAxis("Time");
    NumberAxis range = new NumberAxis("Tweet Count");
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesStroke(1, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    domain.setAutoRange(true);
    domain.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2, Regression.sdf));
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    range.setTickLabelsVisible(true);

    plot.setDomainGridlinesVisible(false);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelsVisible(true);

    JFreeChart liveTweetAnalysisChart = new JFreeChart("Rate of tweets per hour",
            new Font("Tahoma", Font.BOLD, 24), plot, true);
    liveTweetAnalysisChart.setBorderVisible(false);

    ChartUtilities.applyCurrentTheme(liveTweetAnalysisChart);

    domain.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    range.setTickMarksVisible(false);
    range.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    domain.setTickMarksVisible(false);
    liveTweetAnalysisChart.setPadding(RectangleInsets.ZERO_INSETS);

    ChartPanel liveTweetAnalysisChartPanel = new ChartPanel(liveTweetAnalysisChart, true);
    liveTweetAnalysisChartPanel.setBorder(null);

    if (timeLineChart == null) {
        timeLineChart = liveTweetAnalysisChartPanel;
    } else {
        timeLinePanel.remove(timeLineChart);
        timeLineChart = liveTweetAnalysisChartPanel;
    }
    timeLinePanel.add(timeLineChart);
    timeLinePanel.validate();
}

From source file:ro.nextreports.engine.chart.JFreeChartExporter.java

private JFreeChart createBubbleChart() throws QueryException {
    bubbleDataset = new DefaultXYZDataset();

    // x, y are inverted for jfree bubble chart!
    // that's why we use minX & maxX values to compute Tu (tickUnit)
    String chartTitle = replaceParameters(chart.getTitle().getTitle());
    chartTitle = StringUtil.getI18nString(chartTitle, I18nUtil.getLanguageByName(chart, language));
    String xLegend = StringUtil.getI18nString(replaceParameters(chart.getYLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));
    String yLegend = StringUtil.getI18nString(replaceParameters(chart.getXLegend().getTitle()),
            I18nUtil.getLanguageByName(chart, language));
    JFreeChart jfreechart = ChartFactory.createBubbleChart(chartTitle, xLegend, // x-axis Label
            yLegend, // y-axis Label
            bubbleDataset, PlotOrientation.HORIZONTAL, true, true, false);

    // hide border
    jfreechart.setBorderVisible(false);/*from  w  w  w .  ja v a2s.  co  m*/

    // title
    setTitle(jfreechart);

    boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart();

    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setForegroundAlpha(transparency);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();

    DecimalFormat decimalformat;
    DecimalFormat percentageFormat;
    if (chart.getYTooltipPattern() == null) {
        decimalformat = new DecimalFormat("#");
        percentageFormat = new DecimalFormat("0.00%");
    } else {
        decimalformat = new DecimalFormat(chart.getYTooltipPattern());
        percentageFormat = decimalformat;
    }

    if (showValues) {
        // increase a little bit the range axis to view all item label values over bars
        xyplot.getRangeAxis().setUpperMargin(0.2);
    }

    // grid axis visibility & colors 
    if ((chart.getXShowGrid() != null) && !chart.getXShowGrid()) {
        xyplot.setDomainGridlinesVisible(false);
    } else {
        if (chart.getXGridColor() != null) {
            xyplot.setDomainGridlinePaint(chart.getXGridColor());
        } else {
            xyplot.setDomainGridlinePaint(Color.BLACK);
        }
    }
    if ((chart.getYShowGrid() != null) && !chart.getYShowGrid()) {
        xyplot.setRangeGridlinesVisible(false);
    } else {
        if (chart.getYGridColor() != null) {
            xyplot.setRangeGridlinePaint(chart.getYGridColor());
        } else {
            xyplot.setRangeGridlinePaint(Color.BLACK);
        }
    }

    // chart background
    xyplot.setBackgroundPaint(chart.getBackground());

    // labels color
    xyplot.getDomainAxis().setTickLabelPaint(chart.getXColor());
    xyplot.getRangeAxis().setTickLabelPaint(chart.getYColor());

    // legend color
    xyplot.getDomainAxis().setLabelPaint(chart.getXLegend().getColor());
    xyplot.getRangeAxis().setLabelPaint(chart.getYLegend().getColor());

    // legend font
    xyplot.getDomainAxis().setLabelFont(chart.getXLegend().getFont());
    xyplot.getRangeAxis().setLabelFont(chart.getYLegend().getFont());

    // axis color
    xyplot.getDomainAxis().setAxisLinePaint(chart.getxAxisColor());
    xyplot.getRangeAxis().setAxisLinePaint(chart.getyAxisColor());

    // hide labels
    if ((chart.getXShowLabel() != null) && !chart.getXShowLabel()) {
        xyplot.getDomainAxis().setTickLabelsVisible(false);
        xyplot.getDomainAxis().setTickMarksVisible(false);
    }
    if ((chart.getYShowLabel() != null) && !chart.getYShowLabel()) {
        xyplot.getRangeAxis().setTickLabelsVisible(false);
        xyplot.getRangeAxis().setTickMarksVisible(false);
    }

    // label orientation
    ValueAxis domainAxis = xyplot.getDomainAxis();
    if (chart.getXorientation() == Chart.VERTICAL) {
        domainAxis.setLabelAngle(Math.PI / 2);
    } else if (chart.getXorientation() == Chart.DIAGONAL) {
        domainAxis.setLabelAngle(Math.PI / 4);
    } else if (chart.getXorientation() == Chart.HALF_DIAGONAL) {
        domainAxis.setLabelAngle(Math.PI / 8);
    }

    // labels fonts
    xyplot.getDomainAxis().setTickLabelFont(chart.getXLabelFont());
    xyplot.getRangeAxis().setTickLabelFont(chart.getYLabelFont());

    createChart(xyplot.getRangeAxis(), new Object[4]);

    double minX = Double.MAX_VALUE;
    double maxX = Double.MIN_VALUE;
    double minY = Double.MAX_VALUE;
    double maxY = Double.MIN_VALUE;
    double maxZ = Double.MIN_VALUE;
    for (String serie : bubbleData.keySet()) {
        XYZList xyzList = bubbleData.get(serie);
        List<Number> yList = xyzList.getyList();
        for (Number n : yList) {
            minY = Math.min(minY, n.doubleValue());
            maxY = Math.max(maxY, n.doubleValue());
        }
        List<Number> xList = xyzList.getxList();
        for (Number n : xList) {
            minX = Math.min(minX, n.doubleValue());
            maxX = Math.max(maxX, n.doubleValue());
        }
        List<Number> zList = xyzList.getzList();
        for (Number n : zList) {
            maxZ = Math.max(maxZ, n.doubleValue());
        }
    }

    double tu = Math.floor((maxX - minX) / 5 + 0.5d);
    NumberTickUnit rUnit = new NumberTickUnit(tu);
    ((NumberAxis) xyplot.getRangeAxis()).setTickUnit(rUnit);

    // make the bubble with text fit on X axis (which is shown vertically!)
    xyplot.getDomainAxis().setUpperMargin(0.2);
    xyplot.getDomainAxis().setLowerMargin(0.2);

    for (String serie : bubbleData.keySet()) {
        XYZList xyzList = bubbleData.get(serie);
        double[][] data = { getDoubleArray(xyzList.getyList()), getDoubleArray(xyzList.getxList()),
                getZDoubleArray(xyzList.getzList(), tu, maxZ) };
        bubbleDataset.addSeries(serie, data);
    }

    int series = bubbleData.keySet().size();
    for (int i = 0; i < series; i++) {
        xyitemrenderer.setSeriesPaint(i, chart.getForegrounds().get(i));
        if (showValues) {
            xyitemrenderer.setSeriesItemLabelsVisible(i, true);
            xyitemrenderer.setSeriesItemLabelGenerator(i,
                    new StandardXYItemLabelGenerator("{2}", decimalformat, percentageFormat));
        }
    }

    // show labels on bubbles
    xyitemrenderer.setBaseItemLabelsVisible(true);
    xyitemrenderer.setBaseItemLabelGenerator(new LegendXYItemLabelGenerator());
    return jfreechart;
}