Search in sources :

Example 71 with ChartPanel

use of org.jfree.chart.ChartPanel in project FRC2018 by first95.

the class AdjustedTalonTester method runVoltageTest.

public void runVoltageTest() {
    // Create dataset
    XYDataset dataset = new XYSeriesCollection();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    int seriesNum = 0;
    for (double throttle = -1.0; throttle <= 1.0; throttle += 0.25) {
        // Prime the UUT with normal voltages for a while
        double voltage = 13;
        for (int i = 0; i < AdjustedTalon.NUM_RECENT_SAMPLES; ++i) {
            pdp.setVoltage(13);
            uut.set(ControlMode.PercentOutput, 0.0);
        }
        XYSeries series = new XYSeries("Throttle at " + throttle, false);
        for (; voltage >= 5.0; voltage -= 0.01) {
            pdp.setVoltage(voltage);
            uut.set(ControlMode.PercentOutput, throttle);
            series.add(voltage, lastCommandedThrottle);
        }
        ((XYSeriesCollection) dataset).addSeries(series);
        renderer.setSeriesLinesVisible(seriesNum, true);
        renderer.setSeriesShapesVisible(seriesNum, false);
        seriesNum++;
    }
    // Create chart
    JFreeChart chart = ChartFactory.createScatterPlot("Adjusted throttle vs battery voltage", "voltage", "Adjusted throttle", dataset);
    // Changes background color
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(200, 200, 200));
    plot.setRenderer(renderer);
    // Create Panel
    ChartPanel panel = new ChartPanel(chart);
    setContentPane(panel);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) ChartPanel(org.jfree.chart.ChartPanel) XYPlot(org.jfree.chart.plot.XYPlot) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Color(java.awt.Color) XYDataset(org.jfree.data.xy.XYDataset) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart)

Example 72 with ChartPanel

use of org.jfree.chart.ChartPanel in project ta4j by ta4j.

the class IndicatorsToChart method displayChart.

/**
 * Displays a chart in a frame.
 * @param chart the chart to be displayed
 */
