List of usage examples for org.jfree.chart.plot XYPlot getRangeAxis
public ValueAxis getRangeAxis()
From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java
private ChartComposite createNetworkChart(InstanceVisualizationData instanceVisualizationData, Color backgroundColor) {//from w w w. j a v a 2 s. c o m final JFreeChart chart = ChartFactory.createStackedXYAreaChart(null, "Time [sec.]", "Network", instanceVisualizationData.getNetworkDataSet(), PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new java.awt.Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue())); // Set axis properly final XYPlot xyPlot = chart.getXYPlot(); xyPlot.getDomainAxis().setAutoRange(true); xyPlot.getDomainAxis().setAutoRangeMinimumSize(60); // TODO: Repair auto range for range axis xyPlot.getRangeAxis().setAutoRange(false); xyPlot.getRangeAxis().setRange(0, 4096); return new ChartComposite(getShell(), SWT.NONE, chart, true); }
From source file:org.jfree.chart.demo.CompassFormatDemo.java
/** * Creates a sample chart./*from w w w . jav a 2 s .co m*/ * * @return a sample chart. */ private JFreeChart createChart() { final XYDataset direction = createDirectionDataset(600); final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true, true, false); final XYPlot plot = chart.getXYPlot(); plot.getDomainAxis().setLowerMargin(0.0); plot.getDomainAxis().setUpperMargin(0.0); // configure the range axis to display directions... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); final TickUnits units = new TickUnits(); units.add(new NumberTickUnit(180.0, new CompassFormat())); units.add(new NumberTickUnit(90.0, new CompassFormat())); units.add(new NumberTickUnit(45.0, new CompassFormat())); units.add(new NumberTickUnit(22.5, new CompassFormat())); rangeAxis.setStandardTickUnits(units); // add the wind force with a secondary dataset/renderer/axis plot.setRangeAxis(rangeAxis); final XYItemRenderer renderer2 = new XYAreaRenderer(); final ValueAxis axis2 = new NumberAxis("Force"); axis2.setRange(0.0, 12.0); renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128)); plot.setDataset(1, createForceDataset(600)); plot.setRenderer(1, renderer2); plot.setRangeAxis(1, axis2); plot.mapDatasetToRangeAxis(1, 1); return chart; }
From source file:org.matsim.contrib.parking.parkingchoice.lib.GeneralLib.java
public static void generateXYScatterPlot(String fileName, double[] x, double[] y, String title, String xLabel, String yLabel) {//from w ww. j a va2 s . co m if (x.length != y.length) { DebugLib.stopSystemAndReportInconsistency("dimensions of arrays do not match"); } final XYSeries series1 = new XYSeries(title); for (int i = 0; i < x.length; i++) { series1.add(x[i], y[i]); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); final JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(1, false); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); int width = 500; int height = 300; try { ChartUtilities.saveChartAsPNG(new File(fileName), chart, width, height); } catch (IOException e) { } }
From source file:org.jfree.chart.demo.XYBoxAnnotationDemo1.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Breakdowns", "Production Date", "Hours of Operation", xydataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setSeriesShape(0, new Rectangle(2, 2)); xylineandshaperenderer.setSeriesShape(1, new Rectangle(2, 2)); xylineandshaperenderer.setBaseLinesVisible(false); xylineandshaperenderer.setBaseShapesFilled(true); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseToolTipGenerator(null); xylineandshaperenderer.setSeriesPaint(0, Color.blue); xylineandshaperenderer.setSeriesPaint(1, Color.red); xyplot.setDomainGridlineStroke(new BasicStroke(1.0F)); xyplot.setRangeGridlineStroke(new BasicStroke(1.0F)); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setTickUnit(new NumberTickUnit(50000D)); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1)); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM.yy")); dateaxis.setVerticalTickLabels(true); Color color = new Color(255, 0, 0, 60); Color color1 = new Color(0, 255, 0, 60); XYBoxAnnotation xyboxannotation = new XYBoxAnnotation((new Day(1, 1, 2004)).getMiddleMillisecond(), 0.0D, (new Day(31, 1, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color); xyboxannotation.setToolTipText("Value: 2.9"); xylineandshaperenderer.addAnnotation(xyboxannotation); xyboxannotation = new XYBoxAnnotation((new Day(1, 2, 2004)).getMiddleMillisecond(), 0.0D, (new Day(29, 2, 2004)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color, color); xyboxannotation.setToolTipText("Value: 2.5"); xylineandshaperenderer.addAnnotation(xyboxannotation); xyboxannotation = new XYBoxAnnotation((new Day(1, 5, 2004)).getMiddleMillisecond(), 50000D, (new Day(31, 5, 2004)).getMiddleMillisecond(), 100000D, new BasicStroke(0.0F), color, color); xyboxannotation.setToolTipText("Value: 1.8"); xylineandshaperenderer.addAnnotation(xyboxannotation); xyboxannotation = new XYBoxAnnotation((new Day(1, 6, 2005)).getMiddleMillisecond(), 0.0D, (new Day(30, 6, 2005)).getMiddleMillisecond(), 50000D, new BasicStroke(0.0F), color1, color1); xyboxannotation.setToolTipText("Value: 3.7"); xylineandshaperenderer.addAnnotation(xyboxannotation); return jfreechart; }
From source file:eu.stratosphere.addons.visualization.swt.SWTJobTabItem.java
private ChartComposite initializeCPUChart(Composite parentComposite, TableXYDataset dataset) { final JFreeChart chart = ChartFactory.createStackedXYAreaChart("CPU", "Time [sec.]", "Average CPU utilization [%]", dataset, PlotOrientation.VERTICAL, true, true, false); // Set axis properly final XYPlot xyPlot = chart.getXYPlot(); xyPlot.getDomainAxis().setAutoRange(true); xyPlot.getDomainAxis().setAutoRangeMinimumSize(60); xyPlot.getRangeAxis().setAutoRange(false); xyPlot.getRangeAxis().setRange(0, 100); return new ChartComposite(parentComposite, SWT.NONE, chart, true); }
From source file:org.jfree.chart.demo.MouseListenerDemo4.java
public void chartMouseClicked(ChartMouseEvent chartmouseevent) { int i = chartmouseevent.getTrigger().getX(); int j = chartmouseevent.getTrigger().getY(); System.out.println("x = " + i + ", y = " + j); Point2D point2d = chartPanel.translateScreenToJava2D(new Point(i, j)); XYPlot xyplot = (XYPlot) chart.getPlot(); ChartRenderingInfo chartrenderinginfo = chartPanel.getChartRenderingInfo(); java.awt.geom.Rectangle2D rectangle2d = chartrenderinginfo.getPlotInfo().getDataArea(); ValueAxis valueaxis = xyplot.getDomainAxis(); org.jfree.ui.RectangleEdge rectangleedge = xyplot.getDomainAxisEdge(); ValueAxis valueaxis1 = xyplot.getRangeAxis(); org.jfree.ui.RectangleEdge rectangleedge1 = xyplot.getRangeAxisEdge(); double d = valueaxis.java2DToValue(point2d.getX(), rectangle2d, rectangleedge); double d1 = valueaxis1.java2DToValue(point2d.getY(), rectangle2d, rectangleedge1); System.out.println("Chart: x = " + d + ", y = " + d1); }
From source file:net.nosleep.superanalyzer.analysis.views.YearView.java
/** * Creates a sample dataset.//www. jav a2 s . c o m * * @return The dataset. */ private void refreshDataset() { // TimeSeries t1 = new TimeSeries("Songs you have", "Year", "Count"); // TimeSeries t2 = new TimeSeries("Songs you played", "Year", "Count"); XYSeries t1 = new XYSeries(Misc.getString("SONGS_YOU_HAVE")); XYSeries t2 = new XYSeries(Misc.getString("SONGS_YOU_PLAYED")); Stat itemStats = null; if (_comboBox == null) { itemStats = _analysis.getStats(Analysis.KIND_TRACK, null); } else { ComboItem item = (ComboItem) _comboBox.getSelectedItem(); itemStats = _analysis.getStats(item.getKind(), item.getValue()); } Vector yearCountListHave = new Vector(); Hashtable years = itemStats.getYears(); Enumeration e = years.keys(); while (e.hasMoreElements()) { Integer year = (Integer) e.nextElement(); Integer count = (Integer) years.get(year); // if (count.intValue() > 0) yearCountListHave.addElement(new YearCountItem(year.intValue(), count.intValue())); } Collections.sort(yearCountListHave, new YearCountComparator()); for (int i = 0; i < yearCountListHave.size(); i++) { YearCountItem item = (YearCountItem) yearCountListHave.elementAt(i); // _dataset.addValue(item.Count, "Songs you have", new // Integer(item.Year)); t1.add(item.Year, new Integer(item.Count)); } Vector yearCountListPlay = new Vector(); Hashtable yearPlays = itemStats.getPlayYears(); e = yearPlays.keys(); while (e.hasMoreElements()) { Integer year = (Integer) e.nextElement(); Integer count = (Integer) yearPlays.get(year); // if (count.intValue() > 0) yearCountListPlay.addElement(new YearCountItem(year.intValue(), count.intValue())); } Collections.sort(yearCountListPlay, new YearCountComparator()); for (int i = 0; i < yearCountListPlay.size(); i++) { YearCountItem item = (YearCountItem) yearCountListPlay.elementAt(i); // _dataset.addValue(item.Count, "Songs you've played", new // Integer(item.Year)); t2.add(item.Year, new Integer(item.Count)); } _dataset.removeAllSeries(); _dataset.addSeries(t1); _dataset.addSeries(t2); // TimeSeriesCollection tsc = new TimeSeriesCollection(t1); XYPlot plot = (XYPlot) _chart.getPlot(); NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeStickyZero(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Theme.getColorSet()[0]); renderer.setSeriesPaint(1, Theme.getColorSet()[2]); }
From source file:org.jfree.experimental.chart.demo.XYTitleAnnotationDemo1.java
/** * Creates a chart./*w w w. j a v a 2 s. co m*/ * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); 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); LegendTitle lt = new LegendTitle(plot); lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); lt.setBackgroundPaint(new Color(200, 200, 255, 100)); lt.setFrame(new BlockBorder(Color.white)); lt.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, RectangleAnchor.BOTTOM_RIGHT); ta.setMaxWidth(0.48); plot.addAnnotation(ta); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ValueAxis yAxis = plot.getRangeAxis(); yAxis.setLowerMargin(0.35); return chart; }
From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java
private JFreeChart createXYLineChart(LoggerData loggerData, XYDataset dataset, boolean combined) { String title = combined ? "Combined Data" : loggerData.getName(); String rangeAxisTitle = combined ? "Data" : buildRangeAxisTitle(loggerData); JFreeChart chart = ChartFactory.createXYLineChart(title, "Time (sec)", rangeAxisTitle, dataset, VERTICAL, false, true, false);/* w ww. j av a 2 s . c o m*/ chart.setBackgroundPaint(BLACK); chart.getTitle().setPaint(WHITE); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(BLACK); plot.getDomainAxis().setLabelPaint(WHITE); plot.getRangeAxis().setLabelPaint(WHITE); plot.getDomainAxis().setTickLabelPaint(LIGHT_GREY); plot.getRangeAxis().setTickLabelPaint(LIGHT_GREY); plot.setDomainGridlinePaint(DARK_GREY); plot.setRangeGridlinePaint(DARK_GREY); plot.setOutlinePaint(DARK_GREY); return chart; }
From source file:visualizer.datamining.dataanalysis.NeighborhoodHit.java
private JFreeChart createChart(XYDataset xydataset) { JFreeChart chart = ChartFactory.createXYLineChart("Neighborhood Hit", "Number Neighbors", "Precision", xydataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot xyplot = (XYPlot) chart.getPlot(); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); xyplot.setDomainGridlinePaint(Color.BLACK); xyplot.setRangeGridlinePaint(Color.BLACK); xyplot.setOutlinePaint(Color.BLACK); xyplot.setOutlineStroke(new BasicStroke(1.0f)); xyplot.setBackgroundPaint(Color.white); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); xyplot.setDrawingSupplier(new DefaultDrawingSupplier( new Paint[] { Color.RED, Color.BLUE, Color.GREEN, Color.MAGENTA, Color.CYAN, Color.ORANGE, Color.BLACK, Color.DARK_GRAY, Color.GRAY, Color.LIGHT_GRAY, Color.YELLOW }, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setBaseShapesFilled(true); xylineandshaperenderer.setDrawOutlines(true); return chart; }