List of usage examples for org.jfree.chart.plot XYPlot setDomainCrosshairVisible
public void setDomainCrosshairVisible(boolean flag)
From source file:au.edu.jcu.usb.USBPlotFrame.java
/** * Constructs the ChartPanel from the provided XYSeriesCollection * * @param xySeriesCollection/*from w w w . j a v a 2 s. com*/ * @return The constructed ChartPanel containing the XY scatter plot */ private ChartPanel constructChart(XYSeriesCollection xySeriesCollection) { // Construct the scatter plot from the provided xySeriesCollection JFreeChart chart = ChartFactory.createScatterPlot("Title", "X Axis", "Y Axis", xySeriesCollection); // Get the XY Plot from the scatter chart XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); // Create the renderer XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setVerticalTickLabels(true); ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
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);/* www. j ava 2 s . c om*/ 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()); }/*from w ww. j av a 2 s . 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:cgpanalyser.gui.chart.ChartCreator.java
private void setCrosshairProperties(XYPlot plot, boolean visible) { plot.setDomainCrosshairVisible(visible); plot.setDomainCrosshairLockedOnData(true); plot.setRangeCrosshairVisible(visible); plot.setRangeCrosshairLockedOnData(true); }
From source file:org.mc.okapi.Plot.java
public Plot(double[] X, double[] Y, String xLab, String yLab, String seriesName, String applicationTitle, String chartTitle) {// w w w . j a va 2 s .c om super(applicationTitle); XYSeries series = new XYSeries(seriesName); for (int i = 0; i < X.length; i++) { series.add(X[i], Y[i]); } // create a dataset... XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); // based on the dataset we create the chart JFreeChart chart = ChartFactory.createScatterPlot(chartTitle, xLab, yLab, dataset, PlotOrientation.VERTICAL, true, rootPaneCheckingEnabled, rootPaneCheckingEnabled); Shape cross = ShapeUtilities.createDiagonalCross(3, 1); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesShape(0, cross); renderer.setSeriesPaint(0, Color.red); // we put the chart into a panel ChartPanel chartPanel = new ChartPanel(chart); setIconImage(Toolkit.getDefaultToolkit().getImage("images/ico/extra/science_32.png")); // default size chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); // add it to our application setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.ScatterPlotDemo4.java
/** * A demonstration application showing a scatter plot. * * @param title the frame title./* w w w. j a v a 2 s . c om*/ */ public ScatterPlotDemo4(final String title) { super(title); final XYDataset data = new SampleXYDataset2(); final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.setRenderer(new XYDotRenderer()); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.rhwlab.ace3d.VolumeIntensityPlot.java
public VolumeIntensityPlot(ImagedEmbryo emb) { this.embryo = emb; collect = new XYSeriesCollection(); series = new XYSeries("Nuclei"); collect.addSeries(series);/*w w w.ja v a2 s . c o m*/ chart = ChartFactory.createScatterPlot("", "Volume", "AvgIntensity", collect, PlotOrientation.VERTICAL, false, true, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotHeight(4); renderer.setDotWidth(4); // plot.setRenderer(renderer); ChartPanel panel = new ChartPanel(chart); panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { ChartEntity entity = event.getEntity(); if (entity instanceof XYItemEntity) { XYItemEntity xyEntity = (XYItemEntity) entity; NucleusPlotDataItem item = (NucleusPlotDataItem) series.getDataItem(xyEntity.getItem()); embryo.setSelectedNucleus(item.nuc); } } @Override public void chartMouseMoved(ChartMouseEvent event) { } }); this.add(panel); embryo.getNucleusFile().addSelectionOberver(this); }
From source file:com.charts.IntradayChart.java
public IntradayChart(YStockQuote currentStock) { TimeSeries series = new TimeSeries(currentStock.get_name()); ArrayList<String> fiveDayData = currentStock.get_one_day_data(); int length = fiveDayData.size(); for (int i = 17; i < length; i++) { String[] data = fiveDayData.get(i).split(","); Date time = new Date((long) Integer.parseInt(data[0]) * 1000); DateFormat df = new SimpleDateFormat("MM-dd-yyyy-h-m"); series.addOrUpdate(new Minute(time), Double.parseDouble(data[1])); }// w w w .jav a2 s . c o m TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart( currentStock.get_name() + "(" + currentStock.get_symbol() + ")" + " Intraday", "Date", "Price", dataset, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); xAxis.setDateFormatOverride(new SimpleDateFormat("h:m a")); xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //xAxis.setVerticalTickLabels(true); chartPanel = new ChartPanel(chart); chart.setBackgroundPaint(chartPanel.getBackground()); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); chartPanel.setVisible(true); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:org.cerberus.refactor.LineChart.java
public BufferedImage bi(TimeSeriesCollection timeseriescollection, String xname, String name, int count) { BufferedImage bi = null;/*from w w w . j av a2s . com*/ boolean fc = false; XYDataset xydataset = timeseriescollection; JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(name, xname, name, xydataset, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(false); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); if (xyitemrenderer instanceof XYLineAndShapeRenderer) { Shape point = ShapeUtilities.createDiagonalCross(1, 1); String[] seriesColors = { "#FF0000", "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01" }; String[] seriesColors2 = { "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01" }; XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer; xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); for (int a = 0; a < count; a++) { xylineandshaperenderer.setSeriesShape(a, point); xyitemrenderer.setSeriesStroke(a, new BasicStroke(1.0F)); //TODO check this - fc is always false if (fc) { xylineandshaperenderer.setSeriesPaint(a, Color.decode(seriesColors[count - a - 1])); } else { xylineandshaperenderer.setSeriesPaint(a, Color.decode(seriesColors2[count - a - 1])); } } } DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm")); bi = jfreechart.createBufferedImage(500, 270); return bi; }
From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo2.java
private static JFreeChart createTimeSeriesChart(XYDataset dataset) { //DomainAxis/*from www . ja v a 2 s. co m*/ DateAxis timeAxis = new DateAxis(""); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); //RangeAxis NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); // override default // valueAxis.setDefaultAutoRange(new Range(100, 1150)); //Renderer XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYURLGenerator urlGenerator = null; // urlGenerator = new StandardXYURLGenerator(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setDrawSeriesLineAsPath(true); //AbstractRenderer.dataBoundsIncludesVisibleSeriesOnly renderer.setDataBoundsIncludesVisibleSeriesOnly(false); renderer.setBaseSeriesVisibleInLegend(true); //Plot XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null) { private static final long serialVersionUID = 1L; // public void rendererChanged(RendererChangeEvent event) { // // if the event was caused by a change to series visibility, then // // the axis ranges might need updating... // if (event.getSeriesVisibilityChanged()) { //// configureDomainAxes(); //// configureRangeAxes(); // } // fireChangeEvent(); // } }; plot.setRenderer(renderer); plot.setBackgroundPaint(plotBackgroundPaint); 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); // plot.setRangePannable(true); //chart JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); valueAxis.setAutoRange(false); timeAxis.setAutoRange(false); return chart; }