Example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer

List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer.

Prototype

public XYLineAndShapeRenderer() 

Source Link

Document

Creates a new renderer with both lines and shapes visible.

Usage

From source file:PowerMethod.power_method.java

public static void main(String[] args) {
    //////////////////////////////////////////////////////
    // Edit vals to contain values for matrix A         //
    // Edit vals2 to contain values for initial vector  //
    //////////////////////////////////////////////////////
    double[][] vals = { { 3, 4 }, { 3, 1 } };
    RealMatrix A = new Array2DRowRealMatrix(vals);
    double[][] vals2 = { { 1 }, { 1 } };
    RealMatrix u = new Array2DRowRealMatrix(vals2);
    power_object a = power_method(A, u, .1, 7);

    List<RealMatrix> matrices = genMatrices();
    List<trace_det> trace_dets = new ArrayList<>();
    double trace;
    double det;//from   w  w w  .ja va  2 s. co  m
    int iterA;
    int iterInverseA;
    for (RealMatrix r : matrices) {
        MatrixMethods m = new MatrixMethods(r);
        RealMatrix inverseR = m.inverseMatrix();
        power_object largestVal = power_method(r, u, .00005, 100);
        power_object smallestVal = power_method(inverseR, u, .00005, 100);
        if (largestVal == null || smallestVal == null) {
            continue;
        }
        trace = m.trace();
        det = m.determinant();
        iterA = largestVal.getNumN();
        iterInverseA = smallestVal.getNumN();
        trace_det td = new trace_det(trace, det, iterA, iterInverseA);
        trace_dets.add(td);
    }
    JFreeChart chart = ChartFactory.createXYLineChart("Trace vs. Determinant for Power Method", "Determinant",
            "Trace", createDataSetA(trace_dets), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.GREEN);
    renderer.setSeriesPaint(3, Color.BLACK);
    renderer.setSeriesPaint(4, Color.YELLOW);
    renderer.setSeriesPaint(5, Color.PINK);
    renderer.setSeriesPaint(6, Color.ORANGE);
    renderer.setSeriesPaint(7, Color.GRAY);
    renderer.setSeriesPaint(8, Color.MAGENTA);
    renderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    renderer.setSeriesPaint(10, Color.DARK_GRAY);
    //renderer.setSeriesStroke( 0 , new BasicStroke( 3.0f ) );
    //renderer.setSeriesStroke( 1 , new BasicStroke( 2.0f ) );
    plot.setRenderer(renderer);
    ChartFrame frame = new ChartFrame("Power Method", chart);
    frame.pack();
    frame.setVisible(true);

    JFreeChart inverseChart = ChartFactory.createXYLineChart("Trace vs. Determinant for Inverse Power Method",
            "Determinant", "Trace", createDataSetAInverse(trace_dets), PlotOrientation.VERTICAL, true, true,
            false);
    ChartPanel inverseChartPanel = new ChartPanel(inverseChart);
    inverseChartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot inversePlot = inverseChart.getXYPlot();
    XYLineAndShapeRenderer inverseRenderer = new XYLineAndShapeRenderer();
    inverseRenderer.setSeriesPaint(0, Color.RED);
    inverseRenderer.setSeriesPaint(1, Color.BLUE);
    inverseRenderer.setSeriesPaint(2, Color.GREEN);
    inverseRenderer.setSeriesPaint(3, Color.BLACK);
    inverseRenderer.setSeriesPaint(4, Color.YELLOW);
    inverseRenderer.setSeriesPaint(5, Color.PINK);
    inverseRenderer.setSeriesPaint(6, Color.ORANGE);
    inverseRenderer.setSeriesPaint(7, Color.GRAY);
    inverseRenderer.setSeriesPaint(8, Color.MAGENTA);
    inverseRenderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    inverseRenderer.setSeriesPaint(10, Color.DARK_GRAY);
    inversePlot.setRenderer(renderer);
    ChartFrame inverseFrame = new ChartFrame("Power Method", inverseChart);
    inverseFrame.pack();
    inverseFrame.setVisible(true);
}

From source file:Graph_with_jframe_and_arduino.java

