List of usage examples for org.jfree.chart JFreeChart getXYPlot
public XYPlot getXYPlot()
From source file:eu.stratosphere.addons.visualization.swt.SWTJobTabItem.java
private ChartComposite initializeNetworkChart(Composite parentComposite, TableXYDataset dataset) { final JFreeChart chart = ChartFactory.createStackedXYAreaChart("Network", "Time [sec.]", "Average throughput [MBit/s]", dataset, PlotOrientation.VERTICAL, true, true, false); // 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(parentComposite, SWT.NONE, chart, true); }
From source file:main.GUI.java
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed areaVypis.setText(""); int pocetRep = Integer.parseInt(txtPoceRep.getText().toString()); int zahod = Integer.parseInt(txtZahod.getText().toString()); carlo = new SCMC(pocetRep, zahod); carlo.addObserver(this); avgSeries = new XYSeries("AVG"); XYSeriesCollection dataset = new XYSeriesCollection(avgSeries); JFreeChart lineChart = ChartFactory.createXYLineChart(null, null, null, dataset); final NumberAxis rangeAxis = (NumberAxis) lineChart.getXYPlot().getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); ChartPanel chartPanel = new ChartPanel(lineChart); panelLive.removeAll();/*from ww w . j a va 2 s . c o m*/ panelLive.add(chartPanel, BorderLayout.CENTER); panelLive.validate(); carlo.simuluj(avgSeries); }
From source file:uk.co.moonsit.sockets.DualAxisDemo2.java
/** * A demonstration application showing how to create a time series chart with dual axes. * * @param title the frame title./*from w w w. j av a 2 s .com*/ */ public DualAxisDemo2(final String title) { super(title); // create a title... final String chartTitle = "Dual Axis Demo 2"; final XYDataset dataset = createDataset1(); final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset, true, true, false); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); final NumberAxis axis2 = new NumberAxis("Secondary"); axis2.setAutoRangeIncludesZero(false); plot.setRangeAxis(1, axis2); plot.setDataset(1, createDataset2()); plot.mapDatasetToRangeAxis(1, 1); /*final XYItemRenderer renderer = plot.getRenderer(); renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; //rr.setPlotShapes(true); rr.setShapesFilled(true); }*/ final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, Color.black); //renderer2.setPlotShapes(true); //renderer.setToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); plot.setRenderer(1, renderer2); final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:org.jfree.chart.demo.TimeSeriesDemo13.java
/** * Creates a chart./*from w ww . j ava2s.com*/ * * @param dataset a dataset. * * @return A chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Weekly Data", "Date", "Value", dataset, true, true, false); chart.setBackgroundPaint(Color.white); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; rr.setPlotShapes(true); rr.setShapesFilled(true); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); final TickUnits standardUnits = new TickUnits(); standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 1, new SimpleDateFormat("MMM dd ''yy"))); standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("MMM dd ''yy"))); standardUnits.add(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM ''yy"))); axis.setStandardTickUnits(standardUnits); return chart; }
From source file:com.wattzap.view.graphs.GenericScatterGraph.java
public GenericScatterGraph(XYSeries series, String xAxis, String yAxis) { super();//w w w . j a va2s. c om XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createScatterPlot("", // chart title xAxis, // x axis label yAxis, // y axis label null, PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.darkGray); plot = chart.getXYPlot(); plot.setDataset(0, xyDataset); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // Shape cross = ShapeUtilities.createDiamond(0.5f); Shape cross = ShapeUtilities.createDiagonalCross(0.5f, 0.5f); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(252, 141, 89)); renderer.setSeriesShape(0, cross); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickLabelPaint(Color.white); rangeAxis.setLabelPaint(Color.white); chartPanel = new ChartPanel(chart); chartPanel.setSize(100, 800); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); setBackground(Color.black); chartPanel.revalidate(); setVisible(true); }
From source file:eu.stratosphere.addons.visualization.swt.SWTJobTabItem.java
private ChartComposite initializeMemoryChart(Composite parentComposite, TableXYDataset dataset) { final JFreeChart chart = ChartFactory.createStackedXYAreaChart("Memory", "Time [sec.]", "Average amount of memory allocated [MB]", dataset, PlotOrientation.VERTICAL, true, true, false); // Set axis properly final XYPlot xyPlot = chart.getXYPlot(); xyPlot.getDomainAxis().setAutoRange(true); xyPlot.getDomainAxis().setAutoRangeMinimumSize(60); // Workaround because auto range does not seem to work properly on the range axis final InstanceVisualizationData instanceVisualizationData = (InstanceVisualizationData) this.visualizationData .getNetworkTopology().getAttachment(); xyPlot.getRangeAxis().setAutoRange(false); xyPlot.getRangeAxis().setRange(0, instanceVisualizationData.getUpperBoundForMemoryChart()); return new ChartComposite(parentComposite, SWT.NONE, chart, true); }
From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java
@FXML public void initialize() { final JFreeChart chart = chartNode.getChart(); final XYPlot plot = chart.getXYPlot(); // Do not set colors and strokes dynamically. They are instead provided // by the dataset and configured in configureRenderer() plot.setDrawingSupplier(null);/*ww w . ja va 2s .c o m*/ plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // chart properties chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); // legend properties LegendTitle legend = chart.getLegend(); // legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); // set the X axis (retention time) properties NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setLabel("Retention time (min)"); xAxis.setUpperMargin(0.03); xAxis.setLowerMargin(0.03); xAxis.setRangeType(RangeType.POSITIVE); xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20)); // set the Y axis (intensity) properties NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel("Intensity"); yAxis.setRangeType(RangeType.POSITIVE); yAxis.setAutoRangeIncludesZero(true); // set the fixed number formats, because otherwise JFreeChart sometimes // shows exponent, sometimes it doesn't DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); xAxis.setNumberFormatOverride(mzFormat); DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); yAxis.setNumberFormatOverride(intensityFormat); chartTitle = chartNode.getChart().getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); chartTitle.setText("Chromatogram"); chartNode.setCursor(Cursor.CROSSHAIR); // Remove the dataset if it is removed from the list datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> { while (c.next()) { if (c.wasRemoved()) { for (ChromatogramPlotDataSet ds : c.getRemoved()) { int index = plot.indexOf(ds); plot.setDataset(index, null); } } } }); itemLabelsVisible.addListener((prop, oldVal, newVal) -> { for (ChromatogramPlotDataSet dataset : datasets) { int datasetIndex = plot.indexOf(dataset); XYItemRenderer renderer = plot.getRenderer(datasetIndex); renderer.setBaseItemLabelsVisible(newVal); } }); legendVisible.addListener((prop, oldVal, newVal) -> { legend.setVisible(newVal); }); }
From source file:org.jfree.chart.demo.XYStepAreaChartDemo.java
/** * Creates a chart.// ww w . j a v a 2 s . c o m * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYStepAreaChart("XY Step Area Chart Demo", "Domain (X)", "Range (Y)", dataset, PlotOrientation.VERTICAL, true, // legend true, // tool tips false // URLs ); // color final XYPlot plot = chart.getXYPlot(); plot.getRenderer().setSeriesPaint(0, Color.green); // fill shapes final XYStepAreaRenderer rend = (XYStepAreaRenderer) plot.getRenderer(); rend.setShapesFilled(true); return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleChartExpression.java
protected JFreeChart computeXYChart(final XYDataset dataset) { // Make sure we have a proper dataset final XYZDataset xyzDataset; final double maxZValue; if (dataset instanceof ExtendedXYZDataset) { final ExtendedXYZDataset exyzDataset = (ExtendedXYZDataset) dataset; xyzDataset = exyzDataset;/*from w w w. j a va 2 s .c o m*/ maxZValue = exyzDataset.getMaxZValue(); } else if (dataset instanceof XYZDataset) { xyzDataset = (XYZDataset) dataset; maxZValue = precomputeMaxZ(xyzDataset); } else { xyzDataset = null; maxZValue = 0; } final JFreeChart rtn = ChartFactory.createBubbleChart(computeTitle(), getDomainTitle(), getRangeTitle(), xyzDataset, computePlotOrientation(), isShowLegend(), false, false); final BubbleRenderer renderer = new BubbleRenderer(); renderer.setMaxSize(getMaxBubbleSize()); renderer.setMaxZ(maxZValue); rtn.getXYPlot().setRenderer(renderer); configureLogarithmicAxis(rtn.getXYPlot()); return rtn; }
From source file:com.redhat.rhn.frontend.graphing.GraphGenerator.java
/** * Generate a JFreeChart class from specified parameters. * * @param height height in pixels of the image generated * @param width in pixels of the image generated * @param xAxisLabel label for the x axis * @param yAxisLabel label for the y axis * @param timeSeriesData List of TimeSeriesData[] DTO objects * @param labelMap a map containing the localized labels used * for the metrics. Contains simple "metricId" keys * with the localized Strings as the value. For example: * labelMap={"pctfree" -> "Percent Free", "memused" -> "Memory Used"} * @return JFreeChart representation// w w w . j av a2 s. c o m */ public JFreeChart generateJFReeChart(int height, int width, String xAxisLabel, String yAxisLabel, List timeSeriesData, Map labelMap) { if (Context.getCurrentContext() == null || Context.getCurrentContext().getTimezone() == null || Context.getCurrentContext().getLocale() == null) { throw new IllegalArgumentException( "Context, Timezone or Locale is " + "NULL in the Context. Please make sure it has been set."); } XYDataset jfreeDataset = createDataset(timeSeriesData, labelMap); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title xAxisLabel, // x-axis label yAxisLabel, // y-axis label jfreeDataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); XYPlot plot = chart.getXYPlot(); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTimeZone(Context.getCurrentContext().getTimezone()); return chart; }