Example usage for org.jfree.chart ChartFactory createXYLineChart

List of usage examples for org.jfree.chart ChartFactory createXYLineChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createXYLineChart.

Prototype

public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset) 

Source Link

Document

Creates a line chart (based on an XYDataset ) with default settings.

Usage

From source file:udpserver.UDPui.java

/**
 * Creates new form UDPui/*from   w w  w .  ja v  a 2 s.co  m*/
 */
public UDPui() {
    // <editor-fold defaultstate="collapsed" desc="Graph">
    series = new XYSeries("ECG Reading");
    series.setMaximumItemCount(50);
    XYSeriesCollection dataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYLineChart("ECG Reading", "Time (seconds)", "Voltage (volt)",
            dataset);

    final XYPlot plot = chart.getXYPlot();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();

    JPanel jPanel1 = new JPanel();
    jPanel1.setLayout(new java.awt.BorderLayout());
    jPanel1.setVisible(true);
    jPanel1.setSize(600, 500);
    jPanel1.add(new ChartPanel(chart), BorderLayout.CENTER);
    jPanel1.validate();
    add(jPanel1);
    // </editor-fold>
    initComponents();
    receiveUDP();
    //        tempReceiveUDP();
    //        new UDPServer(valuePane);
}

From source file:LowPassFilterTest.java

@Test
public void test() throws InterruptedException {
    CategoryTableXYDataset serie = new CategoryTableXYDataset();
    serie.setNotify(false);/*from  w ww .jav a  2  s  . com*/
    double step = 1.0 / discretization;
    double startPosition = step * framePosition;
    //100 ? - 100 , 50 ? - 50 , 25 ?- 25 
    double[] data = math.convolve(
            math.HammingWindow(testData.get1DPolyharmSignal(4, 200, frameWidth, discretization), frameWidth),
            math.lpf(60, step, 1024));
    //        double[] data = math.convolve(testData.get1DSignal(100, 200, frameWidth, discretization), math.lpf(70, step, 128));

    //        double[] data = math.convolve(testData.get1DSignal(100, 200, 32768, 10000), math.lpf(70, 1./10000, 32));
    //        double[] data = testData.get1DSignal(100, 200, frameWidth, discretization);
    //        double[] data = math.lpf(70, step,128);
    for (int i = 0; i < data.length; i++) {
        serie.add(startPosition, data[i], "");
        startPosition += step;
    }
    JFreeChart chart = ChartFactory.createXYLineChart("", "t,c", "g, /c^2", serie);
    chart.removeLegend();
    chart.setAntiAlias(false);

    XYPlot plot = chart.getXYPlot();
    //plot.setRangeGridlinePaint(Color.BLACK);
    org.jfree.chart.axis.ValueAxis yAxis = plot.getRangeAxis();
    org.jfree.chart.axis.ValueAxis xAxis = plot.getDomainAxis();
    double start = framePosition * 1.0 / discretization;
    double max = start + frameWidth * 1.0 / discretization;
    xAxis.setRange(start, max);
    ChartPanel chartPanel = new ChartPanel(chart);

    JPanel p = new JPanel(new BorderLayout());

    p.removeAll();
    p.add(chartPanel);
    p.validate();
    //1. Create the frame.
    JFrame frame = new JFrame("FrameDemo");

    //2. Optional: What happens when the frame closes?
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //3. Create components and put them in the frame.
    //...create emptyLabel...
    frame.getContentPane().add(new Label("olol"), BorderLayout.CENTER);
    frame.getContentPane().add(p, BorderLayout.CENTER);

    //4. Size the frame.
    frame.pack();

    //5. Show it.
    frame.setVisible(true);
}

From source file:statUtil.TurnMovementPlot.java

public TurnMovementPlot(String title) throws IOException {
    super(title);
    Data data = CSVData.getCSVData(TURN_CSV_LOG);
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y",
            XYDatasetGenerator.generateXYDataset(data.csvData));
    final XYPlot xyPlot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(3f));
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    Shape cross = ShapeUtilities.createDiagonalCross(2f, 0.5f);
    renderer.setSeriesShape(1, cross);/* w w w.j  av a  2 s. c o  m*/
    xyPlot.setRenderer(renderer);
    xyPlot.setQuadrantOrigin(new Point(0, 0));

    int i = 0;
    for (Double[] csvRow : data.csvData) {
        if (i % 20 == 1) {
            final XYTextAnnotation annotation = new XYTextAnnotation(Double.toString(csvRow[3]), csvRow[0],
                    csvRow[1]);
            annotation.setFont(new Font("SansSerif", Font.PLAIN, 10));
            xyPlot.addAnnotation(annotation);
        }
        i++;
    }

    int width = (int) Math.round(data.maxX - data.minX) + 50;
    int height = (int) Math.round(data.maxY - data.minY) + 50;
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(width, height));
    setContentPane(chartPanel);
    File XYChart = new File(FILE_PATH + "\\TurnMovementPlot.png");
    ChartUtilities.saveChartAsPNG(XYChart, chart, width, height);
}