public static void main(String[] args) {

    // create and configure the window
    JFrame window = new JFrame();
    window.setTitle("Sensor Graph GUI");
    window.setSize(600, 400);//from ww  w  .  j  a va2 s . c o m
    window.setLayout(new BorderLayout());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create a drop-down box and connect button, then place them at the top of the window
    JComboBox<String> portList_combobox = new JComboBox<String>();
    Dimension d = new Dimension(300, 100);
    portList_combobox.setSize(d);
    JButton connectButton = new JButton("Connect");
    JPanel topPanel = new JPanel();
    topPanel.add(portList_combobox);
    topPanel.add(connectButton);
    window.add(topPanel, BorderLayout.NORTH);
    //pause button
    JButton Pause_btn = new JButton("Start");

    // populate the drop-down box
    SerialPort[] portNames;
    portNames = SerialPort.getCommPorts();
    //check for new port available
    Thread thread_port = new Thread() {
        @Override
        public void run() {
            while (true) {
                SerialPort[] sp = SerialPort.getCommPorts();
                if (sp.length > 0) {
                    for (SerialPort sp_name : sp) {
                        int l = portList_combobox.getItemCount(), i;
                        for (i = 0; i < l; i++) {
                            //check port name already exist or not
                            if (sp_name.getSystemPortName().equalsIgnoreCase(portList_combobox.getItemAt(i))) {
                                break;
                            }
                        }
                        if (i == l) {
                            portList_combobox.addItem(sp_name.getSystemPortName());
                        }

                    }

                } else {
                    portList_combobox.removeAllItems();

                }
                portList_combobox.repaint();

            }

        }

    };
    thread_port.start();
    for (SerialPort sp_name : portNames)
        portList_combobox.addItem(sp_name.getSystemPortName());

    //for(int i = 0; i < portNames.length; i++)
    //   portList.addItem(portNames[i].getSystemPortName());

    // create the line graph
    XYSeries series = new XYSeries("line 1");
    XYSeries series2 = new XYSeries("line 2");
    XYSeries series3 = new XYSeries("line 3");
    XYSeries series4 = new XYSeries("line 4");
    for (int i = 0; i < 100; i++) {
        series.add(x, 0);
        series2.add(x, 0);
        series3.add(x, 0);
        series4.add(x, 10);
        x++;
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(series2);
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series3);
    dataset2.addSeries(series4);

    //create jfree chart
    JFreeChart chart = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading",
            dataset);
    JFreeChart chart2 = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading 2",
            dataset2);

    //color render for chart 1
    XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer();
    r1.setSeriesPaint(0, Color.RED);
    r1.setSeriesPaint(1, Color.GREEN);
    r1.setSeriesShapesVisible(0, false);
    r1.setSeriesShapesVisible(1, false);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(0, r1);
    plot.setRenderer(1, r1);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.blue);

    //color render for chart 2
    XYLineAndShapeRenderer r2 = new XYLineAndShapeRenderer();
    r2.setSeriesPaint(0, Color.BLUE);
    r2.setSeriesPaint(1, Color.ORANGE);
    r2.setSeriesShapesVisible(0, false);
    r2.setSeriesShapesVisible(1, false);

    XYPlot plot2 = chart2.getXYPlot();
    plot2.setRenderer(0, r2);
    plot2.setRenderer(1, r2);

    ChartPanel cp = new ChartPanel(chart);
    ChartPanel cp2 = new ChartPanel(chart2);

    //multiple graph container
    JPanel graph_container = new JPanel();
    graph_container.setLayout(new BoxLayout(graph_container, BoxLayout.X_AXIS));
    graph_container.add(cp);
    graph_container.add(cp2);

    //add chart panel in main window
    window.add(graph_container, BorderLayout.CENTER);
    //window.add(cp2, BorderLayout.WEST);

    window.add(Pause_btn, BorderLayout.AFTER_LAST_LINE);
    Pause_btn.setEnabled(false);
    //pause btn action
    Pause_btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Pause_btn.getText().equalsIgnoreCase("Pause")) {

                if (chosenPort.isOpen()) {
                    try {
                        Output.write(0);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Start");
            } else {
                if (chosenPort.isOpen()) {
                    try {
                        Output.write(1);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Pause");
            }
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });

    // configure the connect button and use another thread to listen for data
    connectButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (connectButton.getText().equals("Connect")) {
                // attempt to connect to the serial port
                chosenPort = SerialPort.getCommPort(portList_combobox.getSelectedItem().toString());
                chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                if (chosenPort.openPort()) {
                    Output = chosenPort.getOutputStream();
                    connectButton.setText("Disconnect");
                    Pause_btn.setEnabled(true);
                    portList_combobox.setEnabled(false);
                }

                // create a new thread that listens for incoming text and populates the graph
                Thread thread = new Thread() {
                    @Override
                    public void run() {
                        Scanner scanner = new Scanner(chosenPort.getInputStream());
                        while (scanner.hasNextLine()) {
                            try {
                                String line = scanner.nextLine();
                                int number = Integer.parseInt(line);
                                series.add(x, number);
                                series2.add(x, number / 2);
                                series3.add(x, number / 1.5);
                                series4.add(x, number / 5);

                                if (x > 100) {
                                    series.remove(0);
                                    series2.remove(0);
                                    series3.remove(0);
                                    series4.remove(0);
                                }

                                x++;
                                window.repaint();
                            } catch (Exception e) {
                            }
                        }
                        scanner.close();
                    }
                };
                thread.start();
            } else {
                // disconnect from the serial port
                chosenPort.closePort();
                portList_combobox.setEnabled(true);
                Pause_btn.setEnabled(false);
                connectButton.setText("Connect");

            }
        }
    });

    // show the window
    window.setVisible(true);
}

