List of usage examples for org.jfree.data.xy XYSeries XYSeries
public XYSeries(Comparable key)
From source file:xdevs.lib.util.ScopeMultiView.java
public void addSerie(String serieName) { if (seriesMap.containsKey(serieName)) { return;//from ww w . j ava 2 s .c o m } XYSeries serie = new XYSeries(serieName); seriesMap.put(serieName, serie); dataSet.addSeries(serie); }
From source file:PlotsBuilding.PlotPanel.java
private JFreeChart fillCollection(ArrayList<PlotsData> plotscollection) { XYSeriesCollection col = new XYSeriesCollection(); ArrayList<Integer> seriesCount = new ArrayList<>(); int SeriesCount = 0; PlotsData plotdata = new PlotsData(); if (plotscollection.isEmpty()) { XYSeries series = new XYSeries("1. "); series.add(0, 0);/* w w w .j av a 2 s. co m*/ plotdata.y1 = -10; plotdata.y2 = 10; col.addSeries(series); } for (int i = 0; i < plotscollection.size(); i++) { plotdata = (PlotsData) plotscollection.get(i); col = plotdata.createPlotdataset(i, col); seriesCount.add(col.getSeriesCount() - SeriesCount); SeriesCount = col.getSeriesCount(); } double y1 = plotdata.y1; double y2 = plotdata.y2; JFreeChart chart = createChart(col, seriesCount, y1, y2); return chart; }
From source file:ch.zhaw.init.walj.projectmanagement.util.chart.LineChart.java
/** * creates a dataset with all data about planned and booked effort * @return dataset with planned and booked PMs * @throws SQLException//from w w w .j av a2s . co m */ private XYDataset createDataset() throws SQLException { // initialize variables Effort effort = new Effort(tasks, path); double plannedEffort = 0; double bookedEffort = 0; XYSeries planned = new XYSeries("Planned"); XYSeries booked = new XYSeries("Booked"); int projectMonths = project.getNumberOfMonths(); // get planned and booked effort for every month for (double i = 1; i <= projectMonths; i++) { effort.getPlannedEffort(i); plannedEffort += effort.getPlannedEffort(i); planned.add(i, plannedEffort); if (effort.getBookedEffort(i) != 0) { bookedEffort += effort.getBookedEffort(i); booked.add(i, bookedEffort); } } // add booked and planned effort to dataset XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(booked); dataset.addSeries(planned); return dataset; }
From source file:techtonic.PlotGraphListener.java
@Override public void actionPerformed(ActionEvent e) { Vector<String> v = new Vector<String>(Arrays.asList(trajectoryQuality)); Techtonic.setEnablejcbX_Axis(true);//from w w w.j ava 2s. c o m Techtonic.setEnablejcbY_Axis(true); Techtonic.setjcbX_Axis(v); Techtonic.setjcbY_Axis(v); List<WitsmlTrajectoryStation> stationsAsList = Arrays .asList(new WitsmlTrajectoryStation[trajectory.getStations().size()]); for (WitsmlTrajectoryStation s : trajectory.getStations()) { stationsAsList.set(s.getStationNo(), s); } Techtonic.setEnablejcbX_Axis(true); Techtonic.setPropertyBtn(true); Techtonic.setEnablejcbY_Axis(true); Techtonic.setjcbX_Axis(v); Techtonic.setjcbY_Axis(v); Techtonic.setEnableRenderBtn(true); XYSeries series = new XYSeries(trajectory.getName()); String xu = ""; String yu = ""; // add data to Dataset (here assume data is in ArrayLists x and y int count = 1; for (WitsmlTrajectoryStation station : stationsAsList) { Value tvd = station.getTvd(); if (tvd == null) { continue; } xu = tvd.getUnit(); Value md = station.getNorth(); if (md == null) { continue; } yu = md.getUnit(); // System.out.println(count + " : ===>> tvd : "+tvd.getValue()+ "; md "+md.getValue()); series.add(md.getValue(), tvd.getValue()); count++; } XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(series); Techtonic.setCurrentStations(stationsAsList); // create a chart using the createYLineChart method... JFreeChart chart = ChartFactory.createXYLineChart(trajectory.getName(), // chart title xu, yu, // x and y axis labels data); // XYPlot plot = (XYPlot) chart.getPlot(); // XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); // renderer.setSeriesLinesVisible(0, true); // renderer.setSeriesShapesVisible(1, true); // renderer.setSeriesLinesVisible(1, false); // renderer.setSeriesShapesVisible(1, true); // plot.setRenderer(renderer); ChartPanel cp = new ChartPanel(chart); // JFrame fr = new JFrame(); // fr.add(cp); // fr.pack(); // fr.setVisible(true); //cp.setMouseZoomable(true, true); // Techtonic.setTrajName(trajectory.getName()); Techtonic.setFreeChart(chart); Techtonic.setDisplayArea(cp); // chartPanel.setLayout(new java.awt.BorderLayout()); // chartPanel.add(cp,BorderLayout.CENTER); // chartPanel.validate(); // chartPanel.repaint();` }
From source file:org.jfree.chart.demo.XYLogAxesDemo.java
/** * Creates a new demo./*from w w w .ja v a2 s .c om*/ * * @param title the frame title. */ public XYLogAxesDemo(final String title) { super(title); //Object[][][] data = new Object[3][50][2]; final XYSeries s1 = new XYSeries("Series 1"); final XYSeries s2 = new XYSeries("Series 2"); final XYSeries s3 = new XYSeries("Series 3"); // for (int i = 1; i <= 50; i++) { // s1.add(i, 1000 * Math.pow(i, -2)); // s2.add(i, 1000 * Math.pow(i, -3)); // s3.add(i, 1000 * Math.pow(i, -4)); // } for (int i = 1; i <= 50; i++) { s1.add(i, 10 * Math.exp(i / 5.0)); s2.add(i, 20 * Math.exp(i / 5.0)); s3.add(i, 30 * Math.exp(i / 5.0)); } final XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); dataset.addSeries(s3); final JFreeChart chart = ChartFactory.createXYLineChart("Log Axis Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); final XYPlot plot = chart.getXYPlot(); final NumberAxis domainAxis = new NumberAxis("x"); final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)"); plot.setDomainAxis(domainAxis); plot.setRangeAxis(rangeAxis); chart.setBackgroundPaint(Color.white); plot.setOutlinePaint(Color.black); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:beadAnalyzer.DrawPoints.java
public XYSeries drawPoints(final ArrayList<GaussianFitParam> beadparams, final String name, final int numBins) { final XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries seriesname = new XYSeries(name); List<Double> Xvalues = new ArrayList<Double>(); List<Double> Yvalues = new ArrayList<Double>(); if (name == "Sigma") { for (final GaussianFitParam param : beadparams) { seriesname.add(param.Sigma[0], param.Sigma[1]); Xvalues.add(param.Sigma[0]); Yvalues.add(param.Sigma[1]); }/*from w ww. j a v a 2 s. co m*/ } dataset.addSeries(seriesname); final JFreeChart histXchart = makehistXChart(Xvalues, numBins); final JFreeChart histYchart = makehistYChart(Yvalues, numBins); display(histXchart, new Dimension(500, 500)); display(histYchart, new Dimension(500, 500)); return seriesname; }
From source file:org.jfree.chart.demo.LineChartDemo3.java
/** * Creates a new demo./*w w w .j ava2 s . com*/ * * @param title the frame title. */ public LineChartDemo3(final String title) { super(title); // create a dataset... final XYSeriesCollection dataset = new XYSeriesCollection(); for (int i = 0; i < 10; i++) { final XYSeries series = new XYSeries("S" + i); for (int j = 0; j < 10; j++) { series.add(j, Math.random() * 100); } dataset.addSeries(series); } final JFreeChart chart = createChart(dataset); // add the chart to a panel... final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:com.compomics.pepshell.view.statistics.RatioStatisticsScatterplotPane.java
@Override public void setGraphData(PepshellProtein aPepshellProtein) { List<XYLineAnnotation> annotations = new ArrayList<>(); XYSeriesCollection allExperiments = new XYSeriesCollection(); for (Experiment anExperiment : experiments) { int proteinIndex = anExperiment.getProteins().indexOf(aPepshellProtein); if (proteinIndex != -1) { XYSeries anExperimentSeries = new XYSeries(anExperiment.getExperimentName()); PepshellProtein experimentPepshellProtein = anExperiment.getProteins().get(proteinIndex); for (PeptideGroup aGroup : experimentPepshellProtein.getPeptideGroups()) { PeptideInterface shortestPeptide = aGroup.getRepresentativePeptide(); if (shortestPeptide instanceof QuantedPeptide && ((QuantedPeptide) shortestPeptide).getRatio() != null) { Double value = Math.log(((QuantedPeptide) shortestPeptide).getRatio()) / Math.log(2); //Double value = ((QuantedPeptide) shortestPeptide).getRatio(); if (value == Double.NEGATIVE_INFINITY) { value = 0.0;/*from www .jav a 2s . co m*/ } double barWithErrors = (shortestPeptide.getEndProteinMatch() + shortestPeptide.getBeginningProteinMatch()) / 2; double error = Math.log(((QuantedPeptide) shortestPeptide).getStandardError()) / Math.log(2); //double error =((QuantedPeptide) shortestPeptide).getStandardError(); XYLineAnnotation vertical = new XYLineAnnotation(barWithErrors, value - error, barWithErrors, value + error, new BasicStroke(), Color.black); XYLineAnnotation horizontalUpper = new XYLineAnnotation(value + error - 0.25, value + error, value + error + 0.25, value + error, new BasicStroke(), Color.black); XYLineAnnotation horizontalLower = new XYLineAnnotation(value - error - 0.25, value - error, value - error + 0.25, value - error, new BasicStroke(), Color.black); annotations.add(vertical); annotations.add(horizontalUpper); annotations.add(horizontalLower); for (int i = shortestPeptide.getBeginningProteinMatch(); i < shortestPeptide .getEndProteinMatch(); i++) { anExperimentSeries.add(i, value); } } } allExperiments.addSeries(anExperimentSeries); } } JFreeChart ratioChart = ChartFactory.createHistogram( "ratio for " + aPepshellProtein.getVisibleAccession() + " over all experiments", "peptide start", "log^2 ratio", allExperiments, PlotOrientation.VERTICAL, true, true, false); chart.setChart(ratioChart); for (XYLineAnnotation anAnnotation : annotations) { ((XYPlot) ratioChart.getPlot()).addAnnotation(anAnnotation); } prettifyChart(ratioChart); }
From source file:org.cyberoam.iview.charts.XYLine.java
/** * This method generates JFreeChart instance for XYLine chart with iView customization. * @param reportID specifies that for which report Chart is being prepared. * @param rsw specifies data set which would be used for the Chart * @param requeest used for Hyperlink generation from URL. * @return jfreechart instance with iView Customization. *//* ww w .ja v a2 s . com*/ public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; try { ReportColumnBean reportColumnBean = null; GraphBean graphBean = null; DataLinkBean dataLinkBean = null; XYDataset dataset = null; XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYSeries series = new XYSeries(reportBean.getTitle()); graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getXColumnId());//getting ReportColumnBean For X Axis String xColumnDBname = reportColumnBean.getDbColumnName(); String xColumnName = reportColumnBean.getColumnName(); //Wheather DataLink is Given For X Axis column if (reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnDBname = reportColumnBean.getDbColumnName(); String yColumnName = reportColumnBean.getColumnName(); //if DataLink is not Given For X Axis column then Check of Y Axis Column if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getZColumnId()); String zColumnDbname = reportColumnBean.getDbColumnName(); //Preparing DataSet String data = ""; rsw.beforeFirst(); while (rsw.next()) { data = rsw.getString(xColumnDBname); series.add(Long.parseLong((data).substring(data.length() - 2)), new Long(rsw.getLong(yColumnDBname)).longValue()); } seriesCollection.addSeries(series); dataset = seriesCollection; // create the chart... chart = ChartFactory.createXYLineChart("", // chart title "", // domain axis label "", seriesCollection, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); /* * Additional iView Customization. */ //Set the background color for the chart... chart.setBackgroundPaint(Color.white); //Get a reference to the plot for further customisation... XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(new Color(245, 245, 245)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setForegroundAlpha(0.7f); //Set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); if (reportColumnBean.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) { rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4)); } rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10)); rangeAxis.setTickLabelsVisible(true); rangeAxis.setTickMarksVisible(false); rangeAxis.setAxisLineVisible(false); Axis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10)); domainAxis.setTickMarksVisible(false); domainAxis.setAxisLineVisible(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.DARK_GRAY); renderer.setSeriesStroke(0, new BasicStroke(1)); } catch (Exception e) { e.printStackTrace(); } return chart; }
From source file:org.usfirst.frc.team2084.neuralnetwork.RobotHeadingTest.java
/** * //from w ww.j a v a2s. c o m */ @Override public void run() { try { final DefaultValueDataset headingData = new DefaultValueDataset(0); final DefaultValueDataset desiredHeadingData = new DefaultValueDataset(0); final CompassPlot headingPlot = new CompassPlot(); headingPlot.addDataset(headingData); headingPlot.addDataset(desiredHeadingData); final JFreeChart headingChart = new JFreeChart("Heading", headingPlot); final XYSeries headingTimeSeries = new XYSeries("Heading"); final XYSeriesCollection headingTimeData = new XYSeriesCollection(); headingTimeData.addSeries(headingTimeSeries); final JFreeChart headingTimeChart = ChartFactory.createXYLineChart("Heading vs. Time", "Time", "Heading", headingTimeData, PlotOrientation.VERTICAL, true, true, false); final XYSeries errorTimeSeries = new XYSeries("Error"); final XYSeriesCollection errorTimeData = new XYSeriesCollection(); errorTimeData.addSeries(errorTimeSeries); final JFreeChart errorTimeChart = ChartFactory.createXYLineChart("Error vs. Time", "Time", "Error", errorTimeData, PlotOrientation.VERTICAL, true, true, false); SwingUtilities.invokeAndWait(() -> { final JFrame frame = new JFrame("Charts"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container content = frame.getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); final JPanel chartPanel = new JPanel(); chartPanel.setLayout(new GridLayout(2, 2)); content.add(chartPanel); final ChartPanel headingPanel = new ChartPanel(headingChart); chartPanel.add(headingPanel); final ChartPanel headingTimePanel = new ChartPanel(headingTimeChart); chartPanel.add(headingTimePanel); final ChartPanel errorTimePanel = new ChartPanel(errorTimeChart); chartPanel.add(errorTimePanel); final JPanel buttonPanel = new JPanel(); content.add(buttonPanel); final JButton startButton = new JButton("Start"); final JButton stopButton = new JButton("Stop"); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stop(); startButton.setEnabled(false); stopButton.setEnabled(true); start(headingData, desiredHeadingData, headingTimeSeries, errorTimeSeries); } }); buttonPanel.add(startButton); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stop(); startButton.setEnabled(true); stopButton.setEnabled(false); } }); stopButton.setEnabled(false); buttonPanel.add(stopButton); frame.pack(); frame.setVisible(true); }); } catch (Exception ex) { ex.printStackTrace(); } }