List of usage examples for org.jfree.chart ChartFactory createHighLowChart
public static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, boolean legend)
From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.MeasurementGraphAction2.java
JFreeChart referenceRangeChart(String demographicNo, String typeIdName, String typeIdName2, String patientName, String chartTitle) {/*from w w w. jav a 2 s. co 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:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java
public static JFreeChart createChartWithXYDataSet(ChartData chartData) { XYDataset dataset = (XYDataset) chartData.getDatasource(); String type = chartData.getType(); String xAxis = chartData.getXlabel(); String yAxis = chartData.getYlabel(); boolean legend = chartData.isLegend(); JFreeChart chart = null;/* w ww. ja v a2 s .c o m*/ PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation()); if (type.equalsIgnoreCase("timeseries")) { chart = ChartFactory.createTimeSeriesChart("", xAxis, yAxis, dataset, legend, true, false); } else if (type.equalsIgnoreCase("xyline")) { chart = ChartFactory.createXYLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("polar")) { chart = ChartFactory.createPolarChart("", dataset, legend, true, false); } else if (type.equalsIgnoreCase("scatter")) { chart = ChartFactory.createScatterPlot("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("xyarea")) { chart = ChartFactory.createXYAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("xysteparea")) { chart = ChartFactory.createXYStepAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("xystep")) { chart = ChartFactory.createXYStepChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("bubble")) { chart = ChartFactory.createBubbleChart("", xAxis, yAxis, (XYZDataset) dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("candlestick")) { chart = ChartFactory.createCandlestickChart("", xAxis, yAxis, (OHLCDataset) dataset, legend); } else if (type.equalsIgnoreCase("boxandwhisker")) { chart = ChartFactory.createBoxAndWhiskerChart("", xAxis, yAxis, (BoxAndWhiskerXYDataset) dataset, legend); } else if (type.equalsIgnoreCase("highlow")) { chart = ChartFactory.createHighLowChart("", xAxis, yAxis, (OHLCDataset) dataset, legend); } else if (type.equalsIgnoreCase("histogram")) { chart = ChartFactory.createHistogram("", xAxis, yAxis, (IntervalXYDataset) dataset, plotOrientation, legend, true, false); } else if (type.equalsIgnoreCase("wind")) { chart = ChartFactory.createWindPlot("", xAxis, yAxis, (WindDataset) dataset, legend, true, false); } if (chart.getPlot() instanceof XYPlot) { chart.getXYPlot().setDomainGridlinesVisible(chartData.isDomainGridLines()); chart.getXYPlot().setRangeGridlinesVisible(chartData.isRangeGridLines()); if (chartData.getGenerateMap() != null) chart.getXYPlot().getRenderer().setURLGenerator(new StandardXYURLGenerator("")); } setXYSeriesColors(chart, chartData); setXYExtensions(chart, chartData); return chart; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Displays a vertical bar chart in its own frame. * * @return a high low chart.// w w w . ja va2s . co m */ public JFreeChart createHighLowChart() { // create a default chart based on some sample data... final String title = this.resources.getString("timeseries.highlow.title"); final String domain = this.resources.getString("timeseries.highlow.domain"); final String range = this.resources.getString("timeseries.highlow.range"); final String subtitleStr = this.resources.getString("timeseries.highlow.subtitle"); final DefaultHighLowDataset data = DemoDatasetFactory.createHighLowDataset(); final JFreeChart chart = ChartFactory.createHighLowChart(title, domain, range, data, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.magenta)); return chart; }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * * @param evaluation//from w w w . j a v a 2 s . c o m * @throws JRException */ protected JFreeChart createHighLowChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createHighLowChart( (String) evaluateExpression(getChart().getTitleExpression()), (String) evaluateExpression(((JRHighLowPlot) getPlot()).getTimeAxisLabelExpression()), (String) evaluateExpression(((JRHighLowPlot) getPlot()).getValueAxisLabelExpression()), (DefaultHighLowDataset) getDataset(), isShowLegend()); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); JRHighLowPlot highLowPlot = (JRHighLowPlot) getPlot(); HighLowRenderer hlRenderer = (HighLowRenderer) xyPlot.getRenderer(); boolean isShowOpenTicks = highLowPlot.getShowOpenTicks() == null ? false : highLowPlot.getShowOpenTicks().booleanValue(); boolean isShowCloseTicks = highLowPlot.getShowCloseTicks() == null ? false : highLowPlot.getShowCloseTicks().booleanValue(); hlRenderer.setDrawOpenTicks(isShowOpenTicks); hlRenderer.setDrawCloseTicks(isShowCloseTicks); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), highLowPlot.getTimeAxisLabelFont(), highLowPlot.getTimeAxisLabelColor(), highLowPlot.getTimeAxisTickLabelFont(), highLowPlot.getTimeAxisTickLabelColor(), highLowPlot.getTimeAxisTickLabelMask(), highLowPlot.getTimeAxisVerticalTickLabels(), highLowPlot.getOwnTimeAxisLineColor(), false, (Comparable) evaluateExpression(highLowPlot.getDomainAxisMinValueExpression()), (Comparable) evaluateExpression(highLowPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), highLowPlot.getValueAxisLabelFont(), highLowPlot.getValueAxisLabelColor(), highLowPlot.getValueAxisTickLabelFont(), highLowPlot.getValueAxisTickLabelColor(), highLowPlot.getValueAxisTickLabelMask(), highLowPlot.getValueAxisVerticalTickLabels(), highLowPlot.getOwnValueAxisLineColor(), true, (Comparable) evaluateExpression(highLowPlot.getRangeAxisMinValueExpression()), (Comparable) evaluateExpression(highLowPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * * @param evaluation// ww w .ja v a 2 s .com * @throws JRException */ protected JFreeChart createHighLowChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createHighLowChart( (String) evaluateExpression(getChart().getTitleExpression()), (String) evaluateExpression(((JRHighLowPlot) getPlot()).getTimeAxisLabelExpression()), (String) evaluateExpression(((JRHighLowPlot) getPlot()).getValueAxisLabelExpression()), (DefaultHighLowDataset) getDataset(), isShowLegend()); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); JRHighLowPlot highLowPlot = (JRHighLowPlot) getPlot(); HighLowRenderer hlRenderer = (HighLowRenderer) xyPlot.getRenderer(); boolean isShowOpenTicks = highLowPlot.getShowOpenTicks() == null ? false : highLowPlot.getShowOpenTicks().booleanValue(); boolean isShowCloseTicks = highLowPlot.getShowCloseTicks() == null ? false : highLowPlot.getShowCloseTicks().booleanValue(); hlRenderer.setDrawOpenTicks(isShowOpenTicks); hlRenderer.setDrawCloseTicks(isShowCloseTicks); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), highLowPlot.getTimeAxisLabelFont(), highLowPlot.getTimeAxisLabelColor(), highLowPlot.getTimeAxisTickLabelFont(), highLowPlot.getTimeAxisTickLabelColor(), highLowPlot.getTimeAxisTickLabelMask(), highLowPlot.getTimeAxisVerticalTickLabels(), highLowPlot.getOwnTimeAxisLineColor(), getDomainAxisSettings(), (Comparable) evaluateExpression(highLowPlot.getDomainAxisMinValueExpression()), (Comparable) evaluateExpression(highLowPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), highLowPlot.getValueAxisLabelFont(), highLowPlot.getValueAxisLabelColor(), highLowPlot.getValueAxisTickLabelFont(), highLowPlot.getValueAxisTickLabelColor(), highLowPlot.getValueAxisTickLabelMask(), highLowPlot.getValueAxisVerticalTickLabels(), highLowPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), (Comparable) evaluateExpression(highLowPlot.getRangeAxisMinValueExpression()), (Comparable) evaluateExpression(highLowPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
/** * *///from w w w. j a va 2s . c o m protected JFreeChart createHighLowChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createHighLowChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRHighLowPlot) getPlot()).getTimeAxisLabelExpression()), evaluateTextExpression(((JRHighLowPlot) getPlot()).getValueAxisLabelExpression()), (DefaultHighLowDataset) getDataset(), isShowLegend()); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); JRHighLowPlot highLowPlot = (JRHighLowPlot) getPlot(); HighLowRenderer hlRenderer = (HighLowRenderer) xyPlot.getRenderer(); boolean isShowOpenTicks = highLowPlot.getShowOpenTicks() == null ? false : highLowPlot.getShowOpenTicks(); boolean isShowCloseTicks = highLowPlot.getShowCloseTicks() == null ? false : highLowPlot.getShowCloseTicks(); hlRenderer.setDrawOpenTicks(isShowOpenTicks); hlRenderer.setDrawCloseTicks(isShowCloseTicks); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), highLowPlot.getTimeAxisLabelFont(), highLowPlot.getTimeAxisLabelColor(), highLowPlot.getTimeAxisTickLabelFont(), highLowPlot.getTimeAxisTickLabelColor(), highLowPlot.getTimeAxisTickLabelMask(), highLowPlot.getTimeAxisVerticalTickLabels(), highLowPlot.getOwnTimeAxisLineColor(), false, (Comparable<?>) evaluateExpression(highLowPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(highLowPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), highLowPlot.getValueAxisLabelFont(), highLowPlot.getValueAxisLabelColor(), highLowPlot.getValueAxisTickLabelFont(), highLowPlot.getValueAxisTickLabelColor(), highLowPlot.getValueAxisTickLabelMask(), highLowPlot.getValueAxisVerticalTickLabels(), highLowPlot.getOwnValueAxisLineColor(), true, (Comparable<?>) evaluateExpression(highLowPlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(highLowPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java
/** * *//* www . j ava 2s .c om*/ protected JFreeChart createHighLowChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createHighLowChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRHighLowPlot) getPlot()).getTimeAxisLabelExpression()), evaluateTextExpression(((JRHighLowPlot) getPlot()).getValueAxisLabelExpression()), (DefaultHighLowDataset) getDataset(), isShowLegend()); configureChart(jfreeChart, getPlot()); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); JRHighLowPlot highLowPlot = (JRHighLowPlot) getPlot(); HighLowRenderer hlRenderer = (HighLowRenderer) xyPlot.getRenderer(); boolean isShowOpenTicks = highLowPlot.getShowOpenTicks() == null ? false : highLowPlot.getShowOpenTicks(); boolean isShowCloseTicks = highLowPlot.getShowCloseTicks() == null ? false : highLowPlot.getShowCloseTicks(); hlRenderer.setDrawOpenTicks(isShowOpenTicks); hlRenderer.setDrawCloseTicks(isShowCloseTicks); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), highLowPlot.getTimeAxisLabelFont(), highLowPlot.getTimeAxisLabelColor(), highLowPlot.getTimeAxisTickLabelFont(), highLowPlot.getTimeAxisTickLabelColor(), highLowPlot.getTimeAxisTickLabelMask(), highLowPlot.getTimeAxisVerticalTickLabels(), highLowPlot.getOwnTimeAxisLineColor(), getDomainAxisSettings(), (Comparable<?>) evaluateExpression(highLowPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(highLowPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), highLowPlot.getValueAxisLabelFont(), highLowPlot.getValueAxisLabelColor(), highLowPlot.getValueAxisTickLabelFont(), highLowPlot.getValueAxisTickLabelColor(), highLowPlot.getValueAxisTickLabelMask(), highLowPlot.getValueAxisVerticalTickLabels(), highLowPlot.getOwnValueAxisLineColor(), getRangeAxisSettings(), (Comparable<?>) evaluateExpression(highLowPlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(highLowPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }
From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java
/** * *///from w w w .j a v a 2 s. c o m protected JFreeChart createHighLowChart() throws JRException { ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); JFreeChart jfreeChart = ChartFactory.createHighLowChart( evaluateTextExpression(getChart().getTitleExpression()), evaluateTextExpression(((JRHighLowPlot) getPlot()).getTimeAxisLabelExpression()), evaluateTextExpression(((JRHighLowPlot) getPlot()).getValueAxisLabelExpression()), (DefaultHighLowDataset) getDataset(), isShowLegend()); configureChart(jfreeChart); XYPlot xyPlot = (XYPlot) jfreeChart.getPlot(); JRHighLowPlot highLowPlot = (JRHighLowPlot) getPlot(); HighLowRenderer hlRenderer = (HighLowRenderer) xyPlot.getRenderer(); boolean isShowOpenTicks = highLowPlot.getShowOpenTicks() == null ? false : highLowPlot.getShowOpenTicks(); boolean isShowCloseTicks = highLowPlot.getShowCloseTicks() == null ? false : highLowPlot.getShowCloseTicks(); hlRenderer.setDrawOpenTicks(isShowOpenTicks); hlRenderer.setDrawCloseTicks(isShowCloseTicks); // Handle the axis formating for the category axis configureAxis(xyPlot.getDomainAxis(), highLowPlot.getTimeAxisLabelFont(), highLowPlot.getTimeAxisLabelColor(), highLowPlot.getTimeAxisTickLabelFont(), highLowPlot.getTimeAxisTickLabelColor(), highLowPlot.getTimeAxisTickLabelMask(), highLowPlot.getTimeAxisVerticalTickLabels(), highLowPlot.getTimeAxisLineColor(), false, (Comparable<?>) evaluateExpression(highLowPlot.getDomainAxisMinValueExpression()), (Comparable<?>) evaluateExpression(highLowPlot.getDomainAxisMaxValueExpression())); // Handle the axis formating for the value axis configureAxis(xyPlot.getRangeAxis(), highLowPlot.getValueAxisLabelFont(), highLowPlot.getValueAxisLabelColor(), highLowPlot.getValueAxisTickLabelFont(), highLowPlot.getValueAxisTickLabelColor(), highLowPlot.getValueAxisTickLabelMask(), highLowPlot.getValueAxisVerticalTickLabels(), highLowPlot.getValueAxisLineColor(), true, (Comparable<?>) evaluateExpression(highLowPlot.getRangeAxisMinValueExpression()), (Comparable<?>) evaluateExpression(highLowPlot.getRangeAxisMaxValueExpression())); return jfreeChart; }