List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:org.gumtree.vis.awt.PlotFactory.java
/** * Creates and returns a time series chart. A time series chart is an * {@link XYPlot} with a {@link DateAxis} for the x-axis and a * {@link NumberAxis} for the y-axis. The default renderer is an * {@link XYLineAndShapeRenderer}./* w ww . j av a 2 s. co m*/ * <P> * A convenient dataset to use with this chart is a * {@link org.jfree.data.time.TimeSeriesCollection}. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> * permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A time series chart. */ public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); // NumberAxis valueAxis = new NumberAxis(valueAxisLabel); LogAxis valueAxis = new LogAxis(valueAxisLabel); // valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); ChartFactory.getChartTheme().apply(chart); return chart; }
From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java
private static JFreeChart createStackedXYAreaChart(TableXYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0);/*from w w w . j ava2 s. c o m*/ xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(toolTipGenerator, urlGenerator); renderer.setOutline(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setRangeAxis(yAxis); // forces recalculation of the axis range JFreeChart chart = new JFreeChart("StackedXYArea Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createHistogramChart(XYDataset dataset) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); ValueAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYBarRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); }//w ww. j a va 2s . c o m if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); JFreeChart chart = new JFreeChart("Histogram Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java
private static JFreeChart createCandlestickChart(OHLCDataset dataset) { ValueAxis timeAxis = new DateAxis(xAxisLabel); NumberAxis valueAxis = new NumberAxis(yAxisLabel); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); plot.setRenderer(new CandlestickRenderer()); JFreeChart chart = new JFreeChart("Candlestick Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); return chart; }
From source file:charts.Chart.java
public static void GraficoSeries() { //System.out.println("After initComponents"); JFrame janela = new JFrame("Example of the series graphic"); janela.getContentPane().setLayout(null); javax.swing.JLabel jLabel1 = new javax.swing.JLabel(); jLabel1.setText(""); janela.getContentPane().add(jLabel1); y_of_x = new double[n_points]; x = new double[n_points]; XYSeries series1 = new XYSeries("Cos(x) versus x"); XYSeries series2 = new XYSeries("Cos^2(x) versus x"); for (int i = 0; i < n_points; i++) {//calculate the data to be plotted y_of_x[i] = Math.cos(i * Math.PI / 180); series1.add((double) i, y_of_x[i]);//add values to the series series2.add((double) i, Math.pow(y_of_x[i], 2)); }/*from w w w . ja v a 2 s . co m*/ XYDataset dataset1 = new XYSeriesCollection(series1); XYDataset dataset2 = new XYSeriesCollection(series2); CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new NumberAxis("x-angle argument")); XYItemRenderer renderer1 = new StandardXYItemRenderer(); XYPlot subplot1 = new XYPlot(dataset1, null, new NumberAxis("Cos(x)"), renderer1); NumberAxis axis1 = (NumberAxis) subplot1.getRangeAxis(); axis1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10)); axis1.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); axis1.setAutoRangeIncludesZero(false); parent.add(subplot1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); XYPlot subplot2 = new XYPlot(dataset2, null, new NumberAxis("Cos^2(x)"), renderer2); NumberAxis axis2 = (NumberAxis) subplot2.getRangeAxis(); axis2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10)); axis2.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); axis2.setAutoRangeIncludesZero(false); parent.add(subplot2, 1); JFreeChart chart = new JFreeChart("Cos(x) versus x", parent); ChartPanel myChart = new ChartPanel(chart); janela.setSize(500, 600); janela.setContentPane(myChart); janela.setVisible(true); }
From source file:tools.descartes.bungee.chart.ChartGenerator.java
private static XYPlot createAllocationPlot(final TimeSeriesCollection dataset) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(false); final NumberAxis rangeAxis = new NumberAxis("Resource Amount"); rangeAxis.setAutoRangeIncludesZero(true); //rangeAxis.setTickUnit(new NumberTickUnit(1)); double lower = Math.min(1, dataset.getRangeBounds(false).getLowerBound()) - 0.2; double upper = Math.max(2, dataset.getRangeBounds(false).getUpperBound()) + 0.2; rangeAxis.setRange(lower, upper);/*from w w w. ja v a2 s . c o m*/ final XYPlot allocationPlot = new XYPlot(dataset, null, rangeAxis, renderer); allocationPlot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE); for (int i = 0; i < dataset.getSeriesCount(); i++) { TimeSeries series = dataset.getSeries(i); //addEndSeriesItem(lastDate, series); String description = series.getKey().toString(); renderer.setSeriesStroke(i, new BasicStroke(STROKE_WIDTH)); if (description.equals(AllocationSeries.CATEGORY.DEMAND.toString())) { renderer.setSeriesShapesVisible(i, false); renderer.setSeriesPaint(i, Color.RED); } else if (description.equals(SupplySeries.TYPE.VM_SCHEDULED.toString())) { renderer.setSeriesPaint(i, VARIANT_C_COLOR); } else if (description.equals(SupplySeries.TYPE.VM_COMPLETED.toString())) { renderer.setSeriesPaint(i, VARIANT_B_COLOR); } else if (description.equals(SupplySeries.TYPE.LB_RULE_ADAPTION.toString())) { if (dataset.getSeriesCount() != 2) { renderer.setSeriesPaint(i, VARIANT_A_COLOR); } else { renderer.setSeriesPaint(i, Color.BLUE); } } else if (description.equals(SupplySeries.TYPE.MONITORED.toString())) { if (dataset.getSeriesCount() != 2) { renderer.setSeriesPaint(i, VARIANT_D_COLOR); } else { renderer.setSeriesPaint(i, Color.BLUE); } } else { renderer.setSeriesPaint(i, colorForConfig(description)); } } return allocationPlot; }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createHighLowChart(XYDataset dataset) { ValueAxis timeAxis = new DateAxis(xAxisLabel); NumberAxis valueAxis = new NumberAxis(yAxisLabel); HighLowRenderer renderer = new HighLowRenderer(); renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator()); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart("HighLow Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); 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 w w . ja v a 2 s .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); 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:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createStackedTimeSeriesChart( final TimeTableXYDatasetChartDefinition chartDefinition) { JFreeChart chart = null;/*from w w w . j a v a2 s . co m*/ // TODO Make the following accessible from the chartDefinition String domainAxisLabel = null; String rangeAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); DateAxis domainAxis = new DateAxis(domainAxisLabel, TimeZone.getDefault()); ValueAxis rangeAxis = new NumberAxis(rangeAxisLabel); XYItemRenderer renderer = null; switch (chartDefinition.getChartType()) { case AREA_CHART_TYPE: renderer = chartDefinition.isStacked() ? new StackedXYAreaRenderer2() : new XYAreaRenderer(); break; default: // should log an error if invalid chart type passed in - at least return null for no renderer return null; } if (tooltips) { XYToolTipGenerator generator = new StandardXYToolTipGenerator(chartDefinition.getTooltipContent(), new SimpleDateFormat(chartDefinition.getTooltipXFormat()), new DecimalFormat(chartDefinition.getTooltipYFormat())); renderer.setToolTipGenerator(generator); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); XYPlot plot = new XYPlot(chartDefinition, domainAxis, rangeAxis, renderer); JFreeChartEngine.updatePlot(plot, chartDefinition); chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:edu.fullerton.ldvservlet.SrcList.java
private PageItem makePlots(ArrayList<ChanSourceData> csdList, String name, Database db, Page vpage, ViewUser vuser, String contextPath) throws WebUtilException, LdvTableException { PageItemList ret = new PageItemList(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date/Time (UTC)")); plot.setGap(10.0);/*from w ww . ja v a 2s. c o m*/ String baseName = ""; StringBuilder errors = new StringBuilder(); int plotNum = 0; Color[] colors = { Color.RED, Color.BLUE, Color.MAGENTA, Color.ORANGE, Color.DARK_GRAY, Color.GREEN }; boolean gotData = false; TimeInterval timeRange = null; for (ChanSourceData csd : csdList) { TimeInterval ti = csd.getTimeRange(); if (ti != null) { if (timeRange == null) { timeRange = ti; } else if (timeRange.overlaps(ti)) { timeRange = timeRange.mergeIntervals(ti); } else if (ti.getStartGps() < timeRange.getStartGps()) { timeRange.setStartGps(ti.getStartGps()); } else if (ti.getStopGps() > timeRange.getStopGps()) { timeRange.setStopGps(ti.getStopGps()); } } } if (timeRange != null) { for (ChanSourceData csd : csdList) { baseName = csd.getChanInfo().getBaseName(); TimeSeriesCollection mtds = new TimeSeriesCollection(); String server = csd.getChanInfo().getServer().replace(".caltech.edu", ""); String legend = String.format("Type: %1$s at %2$s", csd.getChanInfo().getcType(), server); TimeSeries ts; double[][] data = csd.getGraphData(); if (data == null) { data = new double[2][2]; data[0][0] = timeRange.getStartGps(); data[1][0] = timeRange.getStopGps(); data[0][1] = data[1][1] = 0; errors.append("Error getting data for: ").append(legend).append("<br>"); } else { gotData = true; } for (double[] d : data) { d[1] = d[1] <= 1 ? 1 : d[1]; } ts = getTimeSeries(data, legend); mtds.addSeries(ts); XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA); BasicStroke str = new BasicStroke(2); int colorIdx = plotNum % colors.length; Color color = colors[colorIdx]; NumberAxis yAxis = new NumberAxis("% Avail"); yAxis.setRange(0, 100); renderer.setBaseFillPaint(color); renderer.setSeriesFillPaint(0, Color.WHITE); renderer.setBaseStroke(str); renderer.setUseFillPaint(true); XYPlot subplot = new XYPlot(mtds, null, yAxis, renderer); plot.add(subplot); plotNum++; } ChartPanel cpnl; JFreeChart chart; String gtitle = String.format("Available data for %1$s ", baseName); String subTitleTxt = String.format("From %1$s to %2$s", TimeAndDate.gpsAsUtcString(timeRange.getStartGps()), TimeAndDate.gpsAsUtcString(timeRange.getStopGps())); plot.setOrientation(PlotOrientation.VERTICAL); chart = new JFreeChart(gtitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.addSubtitle(new TextTitle(subTitleTxt)); cpnl = new ChartPanel(chart, false, false, false, false, false); PluginSupport psupport = new PluginSupport(); psupport.setup(db, vpage, vuser); int imgId; PageItemImage img = null; try { psupport.setSize(800, 600); imgId = psupport.saveImageAsPNG(cpnl); String url = String.format("%1$s/view?act=getImg&imgId=%2$d", contextPath, imgId); img = new PageItemImage(url, "availability", baseName); } catch (SQLException | IOException | NoSuchAlgorithmException ex) { String ermsg = String.format("Error creating or saving image: %1$s - $2$s", ex.getClass().getSimpleName(), ex.getLocalizedMessage()); errors.append(ermsg); } if (errors.length() > 0) { ret.add(errors.toString()); } if (img != null) { ret.add(img); } } else { ret.add("No data to plot."); } return ret; }