List of usage examples for org.jfree.chart ChartFactory createXYLineChart
public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:ca.nengo.plot.impl.DefaultPlotter.java
/** * @see ca.nengo.plot.Plotter#doPlot(ca.nengo.util.TimeSeries, ca.nengo.util.TimeSeries, java.lang.String) */// w w w .j a v a 2 s. c o m public void doPlot(TimeSeries ideal, TimeSeries actual, String title) { XYSeriesCollection idealDataset = getDataset(ideal); XYSeriesCollection actualDataset = getDataset(actual); JFreeChart chart = ChartFactory.createXYLineChart(title, "Time (s)", "", idealDataset, PlotOrientation.VERTICAL, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDataset(1, actualDataset); XYLineAndShapeRenderer idealRenderer = new XYLineAndShapeRenderer(true, false); idealRenderer.setDrawSeriesLineAsPath(true); idealRenderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10f, new float[] { 10f, 10f }, 0f)); plot.setRenderer(plot.indexOf(idealDataset), idealRenderer); XYLineAndShapeRenderer actualRenderer = new XYLineAndShapeRenderer(true, false); actualRenderer.setDrawSeriesLineAsPath(true); //idealRenderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10f, new float[]{10f, 10f}, 0f)); plot.setRenderer(plot.indexOf(actualDataset), actualRenderer); showChart(chart, "Time Series Plot"); }
From source file:org.interpss.chart.dstab.SimpleOneStateChart.java
/** * create the chart based on the data attributes * //from w w w .j a v a2s.com */ public void createChart() { final JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xLabel, yLabel, createXYDataSet(xDataAry, yDataAry, yDataLabel), PlotOrientation.VERTICAL, true, false, false); final XYPlot plot = (XYPlot) chart.getPlot(); final StandardXYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(renderer); //NumberAxis axis_x = (NumberAxis) plot.getDomainAxis(); //axis_x.setRangeAboutValue(12.0, 24.0); final NumberAxis axisLeft = (NumberAxis) plot.getRangeAxis(); axisLeft.setAutoRangeIncludesZero(false); axisLeft.setAutoRangeMinimumSize(autoRangeMinimumSize); final XYItemRenderer v_renderer = plot.getRenderer(0); v_renderer.setSeriesPaint(0, yColor); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(Chart_Width, Chart_Height)); setContentPane(chartPanel); }
From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo2.java
/** * Creates a chart./*w w w . j av a 2 s .co m*/ * * @param dataset the data for the chart. * * @return a chart. */ protected JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. setXSummary(dataset); return chart; }
From source file:Methods.CalculusSecant.java
public static ChartPanel createChartSecant(XYDataset datasetFunction) {// Method that populates and returns a Chart Pannel object, uses an entering paramether for the equation dataset and a global variable for the iteration points data set datasetPointsSecant();/*from www.j a v a 2 s . c o m*/ JFreeChart chart = ChartFactory.createXYLineChart("Equation Chart", "X Axys", "Y Axys", datasetFunction, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();//declaring a renderer used to plot more than one datatset on the table plot.setDataset(1, datasetPoints); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); plot.setRenderer(1, renderer); return new ChartPanel(chart); }
From source file:edu.ucla.stat.SOCR.chart.demo.NormalDistributionDemo.java
/** * Creates a line chart using the data from the supplied dataset. * /*from ww w. j a v a 2 s.c o m*/ * @param dataset the dataset. * * @return The chart. */ protected JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "X", "Y", dataset, PlotOrientation.VERTICAL, !legendPanelOn, true, false); return chart; }
From source file:org.nees.rpi.vis.ui.ProfilePlotFrame.java
private void initChartArea() { JFreeChart chart;/* w ww .j a v a 2 s.c om*/ xyDataset = new XYSeriesCollection(); chart = ChartFactory.createXYLineChart(null, "Sensor Reading", "Sensor Depth", xyDataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); XYPlot plot = (XYPlot) chart.getPlot(); plot.getDomainAxis().setAutoRange(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(true); renderer.setShapesFilled(true); chartPanel = new ChartPanel(chart); chartPanel.setFillZoomRectangle(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.setVerticalAxisTrace(true); chartPanel.setOpaque(false); VisSaveJChartPlotToImageButton saveButton = new VisSaveJChartPlotToImageButton(this, chart); JPanel buttonArea = new JPanel(); buttonArea.setOpaque(false); buttonArea.setLayout(new FlowLayout(FlowLayout.LEFT)); buttonArea.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 3)); buttonArea.add(saveButton); JPanel chartArea = new JPanel(); chartArea.setOpaque(false); chartArea.setLayout(new BorderLayout()); chartArea.add(chartPanel, BorderLayout.CENTER); chartArea.add(buttonArea, BorderLayout.NORTH); contentPane.add(chartArea, BorderLayout.CENTER); }
From source file:correospingtelnet.CorreosPingTelnet.java
private void mainAnterior() throws Exception { //JFreeChart chart; //chart = createPlot(); //ChartUtilities.saveChartAsPNG(new File("imagen.png"), chart, 1000, 600); // request/*from ww w .jav a 2 s . co m*/ final IcmpPingRequest request = IcmpPingUtil.createIcmpPingRequest(); request.setHost("192.168.1.5"); final XYSeries google = new XYSeries("Ping a google"); // repeat a few times for (int count = 1; count <= 1; count++) { // delegate final IcmpPingResponse response = IcmpPingUtil.executePingRequest(request); // log final String formattedResponse = IcmpPingUtil.formatResponse(response); System.out.println(formattedResponse); //Aqu tomaremos el valor de los ms y los guardaremos en un arreglo. String[] splitStr = formattedResponse.split("\\s+"); int valor = 0; if (splitStr.length > 5) { //Quitamos los ms char[] cadenaEnChars = splitStr[4].toCharArray(); if (cadenaEnChars.length == 8) { valor = Integer.parseInt(Character.toString(cadenaEnChars[5])); } else { valor = Integer .parseInt(Character.toString(cadenaEnChars[5]) + Character.toString(cadenaEnChars[6])); } } else { //Aqu hacer telnet //Aqu enviar correo Telnet.doTelnet("64.62.142.154"); valor = 0; } google.add(count, valor); // rest Thread.sleep(1000); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(google); JFreeChart xylineChart = ChartFactory.createXYLineChart("Grfica de ping", "Ping #", "ms", dataset, PlotOrientation.VERTICAL, true, true, false); ChartUtilities.saveChartAsPNG(new File("imagen.png"), xylineChart, 1000, 600); }
From source file:ch.zhaw.init.walj.projectmanagement.util.chart.LineChart.java
/** * creates a line chart with all booked and planned PMs *///w ww .ja v a 2 s .c om public void createChart() { // get dataset XYSeriesCollection dataset = null; try { dataset = (XYSeriesCollection) createDataset(); } catch (SQLException e) { e.printStackTrace(); } // create line chart JFreeChart xylineChart = ChartFactory.createXYLineChart("", "Month", "PM", dataset, PlotOrientation.VERTICAL, true, true, false); // set color of chart XYPlot plot = xylineChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, new Color(0, 101, 166)); renderer.setSeriesPaint(1, new Color(0, 62, 102)); plot.setRenderer(renderer); // set size of the chart and save it as small JPEG for project overview int width = 600; int height = 400; File lineChart = new File(path + "EffortProject" + project.getID() + ".jpg"); try { ChartUtilities.saveChartAsJPEG(lineChart, xylineChart, width, height); } catch (IOException e) { e.printStackTrace(); } // set size of the chart and save it as large JPEG for effort detail page width = 1200; height = 600; lineChart = new File(path + "/Charts/EffortProject" + project.getID() + "_large.jpg"); try { ChartUtilities.saveChartAsJPEG(lineChart, xylineChart, width, height); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotWindow.java
public IntensityPlotWindow(ParameterSet parameters) { PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue() .getMatchingPeakLists()[0];//from w w w. j a v a2 s . co m String title = "Intensity plot [" + peakList + "]"; String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString(); String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString(); // create dataset dataset = new IntensityPlotDataset(parameters); // create new JFreeChart logger.finest("Creating new chart instance"); Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue(); boolean isCombo = (xAxisValueSource instanceof ParameterWrapper) && (!(((ParameterWrapper) xAxisValueSource).getParameter() instanceof DoubleParameter)); if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) { chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); } else { chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); } chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this); add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); Plot plot = chart.getPlot(); // set shape provider IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier(); plot.setDrawingSupplier(shapeSupplier); // set y axis properties NumberAxis yAxis; if (plot instanceof CategoryPlot) yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis(); else yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis(); NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat(); if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT) yAxisFormat = MZmineCore.getConfiguration().getRTFormat(); yAxis.setNumberFormatOverride(yAxisFormat); setTitle(title); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); // Add the Windows menu JMenuBar menuBar = new JMenuBar(); menuBar.add(new WindowsMenu()); setJMenuBar(menuBar); pack(); // get the window settings parameter ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(IntensityPlotModule.class); WindowSettingsParameter settings = paramSet.getParameter(IntensityPlotParameters.windowSettings); // update the window and listen for changes settings.applySettingsToWindow(this); this.addComponentListener(settings); }
From source file:org.jmxtrans.embedded.samples.graphite.GraphiteDataInjector.java
public void exportMetrics(TimeSeries timeSeries) throws IOException { System.out.println("Export '" + timeSeries.getKey() + "' to " + graphiteHost + " with prefix '" + graphiteMetricPrefix + "'"); Socket socket = new Socket(graphiteHost, graphitePort); OutputStream outputStream = socket.getOutputStream(); if (generateDataPointsFile) { JFreeChart chart = ChartFactory.createXYLineChart("Purchase", "date", "Amount", new TimeSeriesCollection(timeSeries), PlotOrientation.VERTICAL, true, true, false); // chart.getXYPlot().setRenderer(new XYSplineRenderer(60)); File file = new File("/tmp/" + timeSeries.getKey() + ".png"); ChartUtilities.saveChartAsPNG(file, chart, 1200, 800); System.out.println("Exported " + file.getAbsolutePath()); String pickleFileName = "/tmp/" + timeSeries.getKey().toString() + ".pickle"; System.out.println("Generate " + pickleFileName); outputStream = new TeeOutputStream(outputStream, new FileOutputStream(pickleFileName)); }//w w w . j a v a2s. c o m PyList list = new PyList(); for (int i = 0; i < timeSeries.getItemCount(); i++) { if (debug) System.out.println(new DateTime(timeSeries.getDataItem(i).getPeriod().getStart()) + "\t" + timeSeries.getDataItem(i).getValue().intValue()); String metricName = graphiteMetricPrefix + timeSeries.getKey().toString(); int time = (int) TimeUnit.SECONDS.convert(timeSeries.getDataItem(i).getPeriod().getStart().getTime(), TimeUnit.MILLISECONDS); int value = timeSeries.getDataItem(i).getValue().intValue(); list.add(new PyTuple(new PyString(metricName), new PyTuple(new PyInteger(time), new PyInteger(value)))); if (list.size() >= batchSize) { System.out.print("-"); rateLimiter.acquire(list.size()); sendDataPoints(outputStream, list); } } // send last data points if (!list.isEmpty()) { rateLimiter.acquire(list.size()); sendDataPoints(outputStream, list); } Flushables.flushQuietly(outputStream); Closeables.close(outputStream, true); try { socket.close(); } catch (Exception e) { // swallow exception e.printStackTrace(); } System.out.println(); System.out.println("Exported " + timeSeries.getKey() + ": " + timeSeries.getItemCount() + " items"); }