List of usage examples for org.jfree.chart.renderer.xy XYBarRenderer setBaseToolTipGenerator
@Override public void setBaseToolTipGenerator(XYToolTipGenerator generator)
From source file:org.jfree.chart.demo.OverlaidXYPlotDemo1.java
private static JFreeChart createChart() { IntervalXYDataset dataset1 = createDataset1(); XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D); renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); DateAxis domainAxis = new DateAxis("Date"); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); NumberAxis valueAxis = new NumberAxis("Value"); XYPlot plot = new XYPlot(dataset1, domainAxis, valueAxis, renderer1); XYDataset dataset2 = createDataset2(); StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); plot.setDataset(1, dataset2);// w w w. java2s . c om plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return new JFreeChart("Overlaid XYPlot Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.jfree.chart.demo.CombinedTimeSeriesDemo1.java
public static JPanel createDemoPanel() { TimeSeries timeseries = new TimeSeries("Annual"); timeseries.add(new Year(1998), 80D); timeseries.add(new Year(1999), 85D); timeseries.add(new Year(2000), 87.599999999999994D); TimeSeriesCollection dataset1 = new TimeSeriesCollection(timeseries); TimeSeries timeseries1 = new TimeSeries("Monthly A"); timeseries1.add(new Month(7, 2000), 85.799999999999997D); timeseries1.add(new Month(8, 2000), 85.799999999999997D); timeseries1.add(new Month(9, 2000), 85.799999999999997D); timeseries1.add(new Month(10, 2000), 86.5D); timeseries1.add(new Month(11, 2000), 86.5D); timeseries1.add(new Month(12, 2000), 86.5D); timeseries1.add(new Month(1, 2001), 87.700000000000003D); timeseries1.add(new Month(2, 2001), 87.700000000000003D); timeseries1.add(new Month(3, 2001), 87.700000000000003D); timeseries1.add(new Month(4, 2001), 88.5D); timeseries1.add(new Month(5, 2001), 88.5D); timeseries1.add(new Month(6, 2001), 88.5D); timeseries1.add(new Month(7, 2001), 90D); timeseries1.add(new Month(8, 2001), 90D); timeseries1.add(new Month(9, 2001), 90D); timeseries1.add(new Month(10, 2001), 90D); timeseries1.add(new Month(11, 2001), 90D); timeseries1.add(new Month(12, 2001), 90D); timeseries1.add(new Month(1, 2002), 90D); timeseries1.add(new Month(2, 2002), 90D); timeseries1.add(new Month(3, 2002), 90D); timeseries1.add(new Month(4, 2002), 90D); timeseries1.add(new Month(5, 2002), 90D); timeseries1.add(new Month(6, 2002), 90D); TimeSeries timeseries2 = new TimeSeries("Monthly B"); timeseries2.add(new Month(7, 2000), 83.799999999999997D); timeseries2.add(new Month(8, 2000), 83.799999999999997D); timeseries2.add(new Month(9, 2000), 83.799999999999997D); timeseries2.add(new Month(10, 2000), 84.5D); timeseries2.add(new Month(11, 2000), 84.5D); timeseries2.add(new Month(12, 2000), 84.5D); timeseries2.add(new Month(1, 2001), 85.700000000000003D); timeseries2.add(new Month(2, 2001), 85.700000000000003D); timeseries2.add(new Month(3, 2001), 85.700000000000003D); timeseries2.add(new Month(4, 2001), 86.5D); timeseries2.add(new Month(5, 2001), 86.5D); timeseries2.add(new Month(6, 2001), 86.5D); timeseries2.add(new Month(7, 2001), 88D); timeseries2.add(new Month(8, 2001), 88D); timeseries2.add(new Month(9, 2001), 88D); timeseries2.add(new Month(10, 2001), 88D); timeseries2.add(new Month(11, 2001), 88D); timeseries2.add(new Month(12, 2001), 88D); timeseries2.add(new Month(1, 2002), 88D); timeseries2.add(new Month(2, 2002), 88D); timeseries2.add(new Month(3, 2002), 88D); timeseries2.add(new Month(4, 2002), 88D); timeseries2.add(new Month(5, 2002), 88D); timeseries2.add(new Month(6, 2002), 88D); TimeSeriesCollection dataset21 = new TimeSeriesCollection(); dataset21.addSeries(timeseries1);//w w w . jav a2 s . c o m dataset21.addSeries(timeseries2); TimeSeries timeseries3 = new TimeSeries("XXX"); timeseries3.add(new Month(7, 2000), 81.5D); timeseries3.add(new Month(8, 2000), 86D); timeseries3.add(new Month(9, 2000), 82D); timeseries3.add(new Month(10, 2000), 89.5D); timeseries3.add(new Month(11, 2000), 88D); timeseries3.add(new Month(12, 2000), 88D); timeseries3.add(new Month(1, 2001), 90D); timeseries3.add(new Month(2, 2001), 89.5D); timeseries3.add(new Month(3, 2001), 90.200000000000003D); timeseries3.add(new Month(4, 2001), 90.599999999999994D); timeseries3.add(new Month(5, 2001), 87.5D); timeseries3.add(new Month(6, 2001), 91D); timeseries3.add(new Month(7, 2001), 89.700000000000003D); timeseries3.add(new Month(8, 2001), 87D); timeseries3.add(new Month(9, 2001), 91.200000000000003D); timeseries3.add(new Month(10, 2001), 84D); timeseries3.add(new Month(11, 2001), 90D); timeseries3.add(new Month(12, 2001), 92D); TimeSeriesCollection dataset22 = new TimeSeriesCollection(timeseries3); // XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D); renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})", new SimpleDateFormat("yyyy"), new DecimalFormat("0.00"))); XYPlot plot1 = new XYPlot(dataset1, new DateAxis("Date"), null, renderer1); // XYAreaRenderer renderer21 = new XYAreaRenderer(); XYPlot plot2 = new XYPlot(dataset21, new DateAxis("Date"), null, renderer21); StandardXYItemRenderer renderer22 = new StandardXYItemRenderer(3); renderer22.setBaseShapesFilled(true); plot2.setDataset(1, dataset22); plot2.setRenderer(1, renderer22); plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // NumberAxis valueAxis = new NumberAxis("Value"); valueAxis.setAutoRangeIncludesZero(false); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(valueAxis); combinedPlot.add(plot1, 1); combinedPlot.add(plot2, 4); //chart JFreeChart jfreechart = new JFreeChart("Sample Combined Plot", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, true); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(500, 270)); chartpanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent chartmouseevent) { System.out.println(chartmouseevent.getEntity()); } public void chartMouseMoved(ChartMouseEvent chartmouseevent) { System.out.println(chartmouseevent.getEntity()); } }); return chartpanel; }
From source file:org.jfree.chart.demo.PriceVolumeDemo2.java
private static JFreeChart createChart() { OHLCDataset ohlcdataset = createPriceDataset(); String s = "Sun Microsystems (SUNW)"; JFreeChart jfreechart = ChartFactory.createHighLowChart(s, "Date", "Price", ohlcdataset, true); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setLowerMargin(0.01D);/*w w w . ja v a 2 s . co m*/ dateaxis.setUpperMargin(0.01D); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setLowerMargin(0.59999999999999998D); numberaxis.setAutoRangeIncludesZero(false); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); NumberAxis numberaxis1 = new NumberAxis("Volume"); numberaxis1.setUpperMargin(1.0D); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createVolumeDataset()); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); XYBarRenderer xybarrenderer = new XYBarRenderer(); xybarrenderer.setDrawBarOutline(false); xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); xyplot.setRenderer(1, xybarrenderer); ChartUtilities.applyCurrentTheme(jfreechart); xybarrenderer.setShadowVisible(false); xybarrenderer.setBarPainter(new StandardXYBarPainter()); return jfreechart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYBarChartExpression.java
protected static JFreeChart createTimeSeriesChart(final String title, final String timeAxisLabel, final String valueAxisLabel, final XYDataset dataset, final boolean legend, final boolean tooltips, final boolean urls, final boolean stacked) { final ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);// w w w . ja v a 2s . c o m final NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default final XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } final XYBarRenderer renderer; if (stacked) { renderer = new StackedXYBarRenderer(); } else { renderer = new XYBarRenderer(); } renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }
From source file:org.jfree.chart.demo.PriceVolumeDemo1.java
private static JFreeChart createChart() { XYDataset xydataset = createPriceDataset(); String s = "Eurodollar Futures Contract (MAR03)"; JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(s, "Date", "Price", xydataset, true, true, false);/*from ww w .j a v a2 s .c om*/ XYPlot xyplot = (XYPlot) jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setLowerMargin(0.40000000000000002D); DecimalFormat decimalformat = new DecimalFormat("00.00"); numberaxis.setNumberFormatOverride(decimalformat); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); NumberAxis numberaxis1 = new NumberAxis("Volume"); numberaxis1.setUpperMargin(1.0D); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createVolumeDataset()); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D); xybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00"))); xyplot.setRenderer(1, xybarrenderer); return jfreechart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYBarChartExpression.java
/** * Creates and returns a default instance of an XY bar chart. * <p/>/*ww w . j a v a2s . co m*/ * The chart object returned by this method uses an {@link XYPlot} instance as the plot, with a {@link * org.jfree.chart.axis.DateAxis} for the domain axis, a {@link org.jfree.chart.axis.NumberAxis} as the range axis, * and a {@link XYBarRenderer} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param dateAxis make the domain axis display dates? * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT 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 An XY bar chart. */ public static JFreeChart createXYBarChart(final String title, final String xAxisLabel, final boolean dateAxis, final String yAxisLabel, final XYDataset dataset, final PlotOrientation orientation, final boolean legend, final boolean tooltips, final boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } ValueAxis domainAxis = null; if (dateAxis) { domainAxis = new DateAxis(xAxisLabel); } else { final NumberAxis axis = new NumberAxis(xAxisLabel); axis.setAutoRangeIncludesZero(false); domainAxis = axis; } final ValueAxis valueAxis = new NumberAxis(yAxisLabel); final XYBarRenderer renderer = new XYBarRenderer(); renderer.setUseYInterval(true); if (tooltips) { final XYToolTipGenerator tt; if (dateAxis) { tt = StandardXYToolTipGenerator.getTimeSeriesInstance(); } else { tt = new StandardXYToolTipGenerator(); } renderer.setBaseToolTipGenerator(tt); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } final XYPlot plot = new XYPlot(dataset, domainAxis, valueAxis, renderer); plot.setOrientation(orientation); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }
From source file:pisco.batch.visu.BatchingChartFactory.java
public static XYPlot createLatenessPlot(Batch[] batches) { final Paint[] palette = makePalette(batches.length); XYBarRenderer renderer = new XYBarRendererPaletteBySeries(palette); renderer.setUseYInterval(true);//from w w w .j av a 2s .co m renderer.setDrawBarOutline(true); final LatenessLabelToolTipGenerator bpg = new LatenessLabelToolTipGenerator(batches); renderer.setBaseItemLabelGenerator(bpg); renderer.setBaseItemLabelsVisible(true); renderer.setBaseToolTipGenerator(bpg); renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER)); XYPlot plot = new XYPlot(createLatenessDataset(batches), null, createIntegerAxis("Batches"), renderer); plot.setRangeGridlinesVisible(false); makeDueDateMarkers(plot, batches, palette); return plot; }
From source file:ChartUsingJava.CombinedXYPlotDemo1.java
/** * Creates an overlaid chart.//from w ww .ja v a 2s . c o m * * @return The chart. */ private static JFreeChart createCombinedChart() { // create plot ... IntervalXYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); DateAxis domainAxis = new DateAxis("Year"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.02); ValueAxis rangeAxis = new NumberAxis("$billion"); XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... IntervalXYDataset data2 = createDataset2(); XYBarRenderer renderer2 = new XYBarRenderer() { public Paint getItemPaint(int series, int item) { XYDataset dataset = getPlot().getDataset(); if (dataset.getYValue(series, item) >= 0.0) { return Color.red; } else { return Color.green; } } }; renderer2.setSeriesPaint(0, Color.red); renderer2.setDrawBarOutline(false); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false); chart.setBackgroundPaint(Color.white); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); return chart; }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java
protected static XYPlot createXYPlot(XYDataset dataset, Color[] colors) { // break up into two datasets, one for bars one for lines //LinkedList lines =new LinkedList(); //LinkedList bars = new LinkedList(); XYDataset seriesLines = new XYSeriesCollection(); XYDataset seriesBars = new XYSeriesCollection(); ((XYSeriesCollection) seriesBars).setIntervalWidth(0.0); if (dataset instanceof XYSeriesCollection) { while (0 < dataset.getSeriesCount()) { XYSeries s = ((XYSeriesCollection) dataset).getSeries(0); ((XYSeriesCollection) dataset).removeSeries(0); Comparable key = s.getKey(); boolean lines = false; if (key instanceof String) lines = ((String) key).startsWith("-"); if (lines) ((XYSeriesCollection) seriesLines).addSeries(s); else// w ww .ja v a2 s . c o m ((XYSeriesCollection) seriesBars).addSeries(s); } } else { seriesBars = dataset; } NumberAxis axisDomain = new NumberAxis(); axisDomain.setAutoRange(true); axisDomain.setAutoRangeIncludesZero(false); // axisDomain.setRange(400.0, 1600.0); // NOTE: zooming in too far kills the chart, prevent this axisDomain.addChangeListener(new AxisChangeListener() { public void axisChanged(AxisChangeEvent event) { NumberAxis axis = (NumberAxis) event.getSource(); Range range = axis.getRange(); if (range.getLength() < 2.0) { //_log.info("AxisChangeListener " + range.getLength() + " " + range.toString()); double middle = range.getLowerBound() + range.getLength() / 2.0; axis.setRange(new Range(middle - 1.1, middle + 1.1)); } } }); NumberAxis axisRange = new NumberAxis(); axisRange.setAutoRange(true); axisRange.setAutoRangeIncludesZero(true); XYToolTipGenerator toolTipGenerator = new XYToolTipGenerator() { public String generateToolTip(XYDataset xyDataset, int s, int i) { double X = Math.round(xyDataset.getXValue(s, i) * 1000.0) / 1000.0; double Y = Math.round(xyDataset.getYValue(s, i) * 1000.0) / 1000.0; return "(" + X + ", " + Y + ")"; } }; XYBarRenderer barRenderer = new XYBarRenderer(); //dhmay adding 2009/09/14. As of jfree 1.0.13, shadows on by default barRenderer.setShadowVisible(false); //dhmay adding for jfreechart 1.0.6 upgrade. If this isn't here, we get a //nullPointerException in XYBarRenderer.drawItemLabel barRenderer.setBaseItemLabelGenerator(new NullLabelGenerator()); barRenderer.setSeriesItemLabelsVisible(0, true); barRenderer.setBaseToolTipGenerator(toolTipGenerator); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(); lineRenderer.setBaseToolTipGenerator(toolTipGenerator); XYPlot xy = new XYPlot(null, axisDomain, axisRange, null); int ds = 0; if (seriesLines.getSeriesCount() > 0) { xy.setDataset(ds, seriesLines); xy.setRenderer(ds, lineRenderer); xy.mapDatasetToRangeAxis(ds, 0); ds++; for (int i = 0; i < seriesLines.getSeriesCount(); i++) { Comparable key = ((XYSeriesCollection) seriesLines).getSeriesKey(i); boolean lines = false; if (key instanceof String) lines = ((String) key).startsWith("-"); lineRenderer.setSeriesLinesVisible(i, lines); lineRenderer.setSeriesShapesVisible(i, !lines); } } if (seriesBars.getSeriesCount() > 0) { xy.setDataset(ds, seriesBars); xy.setRenderer(ds, barRenderer); xy.mapDatasetToRangeAxis(ds, 0); ds++; } setColors(xy, colors); return xy; }
From source file:pisco.batch.visu.BatchingChartFactory.java
public static XYPlot createBatchPlot(Batch[] batches, int capacity) { final XYBarRenderer renderer = new StackedXYBarRendererPaletteByItems(makePalette(batches.length)); renderer.setShadowVisible(false);/*from w ww . jav a 2 s .com*/ renderer.setShadowXOffset(0); renderer.setDrawBarOutline(true); renderer.setBaseOutlineStroke(new BasicStroke(2)); final BatchLabelToolTipGenerator lpg = new BatchLabelToolTipGenerator(); renderer.setBaseItemLabelGenerator(lpg); renderer.setBaseItemLabelsVisible(true); renderer.setBaseToolTipGenerator(lpg); XYPlot plot = new XYPlot(new BatchProcessingDataset(batches), null, createIntegerAxis("Load"), renderer); if (capacity > 0) { Marker capaMarker = createCapacityMarker(capacity, "Capacity", B_RED); plot.addRangeMarker(0, capaMarker, Layer.FOREGROUND); } return plot; }