Example usage for org.jfree.data.time TimeSeries addOrUpdate

List of usage examples for org.jfree.data.time TimeSeries addOrUpdate

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries addOrUpdate.

Prototype

public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, Number value) 

Source Link

Document

Adds or updates an item in the times series and sends a SeriesChangeEvent to all registered listeners.

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  . j  av  a2s .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 defaultChart(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {//from w w  w .j a  v  a  2s.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);

    if (typeIdName2 != null) {
        log.debug("type id name 2" + typeIdName2);

        ArrayList<EctMeasurementsDataBean> list2 = getList(demographicNo, typeIdName2);
        org.jfree.data.time.TimeSeriesCollection dataset2 = new org.jfree.data.time.TimeSeriesCollection();

        log.debug("list2 " + list2);

        EctMeasurementsDataBean sampleLine2 = list2.get(0);
        String typeLegendName = sampleLine2.getTypeDisplayName();
        String typeYAxisName2 = sampleLine2.getTypeDescription(); // this should be the type of measurement

        TimeSeries newSeries = new TimeSeries(typeLegendName, Day.class);
        for (EctMeasurementsDataBean mdb : list2) { //dataVector) {
            newSeries.addOrUpdate(new Day(mdb.getDateObservedAsDate()), Double.parseDouble(mdb.getDataField()));
        }
        dataset2.addSeries(newSeries);

        ////
        final XYPlot plot = chart.getXYPlot();
        final NumberAxis axis2 = new NumberAxis(typeYAxisName2);
        axis2.setAutoRangeIncludesZero(false);
        plot.setRangeAxis(1, axis2);
        plot.setDataset(1, dataset2);
        plot.mapDatasetToRangeAxis(1, 1);
        final XYItemRenderer renderer = plot.getRenderer();
        renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
        if (renderer instanceof StandardXYItemRenderer) {
            final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;

            rr.setBaseShapesFilled(true);
        }

        final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
        renderer2.setSeriesPaint(0, Color.black);
        renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
        plot.setRenderer(1, renderer2);

    }
    return chart;
}

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Another test of the clone() method.// www  . j  a  v  a 2 s  .com
 */
public void testClone2() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2007), 100.0);
    s1.add(new Year(2008), null);
    s1.add(new Year(2009), 200.0);
    TimeSeries s2 = null;
    try {
        s2 = (TimeSeries) s1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(s1.equals(s2));

    // check independence
    s2.addOrUpdate(new Year(2009), 300.0);
    assertFalse(s1.equals(s2));
    s1.addOrUpdate(new Year(2009), 300.0);
    assertTrue(s1.equals(s2));
}

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

JFreeChart labChartRef(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {/*from w  w  w.  ja v  a2s  .co m*/
    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) {/*w w w  .java2s  . c om*/
    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:org.jfree.data.time.TimeSeriesTest.java

@Test
public void testGetMinY2() {
    TimeSeries ts = new TimeSeries("Time Series");
    assertTrue(Double.isNaN(ts.getMinY()));

    ts.add(new Year(2014), 1.0);
    assertEquals(1.0, ts.getMinY(), EPSILON);

    ts.addOrUpdate(new Year(2014), null);
    assertTrue(Double.isNaN(ts.getMinY()));

    ts.addOrUpdate(new Year(2014), 1.0);
    assertEquals(1.0, ts.getMinY(), EPSILON);

    ts.clear();//from  w  ww  .j ava2  s  .com
    assertTrue(Double.isNaN(ts.getMinY()));
}

From source file:org.jfree.data.time.TimeSeriesTest.java

@Test
public void testGetMaxY2() {
    TimeSeries ts = new TimeSeries("Time Series");
    assertTrue(Double.isNaN(ts.getMaxY()));

    ts.add(new Year(2014), 1.0);
    assertEquals(1.0, ts.getMaxY(), EPSILON);

    ts.addOrUpdate(new Year(2014), null);
    assertTrue(Double.isNaN(ts.getMaxY()));

    ts.addOrUpdate(new Year(2014), 1.0);
    assertEquals(1.0, ts.getMaxY(), EPSILON);

    ts.clear();/*from   ww  w . j  a  v a 2  s  .com*/
    assertTrue(Double.isNaN(ts.getMaxY()));
}

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

JFreeChart rxAndLabChart(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {/*w  w  w  .  j ava2  s .  co 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);
    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 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);//  ww  w.ja  va2 s  . 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 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 a v  a  2s  .  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;
}