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:com.rapidminer.gui.plotter.charts.MultipleSeriesChartPlotter.java
private JFreeChart createChart() { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title null, // x axis label null, // y axis label null, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls );// w w w .j av a 2 s . com chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customization... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) { DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis)); domainAxis.setTimeZone(Tools.getPreferredTimeZone()); chart.getXYPlot().setDomainAxis(domainAxis); } } else { plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false); ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false); } ValueAxis xAxis = plot.getDomainAxis(); if (indexAxis > -1) { xAxis.setLabel(getDataTable().getColumnName(indexAxis)); } else { xAxis.setLabel(SERIESINDEX_LABEL); } xAxis.setAutoRange(true); xAxis.setLabelFont(LABEL_FONT_BOLD); xAxis.setTickLabelFont(LABEL_FONT); xAxis.setVerticalTickLabels(isLabelRotating()); if (indexAxis > 0) { if (getRangeForDimension(indexAxis) != null) { xAxis.setRange(getRangeForDimension(indexAxis)); } } else { if (getRangeForName(SERIESINDEX_LABEL) != null) { xAxis.setRange(getRangeForName(SERIESINDEX_LABEL)); } } // renderer and range axis synchronized (dataTable) { int numberOfSelectedColumns = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { numberOfSelectedColumns++; } } } int columnCount = 0; for (int c = 0; c < dataTable.getNumberOfColumns(); c++) { if (getPlotColumn(c)) { if (dataTable.isNumerical(c)) { // YIntervalSeries series = new // YIntervalSeries(this.dataTable.getColumnName(c)); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(dataTable.getColumnName(c)); Iterator<DataTableRow> i = dataTable.iterator(); int index = 1; while (i.hasNext()) { DataTableRow row = i.next(); double value = row.getValue(c); if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) { double indexValue = row.getValue(indexAxis); series.add(indexValue, value); } else { series.add(index++, value); } } dataset.addSeries(series); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Color color = getColorProvider().getPointColor(1.0d); if (numberOfSelectedColumns > 1) { color = getColorProvider() .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1)); } renderer.setSeriesPaint(0, color); renderer.setSeriesStroke(0, new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); renderer.setSeriesShapesVisible(0, false); NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c)); if (getRangeForDimension(c) != null) { yAxis.setRange(getRangeForDimension(c)); } else { yAxis.setAutoRange(true); yAxis.setAutoRangeStickyZero(false); yAxis.setAutoRangeIncludesZero(false); } yAxis.setLabelFont(LABEL_FONT_BOLD); yAxis.setTickLabelFont(LABEL_FONT); if (numberOfSelectedColumns > 1) { yAxis.setAxisLinePaint(color); yAxis.setTickMarkPaint(color); yAxis.setLabelPaint(color); yAxis.setTickLabelPaint(color); } plot.setRangeAxis(columnCount, yAxis); plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT); plot.setDataset(columnCount, dataset); plot.setRenderer(columnCount, renderer); plot.mapDatasetToRangeAxis(columnCount, columnCount); columnCount++; } } } } chart.setBackgroundPaint(Color.white); return chart; }
From source file:org.jgrasstools.gears.utils.images.LineChartGenerator.java
/** * Creates the chart image and dumps it to file. * //from ww w.ja v a 2 s.c o m * @param chartFile the file to which to write to. * @param autoRange flag to define if to auto define the range from the bounds. * @param withLegend flag to define the legend presence. * @param imageWidth the output image width (if -1 default is used). * @param imageHeight the output image height (if -1 default is used). * @throws IOException */ @SuppressWarnings("nls") public void dumpChart(File chartFile, boolean autoRange, boolean withLegend, int imageWidth, int imageHeight) throws IOException { JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, collection, PlotOrientation.VERTICAL, withLegend, false, false); XYPlot plot = (XYPlot) chart.getPlot(); // plot.setDomainPannable(true); // plot.setRangePannable(true); // plot.setForegroundAlpha(0.85f); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); if (autoRange) { double delta = (max - min) * 0.1; yAxis.setRange(min - delta, max + delta); yAxis.setMinorTickCount(4); yAxis.setMinorTickMarksVisible(true); } // ValueAxis xAxis = plot.getDomainAxis(); // xAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US)); // XYItemRenderer renderer = plot.getRenderer(); // renderer.setDrawBarOutline(false); // // flat bars look best... // renderer.setBarPainter(new StandardXYBarPainter()); // renderer.setShadowVisible(false); if (!chartFile.getName().endsWith(".png")) { chartFile = FileUtilities.substituteExtention(chartFile, "png"); } if (imageWidth == -1) { imageWidth = IMAGEWIDTH; } if (imageHeight == -1) { imageHeight = IMAGEHEIGHT; } BufferedImage bufferedImage = chart.createBufferedImage(imageWidth, imageHeight); ImageIO.write(bufferedImage, "png", chartFile); }
From source file:net.sf.clichart.chart.XYChartBuilder.java
protected JFreeChart getChartImpl(Options options) { return ChartFactory.createXYLineChart(options.getChartTitle(), options.getChartXAxisTitle(), options.getChartYAxisTitle(), m_seriesCollection, PlotOrientation.VERTICAL, true, true, false); }
From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java
public JFreeChart createChart() { JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips false // urls );//from ww w . j a va 2s.co m return chart; }
From source file:ip.ui.plot.PlotGenerator.java
public void generateResultsChart(ResultsPlotData data, String fileName) throws IOException { XYSeries expectedData = new XYSeries("Expected output"); XYSeries networkData = new XYSeries("Network output"); List<double[]> inputs = new ArrayList(data.getInputs().size()); data.getInputs().stream().forEach((InputRow row) -> { inputs.add(row.getValues());// w ww . j a va 2 s . co m }); List<double[]> expectedOutputs = new ArrayList(data.getInputs().size()); data.getInputs().stream().forEach((InputRow row) -> { expectedOutputs.add(row.getExpectedOutput()); }); List<double[]> outputs = data.getOutputs(); for (int i = 0; i < inputs.size(); ++i) { expectedData.add(inputs.get(i)[0], expectedOutputs.get(i)[0]); networkData.add(inputs.get(i)[0], outputs.get(i)[0]); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(expectedData); dataset.addSeries(networkData); JFreeChart chart = ChartFactory.createXYLineChart(data.getPlotName(), data.getxAxisLabel(), data.getyAxisLabel(), dataset, PlotOrientation.VERTICAL, true, true, true); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesLinesVisible(1, false); chart.getXYPlot().setRenderer(renderer); File XYChart = new File(fileName); ChartUtilities.saveChartAsJPEG(XYChart, chart, chartWidth, chartHeight); }
From source file:de.openedu.serialconnect.lib.XYPlotter.java
/** * Creates a chart and a plotpanel and add it to the mainwindow. */// w w w . j a v a 2s .c om private void createChart() { getContentPane().removeAll(); xyDataset = createDataset(""); // create the chart... chart = ChartFactory.createXYLineChart("", // chart title "Line Chart Demo 6" "x", // x axis label "f(x)", // y axis label xyDataset, // data PlotOrientation.VERTICAL, true, // 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... plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); renderer.setSeriesShapesVisible(0, false); // a thin line will be painted for series1 renderer.setSeriesLinesVisible(1, false); // points will be painted for series2 plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... rangeAxis = (NumberAxis) plot.getRangeAxis(); domainAxis = (NumberAxis) plot.getDomainAxis(); // rangeAxis.setRange(0, 1); // setup and fix the range of y-achses // domainAxis.setRange(0, 100); // setup and fix the range of x-achses rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // plot.getDomainAxis().setRange(0, 100); // setup the range of y-achses // OPTIONAL CUSTOMISATION COMPLETED. chartPanel = new ChartPanel(chart); getContentPane().add(chartPanel); }
From source file:Transistor.JFETGraphViewer.java
public JFreeChart getResultChart() { this.makeNewSeries(); this.chart = ChartFactory.createXYLineChart("Output characteristic V-I curves", "V_ds", "I_d", data, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.getRangeAxis().setRange(0, 2100); pointer = new XYPointerAnnotation("V_ds", info.getVds(), getDrainCurrent(info.getVds()), PI / 4.0); plot.getAnnotations().clear();//from w ww .ja v a 2 s. c o m plot.addAnnotation(pointer); return this.chart; }
From source file:fr.crnan.videso3d.trajectography.Track2DView.java
public Track2DView(VidesoTrack track) { if (track instanceof LPLNTrack) { XYSeries dataset = new XYSeries(track.getName()); List<ValueMarker> markers = new LinkedList<ValueMarker>(); double distance = 0; LPLNTrackPoint last = null;/* ww w.ja v a 2 s. com*/ for (LPLNTrackPoint p : ((LPLNTrack) track).getTrackPoints()) { if (last != null) { distance += Position.ellipsoidalDistance(last.getPosition(), p.getPosition(), Earth.WGS84_EQUATORIAL_RADIUS, Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM; } dataset.add(distance, p.getElevation() / 30.48); ValueMarker marker = new ValueMarker(distance); marker.setLabel(p.getName()); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.TOP_CENTER); markers.add(marker); last = p; } JFreeChart chart = ChartFactory.createXYLineChart("Coupe 2D", "NM", "FL", new XYSeriesCollection(dataset), PlotOrientation.VERTICAL, false, false, false); for (ValueMarker m : markers) { chart.getXYPlot().addDomainMarker(m); } //ajout des secteurs AIP avec des XYPolygonAnnotation Collection<Object> secteurs; AIPController controller = (AIPController) DatasManager.getController(DatasManager.Type.AIP); secteurs = controller.getObjects(AIP.CTL); for (int i = 0; i <= 600; i += 10) { last = null; Secteur3D lastSecteur = null; double lastBoundary = 0.0; for (LPLNTrackPoint point : ((LPLNTrack) track).getTrackPoints()) { Position p = new Position(point.getPosition(), i * 30.48); //calcul du secteur contenant le point en cours Iterator<Object> iterator = secteurs.iterator(); boolean contain = false; Secteur3D secteur = null; while (iterator.hasNext() && !contain) { Secteur3D temp = (Secteur3D) iterator.next(); if (temp.contains(p)) { contain = true; secteur = temp; } } //si premier point, on enregistre simplement le secteur trouv if (last == null) { lastSecteur = secteur; } else { if (lastSecteur != secteur) { //si le secteur a chang, on dessine le secteur prcdent //sauf si ce dernier n'existait pas if (lastSecteur != null) { //dans ce cas, on calcule le point d'intersection entre le secteur et le segment form par les deux points //lastSecteur != null => last !=null Set<Point2D> intersects = lastSecteur .getIntersections(new Line2D.Double(last.getLatitude(), last.getLongitude(), p.getLatitude().degrees, p.getLongitude().degrees), true); if (!intersects.isEmpty()) { Point2D intersect = intersects.iterator().next(); distance = Position.ellipsoidalDistance( new LatLonCautra(intersect.getX(), intersect.getY()), last.getPosition(), Earth.WGS84_EQUATORIAL_RADIUS, Earth.WGS84_POLAR_RADIUS) / LatLonCautra.NM; //et ajout de l'annotation XYPolygonAnnotation annotation = new XYPolygonAnnotation( new double[] { lastBoundary, i, lastBoundary + distance, i, lastBoundary + distance, i + 10, lastBoundary, i + 10 }); chart.getXYPlot().addAnnotation(annotation); lastBoundary += distance; } } lastSecteur = secteur; } } last = point; } } //espace en haut pour les marqueurs chart.getXYPlot().getRangeAxis().setUpperMargin(0.05); ChartPanel chartPanel = new ChartPanel(chart); this.setContentPane(chartPanel); this.pack(); } }
From source file:support.SystemMonitorGui.java
private XYPlot createChartFrame(XYSeries series) { XYSeriesCollection dataSet = new XYSeriesCollection(); dataSet.addSeries(series);/*from ww w .ja v a2 s . c om*/ JFreeChart chart = ChartFactory.createXYLineChart("Memory Allocation Rate", "Time (ms)", "Allocation Rate (MB/s)", dataSet, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.getRenderer().setSeriesPaint(0, Color.BLUE); JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.setTitle("Hazelcast Jet Source Builder Sample"); frame.setBounds(WINDOW_X, WINDOW_Y, WINDOW_WIDTH, WINDOW_HEIGHT); frame.setLayout(new BorderLayout()); frame.add(new ChartPanel(chart)); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { hzMap.removeEntryListener(entryListenerId); } }); frame.setVisible(true); return plot; }
From source file:net.sourceforge.jasa.view.SupplyAndDemandFrame.java
public void initialiseGUI() { panel = new JPanel(); BorderLayout layout = new BorderLayout(); panel.setLayout(layout);//from w ww . j a va 2 s .c o m ArrayList<DataSeriesWriter> dataSeries = new ArrayList<DataSeriesWriter>(2); dataSeries.add(0, supplyCurve); dataSeries.add(1, demandCurve); ArrayList<String> seriesNames = new ArrayList<String>(2); seriesNames.add(0, "Supply"); seriesNames.add(1, "Demand"); dataset = new XYDatasetAdaptor(dataSeries, seriesNames); graph = ChartFactory.createXYLineChart(getGraphName(), "Price", "Quantity", dataset, PlotOrientation.HORIZONTAL, true, true, false); ChartPanel chartPanel = new ChartPanel(graph, true); chartPanel.setPreferredSize(new Dimension(500, 270)); panel.add(chartPanel); }