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

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

Introduction

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

Prototype

public void setSeriesItemLabelGenerator(int series, XYItemLabelGenerator generator);

Source Link

Document

Sets the item label generator for a series and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:org.gwaspi.reports.PlinkReportLoader.java

private static void appendToCombinedRangePlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection seriesCol) {/*from  w  w w  .j a  va  2  s .  c  o m*/
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.blue);

    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", seriesCol,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    subplot.setDomainGridlineStroke(new BasicStroke(0.0f));
    subplot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    subplot.setDomainGridlinePaint(Color.blue);
    subplot.setRangeGridlineStroke(new BasicStroke(0.0f));
    subplot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    subplot.setRangeGridlinePaint(Color.blue);

    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setAxisLineVisible(true);
    chrAxis.setTickLabelsVisible(true);
    chrAxis.setTickMarksVisible(true);
    chrAxis.setTickUnit(new NumberTickUnit(10000));
    chrAxis.setAutoRangeIncludesZero(false);

    NumberAxis log10Axis = (NumberAxis) subplot.getRangeAxis();
    log10Axis.setTickMarkInsideLength(2.0f);
    log10Axis.setTickMarkOutsideLength(2.0f);
    log10Axis.setMinorTickCount(2);
    log10Axis.setMinorTickMarksVisible(true);
    log10Axis.setAxisLineVisible(true);
    log10Axis.setAutoRangeIncludesZero(false);

    XYItemRenderer lblRenderer = subplot.getRenderer();
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(4.0d, chromosome);

    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelGenerator(1, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("Serif", Font.PLAIN, 12));
    lblRenderer.setSeriesItemLabelFont(1, new Font("Serif", Font.PLAIN, 12));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.TOP_LEFT, -Math.PI / 4.0));
    lblRenderer.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.TOP_LEFT, -Math.PI / 4.0));
    lblRenderer.setSeriesItemLabelsVisible(0, true);
    lblRenderer.setSeriesItemLabelsVisible(1, true);

    combinedPlot.add(subplot, 1);
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaMoneyGroupChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Money [Chf]");
    plot.setDomainAxis(xAxis);//from w  w w. java  2 s .  c om
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsGroupChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]");
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    plot.setDomainAxis(xAxis);//from ww  w.  ja v a  2s . com
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    return chart;
}

From source file:org.gwaspi.gui.reports.SampleQAHetzygPlotZoom.java

private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createScatterPlot("Heterozygosity vs. Missing Ratio",
            "Heterozygosity Ratio", "Missing Ratio", dataset, PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    // CHART BACKGROUD COLOR
    chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness
    plot.setBackgroundPaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9

    // GRIDLINES//from w  ww  .  jav a 2 s  .  com
    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setDomainMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7
    plot.setRangeMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker()); // Hue, saturation, brightness 8

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    // DOTS RENDERER
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, PLOT_MANHATTAN_DOTS);
    //      renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
    //      renderer.setUseOutlinePaint(true);
    // Set dot shape of the currently appended Series
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1, -1, 2, 2));

    renderer.setSeriesVisibleInLegend(0, false);

    // AXIS
    double maxHetzy = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxHetzy < dataset.getXValue(0, i)) {
            maxHetzy = dataset.getXValue(0, i);
        }
    }
    NumberAxis hetzyAxis = (NumberAxis) plot.getDomainAxis();
    hetzyAxis.setAutoRangeIncludesZero(true);
    hetzyAxis.setAxisLineVisible(true);
    hetzyAxis.setTickLabelsVisible(true);
    hetzyAxis.setTickMarksVisible(true);
    hetzyAxis.setRange(0, maxHetzy * 1.1);

    double maxMissrat = 0.005;
    for (int i = 0; i < dataset.getItemCount(0); i++) {
        if (maxMissrat < dataset.getYValue(0, i)) {
            maxMissrat = dataset.getYValue(0, i);
        }
    }
    NumberAxis missratAxis = (NumberAxis) plot.getRangeAxis();
    missratAxis.setAutoRangeIncludesZero(true);
    missratAxis.setAxisLineVisible(true);
    missratAxis.setTickLabelsVisible(true);
    missratAxis.setTickMarksVisible(true);
    missratAxis.setRange(0, maxMissrat * 1.1);

    // Add significance Threshold to subplot
    final Marker missingThresholdLine = new ValueMarker(missingThreshold);
    missingThresholdLine.setPaint(Color.blue);

    final Marker hetzyThresholdLine = new ValueMarker(hetzyThreshold);
    hetzyThresholdLine.setPaint(Color.blue);

    // Add legend to hetzyThreshold
    hetzyThresholdLine.setLabel("hetzyg. threshold = " + hetzyThreshold);
    missingThresholdLine.setLabel("missing. threshold = " + missingThreshold);
    hetzyThresholdLine.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    hetzyThresholdLine.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    missingThresholdLine.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
    missingThresholdLine.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    plot.addRangeMarker(missingThresholdLine); // THIS FOR MISSING RATIO
    plot.addDomainMarker(hetzyThresholdLine); // THIS FOR HETZY RATIO

    // Marker label if below hetzyThreshold
    XYItemRenderer lblRenderer = plot.getRenderer();

    // THRESHOLD AND SELECTED LABEL GENERATOR
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(hetzyThreshold, missingThreshold);
    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 10));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 2 * Math.PI));

    // TOOLTIP GENERATOR
    MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator();

    lblRenderer.setBaseToolTipGenerator(tooltipGenerator);

    lblRenderer.setSeriesItemLabelsVisible(0, true);

    return chart;
}