From source file:neironweb.Frame.java

public Frame() {
    super("neural network");
    //JPanel pane = new JPanel();

    setLayout(null);/*from   w w w . j  a v  a2s.  co m*/

    JPanel mailPanel = new JPanel();
    mailPanel.setLayout(null);
    mailPanel.setLocation(50, 30);
    mailPanel.setSize(300, 170);
    mailPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    JLabel mailLabel = new JLabel("e-mail:");
    mailLabel.setLocation(10, 10);
    mailLabel.setSize(50, 30);
    mailPanel.add(mailLabel);

    JLabel dirMailLabel = new JLabel("direct:");
    dirMailLabel.setLocation(10, 50);
    dirMailLabel.setSize(50, 30);
    mailPanel.add(dirMailLabel);

    JTextField mailField = new JTextField("mail@mail.ru");
    mailField.setSize(150, 30);
    mailField.setLocation(80, 10);
    mailPanel.add(mailField);

    JTextField textField = new JTextField("INBOX");
    textField.setLocation(80, 50);
    textField.setSize(150, 30);
    mailPanel.add(textField);

    JButton mailButton = new JButton("Analyze");
    mailButton.setLocation(80, 90);
    mailButton.setSize(150, 30);
    mailPanel.add(mailButton);

    //        JButton eduButton = new JButton("Start education");
    //        eduButton.setLocation(0, 50);
    //        eduButton.setSize(150, 30);
    //        buttonPanel.add(eduButton);

    XYSeries xyser = new XYSeries("");
    XYDataset xy = new XYSeriesCollection(xyser);
    JFreeChart jf = ChartFactory.createXYLineChart("Education", "X", "Y", xy);

    for (int i = 0; i < 100; i++)
        xyser.add(i, Math.cos(i));

    ChartPanel chartPanel = new ChartPanel(jf);
    chartPanel.setSize(700, 300);
    chartPanel.setLocation(50, 230);
    chartPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    //        JPanel myChartPanel = new JPanel();        
    //        myChartPanel.setLayout(null);
    //        myChartPanel.setLocation(50, 230);
    //        myChartPanel.setSize(700, 300);
    //        myChartPanel
    //      myChartPanel.add(chartPanel);        

    setSize(800, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = this.getContentPane(); // inherit main frame
    //con.add(pane); 
    con.add(mailPanel);
    //con.add(myChartPanel);
    con.add(chartPanel);
    setVisible(true);

}

From source file:cachedataanalysis.FlowCacheGroup.java

public XYSeries exportReportChart() throws IOException {

    ArrayList<XYSeries> series = new ArrayList<XYSeries>();

    for (FlowCache cache : caches) {
        series.add(cache.exportReportChart());
    }// ww w.  jav a2 s .  co m

    XYSeriesCollection data = new XYSeriesCollection();

    for (XYSeries s : series) {
        data.addSeries(s);
    }

    JFreeChart chart = ChartFactory.createXYLineChart("Performance by Size", "Second", "Hit Rate", data);
    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitRateComp" + size + ".jpg"), chart, 1500,
            900);

    return series.get(series.size() / 2 + 1);

}

From source file:de.nomagic.printerController.gui.TemperaturePanel.java

public TemperaturePanel(Executor exe) {
    updateExecutor(exe);
    chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset);
    myPanel = new ChartPanel(chart);
}

From source file:de.hs.mannheim.modUro.diagram.JCellcycletimeDiagram.java

protected JFreeChart createChart(XYDataset dataset, List<String> celltypes) {
    String title = "Cell cycle times";

    JFreeChart xyLineChart = ChartFactory.createXYLineChart(title, // title
            "t", // x-axis label
            "T", // y-axis label
            dataset);//from  www. j a  v a2s.  c  o m

    String fontName = "Palatino";
    xyLineChart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));

    XYPlot plot = (XYPlot) xyLineChart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    plot.getRangeAxis().setLowerMargin(0.0);
    // plot.getRangeAxis().setRange(0.0, 1.01);
    plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
    plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
    xyLineChart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
    xyLineChart.getLegend().setFrame(BlockBorder.NONE);
    xyLineChart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
    XYItemRenderer r = plot.getRenderer();

    // set the default stroke for all series
    int i = 0;
    for (String celltype : celltypes) {
        r.setSeriesPaint(i, CellTypeColor.getColor(celltype));
        i++;
    }
    return xyLineChart;
}

