Example usage for org.jfree.chart.plot XYPlot getRendererForDataset

List of usage examples for org.jfree.chart.plot XYPlot getRendererForDataset

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getRendererForDataset.

Prototype

public XYItemRenderer getRendererForDataset(XYDataset dataset) 

Source Link

Document

Returns the renderer for the specified dataset (this is either the renderer with the same index as the dataset or, if there isn't a renderer with the same index, the default renderer).

Usage

From source file:LoggerGUI.DataLogger.java

public DataLogger(String title) {
    super(title);
    initialize();//w  ww.ja v  a2s.  c  o  m

    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
    this.datasets = new TimeSeriesCollection[INPUT_COUNT];

    this.lastValue[0] = 100.0;
    this.lastValue[1] = 100.0;
    this.lastValue[2] = 100.0;
    this.lastValue[3] = 100.0;
       
        
        
       
        
    final TimeSeries s0 = new TimeSeries("A0", Millisecond.class);
    final TimeSeries s1 = new TimeSeries("A1", Millisecond.class);
    final TimeSeries s2 = new TimeSeries("A2", Millisecond.class);
    final TimeSeries s3 = new TimeSeries("A3", Millisecond.class);
        
        
        
    this.datasets[0] = new TimeSeriesCollection(s0);
    this.datasets[1] = new TimeSeriesCollection(s1);
    this.datasets[2] = new TimeSeriesCollection(s2);
    this.datasets[3] = new TimeSeriesCollection(s3);
       
        

    final NumberAxis rangeAxis = new NumberAxis("ADC Signal");

    rangeAxis.setAutoRangeIncludesZero(false);
    XYPlot subplot;

        
    XYLineAndShapeRenderer renderer =  new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true,false);
    XYLineAndShapeRenderer renderer3 = new XYLineAndShapeRenderer(true,false);
        
    subplot= new XYPlot(
            new TimeSeriesCollection(), null, rangeAxis, new XYLineAndShapeRenderer(true,false)
    );
       
    plot.add(subplot);
       
        
        
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesPaint(0, Color.red);
    subplot.setDataset(0,datasets[0]);
    subplot.setRenderer(0,renderer);
        
        
    renderer1.setBaseShapesVisible(false);
    renderer1.setSeriesPaint(0, Color.blue);
    subplot.setDataset(1,datasets[1]);
    subplot.setRenderer(1,renderer1);
        
        
    renderer2.setBaseShapesVisible(false);
    renderer2.setSeriesPaint(0, Color.black);
    subplot.setDataset(2,datasets[2]);
    subplot.setRenderer(2,renderer2);
        
    subplot.getRendererForDataset(subplot.getDataset(0)).setSeriesPaint(0, Color.red); 
    subplot.getRendererForDataset(subplot.getDataset(1)).setSeriesPaint(1, Color.blue);
    subplot.getRendererForDataset(subplot.getDataset(2)).setSeriesPaint(2, Color.black);
        
    renderer3.setBaseShapesVisible(false);
    renderer3.setSeriesPaint(0, Color.green);
    subplot.setDataset(3,datasets[3]);
    subplot.setRenderer(3,renderer3);
        
        
        
    final JFreeChart chart = new JFreeChart("Data Logger", plot);
    chart.setBorderPaint(Color.black);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);
        
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    final ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);
    axis.setFixedAutoRange(20000.0);  // 60 seconds

    
    final JPanel content = new JPanel(new BorderLayout());

    final ChartPanel chartPanel = new ChartPanel(chart);
    content.add(chartPanel);

    final JPanel buttonPanel = new JPanel(new FlowLayout());
        
    content.add(buttonPanel, BorderLayout.NORTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(600, 600));
    chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(content);
        
        
}