private static void displayChart(JFreeChart chart) {
    // Chart panel
    ChartPanel panel = new ChartPanel(chart);
    panel.setFillZoomRectangle(true);
    panel.setMouseWheelEnabled(true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    // Application frame
    ApplicationFrame frame = new ApplicationFrame("Ta4j example - Indicators to chart");
    frame.setContentPane(panel);
    frame.pack();
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) ApplicationFrame(org.jfree.ui.ApplicationFrame)

Example 73 with ChartPanel

use of org.jfree.chart.ChartPanel in project ta4j by ta4j.

the class BuyAndSellSignalsToChart method displayChart.

/**
 * Displays a chart in a frame.
 * @param chart the chart to be displayed
 */
private static void displayChart(JFreeChart chart) {
    // Chart panel
    ChartPanel panel = new ChartPanel(chart);
    panel.setFillZoomRectangle(true);
    panel.setMouseWheelEnabled(true);
    panel.setPreferredSize(new Dimension(1024, 400));
    // Application frame
    ApplicationFrame frame = new ApplicationFrame("Ta4j example - Buy and sell signals to chart");
    frame.setContentPane(panel);
    frame.pack();
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) ApplicationFrame(org.jfree.ui.ApplicationFrame)

Example 74 with ChartPanel

use of org.jfree.chart.ChartPanel in project Energieverbrauchssimulator by duschdas2.

the class Diagramm method erzeuge2.

public static void erzeuge2(String s) throws IOException {
    JFreeChart xylineChart = ChartFactory.createXYLineChart("Simulierter Haushalt", "Zeit in Minuten", "Verbrauch in Watt", erstelleDataset(s), PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = xylineChart.getXYPlot();
    plot.setBackgroundPaint(Color.black);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    // Erstellt das Frame zum abbilden des Graphen
    ChartFrame frame = new ChartFrame("Diagramm", xylineChart);
    frame.pack();
    frame.setVisible(true);
}
Also used : ChartFrame(org.jfree.chart.ChartFrame) ChartPanel(org.jfree.chart.ChartPanel) XYPlot(org.jfree.chart.plot.XYPlot) JFreeChart(org.jfree.chart.JFreeChart)

Example 75 with ChartPanel

use of org.jfree.chart.ChartPanel in project Stock-Ticker-Project by IsaiahL12.

the class DynamicDataDemo method graph2.

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title.
 */
public JPanel graph2(String title, Vector<Double> avgV, Vector<String> time) {
    final TimeSeries high = new TimeSeries("High");
    final TimeSeries average = new TimeSeries("Price");
    final TimeSeries low = new TimeSeries("Low");
    double hold = 0;
    double hold1 = -1;
    double hold2 = 100000000;
    int spacing = 20;
    for (int i = 0; i < avgV.size(); i++) {
        if (avgV.get(i) != -1 && avgV.get(i) != 0) {
            if (hold1 < avgV.get(i)) {
                hold1 = avgV.get(i);
            }
            if (hold2 > avgV.get(i)) {
                hold2 = avgV.get(i);
            // System.out.println(hold2);
            }
            // Date day = new SimpleDateFormat("HH:MM").parse("9:30");
            try {
                Date date = new SimpleDateFormat("yyyy-MM-dd").parse(time.get(i));
                hold = avgV.get(i);
                average.addOrUpdate(new Day(date), round(hold, 2));
                // average.add( null, round(hold,2));
                high.addOrUpdate(new Day(date), round(hold1, 2));
                low.addOrUpdate(new Day(date), round(hold2, 2));
            // high.add(spacing*i, round(hold1,2));
            // low.add(spacing*i, round(hold2,2));
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection(high);
    dataset.addSeries(low);
    dataset.addSeries(average);
    JFreeChart chart;
    chart = createChart2(dataset, title);
    chart.getPlot().setBackgroundPaint(Color.BLACK);
    ChartPanel chartPanel = new ChartPanel(chart);
    // chartPanel.overlayChanged(event);
    JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    // content.add(button, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(375, 320));
    // this.add(content);
    return content;
/*
        final XYSeries high = new XYSeries("High");
  	  final XYSeries average = new XYSeries("Price");
  	  final XYSeries low = new XYSeries("Low");
  	  double hold = 0;
  	  double hold1 = -1;
  	  double hold2 = 100000000;
  	  int spacing = 20;
  	  
  	 for (int i =0; i< avgV.size(); i++) {
  		   if (avgV.get(i) != -1 && avgV.get(i) != 0) {
  			   if (hold1 < avgV.get(i)) {
  				   hold1 =  avgV.get(i);
  			   }
  		 
  			   if (hold2 > avgV.get(i)) {
  				   hold2 =  avgV.get(i);
  				   //System.out.println(hold2);
  			   }
  			   
  			  
  			   
  		// Date day = new SimpleDateFormat("HH:MM").parse("9:30");
  		 
  			 hold =  avgV.get(i);
  			average.add(spacing*i, round(hold,2));
  			 high.add(spacing*i, round(hold1,2));
  		 low.add(spacing*i, round(hold2,2));
  		  }
  		  
  	  }
  	  
  	  
  	XYSeriesCollection dataset = new XYSeriesCollection(high); 
    	dataset.addSeries(low);
    	dataset.addSeries(average);
    	JFreeChart chart;
    
    	chart = createChart2(dataset, title);
    	chart.getPlot().setBackgroundPaint( Color.BLACK );
      ChartPanel chartPanel = new ChartPanel(chart);
     // chartPanel.overlayChanged(event);
      
      JPanel content = new JPanel(new BorderLayout());
      content.add(chartPanel);
      //content.add(button, BorderLayout.SOUTH);
      chartPanel.setPreferredSize(new java.awt.Dimension(375, 320));
      //setContentPane(content)
      //this.add(content);
      return content;
      */
}
Also used : JPanel(javax.swing.JPanel) TimeSeries(org.jfree.data.time.TimeSeries) ChartPanel(org.jfree.chart.ChartPanel) Date(java.util.Date) JFreeChart(org.jfree.chart.JFreeChart) BorderLayout(java.awt.BorderLayout) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Day(org.jfree.data.time.Day)

Aggregations

ChartPanel (org.jfree.chart.ChartPanel)84 JFreeChart (org.jfree.chart.JFreeChart)50 XYPlot (org.jfree.chart.plot.XYPlot)20 Dimension (java.awt.Dimension)18 JPanel (javax.swing.JPanel)17 Color (java.awt.Color)16 NumberAxis (org.jfree.chart.axis.NumberAxis)16 ChartEntity (org.jfree.chart.entity.ChartEntity)15 XYSeries (org.jfree.data.xy.XYSeries)15 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)15 XYDataset (org.jfree.data.xy.XYDataset)12 BasicStroke (java.awt.BasicStroke)11 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)11 ChartGesture (net.sf.mzmine.chartbasics.gestures.ChartGesture)8 Button (net.sf.mzmine.chartbasics.gestures.ChartGesture.Button)8 Entity (net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity)8 ChartGestureEvent (net.sf.mzmine.chartbasics.gestures.ChartGestureEvent)8 DecimalFormat (java.text.DecimalFormat)7 JButton (javax.swing.JButton)7 JLabel (javax.swing.JLabel)7