From source file:org.jfree.chart.demo.XYLineAndShapeRendererDemo1.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setSeriesLinesVisible(0, true);
    xylineandshaperenderer.setSeriesShapesVisible(0, false);
    xylineandshaperenderer.setSeriesLinesVisible(1, false);
    xylineandshaperenderer.setSeriesShapesVisible(1, true);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    xylineandshaperenderer.setDefaultEntityRadius(6);
    xyplot.setRenderer(xylineandshaperenderer);
    return jfreechart;
}

From source file:org.jfree.chart.demo.XYTaskDatasetDemo2.java

private static XYPlot createSubplot1(XYDataset xydataset) {
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseShape(new java.awt.geom.Ellipse2D.Double(-4D, -4D, 8D, 8D));
    xylineandshaperenderer.setAutoPopulateSeriesShape(false);
    NumberAxis numberaxis = new NumberAxis("Y");
    numberaxis.setLowerMargin(0.10000000000000001D);
    numberaxis.setUpperMargin(0.10000000000000001D);
    XYPlot xyplot = new XYPlot(xydataset, new DateAxis("Time"), numberaxis, xylineandshaperenderer);
    return xyplot;
}

From source file:com.moczul.jbacktester.Main.java

private static void showChart(XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart("PKO - PEO", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from ww  w  .ja  va 2s .  com*/

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    XYPlot plot = chart.getXYPlot();
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesShapesVisible(3, false);
    renderer.setSeriesShapesVisible(4, false);
    plot.setRenderer(renderer);

    JFrame frame = new JFrame();
    frame.setContentPane(chartPanel);

    frame.pack();
    frame.setVisible(true);
}

From source file:org.jfree.chart.demo.CompareToPreviousYearDemo.java

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);/*w w w. j av  a2  s . c  om*/
    xyplot.setRangePannable(true);
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:Charts.LineChart.java

@Override
protected JFreeChart createChart(String title, String x, String y) {

    JFreeChart lineChart = this.makeJFreeChart(title, x, y);

    // Custom chart..
    lineChart.setBackgroundPaint(Color.white);

    final XYPlot plot = lineChart.getXYPlot();

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShapesVisible(0, false);
    plot.setRenderer(renderer);//w  ww .j  av  a2 s  .c  o  m

    return lineChart;
}

From source file:democsv.XYLineChart_AWT.java

public XYLineChart_AWT(String applicationTitle, String chartTitle) {
    super(applicationTitle);
    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "Category", "Score", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setRenderer(renderer);/*from  w  ww  .  j  ava  2  s  . c  o  m*/
    setContentPane(chartPanel);
}

From source file:graficarfreechart.GraficarFreeChart.java

public GraficarFreeChart(String applicationTitle, String chartTitle) {
    super(applicationTitle);

    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "Category", "Score", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setRenderer(renderer);// www  .  j  a v  a  2s .c  o  m
    setContentPane(chartPanel);
}

From source file:org.xwiki.chart.internal.plot.XYLineAndShapePlotGenerator.java

@Override
public XYItemRenderer getRenderer() {
    return new XYLineAndShapeRenderer();
}