From source file:serial.ChartFromSerial.java

/**
 * Creates new form JavaArduinoInterfacingAttempt
 */// w w  w .j a  v  a  2 s.  co  m
public ChartFromSerial() {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.out.println(e);
    }
    initComponents();

    //set autoscroll
    autoScroll_chkBx.setSelected(true);
    autoScrollEnabled = true;

    //create the graph
    defaultSeries = new XYSeries(graphName);
    defaultDataset = new XYSeriesCollection(defaultSeries);
    defaultChart = ChartFactory.createXYLineChart(graphName, xAxisLabel, yAxisLabel, defaultDataset);
    graph = new ChartPanel(defaultChart);
    chartPanel.add(graph, BorderLayout.CENTER);
    graph.setVisible(true);

    //create the text log
    text = new JTextArea();
    text.setEditable(false);
    textScrollPane = new JScrollPane(text);
    textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    textPanel.add(textScrollPane, BorderLayout.CENTER);
    textScrollPane.setVisible(true);

    //Populate the combo box
    portNames = SerialPort.getCommPorts();
    while (portNames.length == 0) {
        if (JOptionPane.showConfirmDialog(rootPane, "No connected devices found.\nWould you like to refresh?",
                "Could not connect to any devices.", JOptionPane.YES_NO_OPTION,
                JOptionPane.ERROR_MESSAGE) == JOptionPane.NO_OPTION) {
            buttonsOff();
            return;
        } else {
            portNames = SerialPort.getCommPorts();
        }
    }
    portList_jCombo.removeAllItems();
    for (SerialPort portName : portNames) {
        portList_jCombo.addItem(portName.getSystemPortName());
    }
}

From source file:techtonic.PlotLogGraphListener.java

@Override
public void actionPerformed(ActionEvent e) {

    List<WitsmlLogCurve> curves = log.getCurves();

    Vector<String> curveDescription = new Vector<>();
    for (WitsmlLogCurve c : curves) {
        // System.out.println(c.getDescription());
        curveDescription.add(c.getDescription());
    }//from ww w .j a  v a  2 s. co  m
    Techtonic.setjcbX_Axis(curveDescription);

    Techtonic.setEnablejcbX_Axis(true);
    Techtonic.setEnablejcbY_Axis(false);
    Techtonic.setEnableRenderBtn(true);
    Techtonic.setPropertyBtn(true);

    //Techtonic.setjcbX_Axis();
    Vector<String> v = new Vector<String>(Arrays.asList(new String[] { "Depth" }));
    Techtonic.setjcbY_Axis(v);
    //plot the graph using values of the second entry
    WitsmlLogCurve ydata = curves.get(0);
    WitsmlLogCurve xdata = curves.get(1);
    List<Object> yvalues = ydata.getValues();
    List<Object> xvalues = xdata.getValues();
    String title = "Depth against " + xdata.getDescription();
    XYSeries series = new XYSeries(title);

    for (int i = 0; i < yvalues.size(); i++) {
        Object vx = xvalues.get(i);
        Object vy = yvalues.get(i);
        double dx = Double.parseDouble(vx.toString());
        double dy = Double.parseDouble(vy.toString());
        series.add(dx, dy);
    }
    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // create a chart using the createYLineChart method...
    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xdata.getDescription(), "Depth", // x and y axis labels
            data); // data

    ChartPanel cp = new ChartPanel(chart);
    //            JFrame fr = new JFrame();
    //            fr.add(cp);
    //            fr.pack();
    //            fr.setVisible(true);
    //cp.setMouseZoomable(true, true);  
    Techtonic.setFreeChart(chart);
    Techtonic.setCurrentCurves(curves);
    Techtonic.setDisplayArea(cp);
    //            chartPanel.setLayout(new java.awt.BorderLayout());
    //            chartPanel.add(cp,BorderLayout.CENTER);
    //            chartPanel.validate();
    //            chartPanel.repaint();
}

From source file:simx.profiler.discovery.latency.LatencyReportTopComponent.java

public LatencyReportTopComponent() {
    initComponents();/*from   w  w w  .j  a  v  a2  s . c om*/
    setName(Bundle.CTL_LatencyReportTopComponent());
    setToolTipText(Bundle.HINT_LatencyReportTopComponent());

    this.latencyPlotData = new XYSeriesCollection();

    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", this.latencyPlotData);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(261, 157));
    this.latencyOverTimePanel.setLayout(new BorderLayout());
    this.latencyOverTimePanel.add(chartPanel, BorderLayout.CENTER);

}