From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java

private JFreeChart createChart(XYDataset dataset, ChromosomeKey chr) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, "", "P value", dataset, PlotOrientation.VERTICAL,
            true, false, false);//from  w ww.  j  ava2  s .  c o m

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    // CHART BACKGROUD COLOR
    chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness
    plot.setBackgroundPaint(manhattan_back); // Hue, saturation, brightness 9

    // GRIDLINES
    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7
    plot.setDomainMinorGridlinePaint(manhattan_back); // Hue, saturation, brightness 9
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7
    plot.setRangeMinorGridlinePaint(manhattan_back.darker()); // Hue, saturation, brightness 8

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    // DOTS RENDERER
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, manhattan_dot);
    //      renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
    //      renderer.setUseOutlinePaint(true);
    // Set dot shape of the currently appended Series
    renderer.setSeriesShape(0, new Rectangle2D.Double(0.0, 0.0, 2, 2));

    renderer.setSeriesVisibleInLegend(0, false);

    NumberAxis positionAxis = (NumberAxis) plot.getDomainAxis();
    //      domainAxis.setAutoRangeIncludesZero(false);
    //      domainAxis.setTickMarkInsideLength(2.0f);
    //      domainAxis.setTickMarkOutsideLength(2.0f);
    //      domainAxis.setMinorTickCount(2);
    //      domainAxis.setMinorTickMarksVisible(true);
    positionAxis.setLabelAngle(1.0);
    positionAxis.setAutoRangeIncludesZero(false);
    positionAxis.setAxisLineVisible(true);
    positionAxis.setTickLabelsVisible(true);
    positionAxis.setTickMarksVisible(true);

    // ADD INVERSE LOG(10) Y AXIS
    LogAxis logPAxis = new LogAxis("P value");
    logPAxis.setBase(10);
    logPAxis.setInverted(true);
    logPAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE);

    logPAxis.setTickMarkOutsideLength(2.0f);
    logPAxis.setMinorTickCount(2);
    logPAxis.setMinorTickMarksVisible(true);
    logPAxis.setAxisLineVisible(true);
    logPAxis.setUpperMargin(0);

    TickUnitSource units = NumberAxis.createIntegerTickUnits();
    logPAxis.setStandardTickUnits(units);
    plot.setRangeAxis(0, logPAxis);

    // Add significance Threshold to subplot
    //threshold = 0.5/rdMatrixMetadata.getMarkerSetSize();  // (0.05/10? SNPs => 5*10-?)
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to threshold
    thresholdLine.setLabel("P = " + GenericReportGenerator.FORMAT_P_VALUE.format(threshold));
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    plot.addRangeMarker(thresholdLine);

    // Marker label if below threshold
    XYItemRenderer lblRenderer = plot.getRenderer();

    // THRESHOLD AND SELECTED LABEL GENERATOR
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(threshold, chr);
    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 12));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_LEFT, Math.PI / 4.0));

    // TOOLTIP GENERATOR
    MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(chr);

    lblRenderer.setBaseToolTipGenerator(tooltipGenerator);

    lblRenderer.setSeriesItemLabelsVisible(0, true);

    return chart;
}

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

JFreeChart labChart(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {/*from   w ww  .java2s .com*/
    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  av a 2  s.  c  om*/

    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) {/*from ww  w  .j a v  a2s  . 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) {/*w  w w .  jav a2 s  . 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:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java

JFreeChart rxAndLabChart(String demographicNo, String typeIdName, String typeIdName2, String patientName,
        String chartTitle) {//  www  .j av  a 2s.  com
    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;
}