Scroll Chart : Chart « Advanced Graphics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Advanced Graphics » ChartScreenshots 
Scroll Chart
Scroll Chart

import java.awt.*;
import java.applet.*;
import java.net.URL;
import java.util.*;
import graph.*;
/*************************************************************************
**
**    Applet example2a
**                                              Version 1.0   August 1996
**
**************************************************************************
**    Copyright (C) 1996 Leigh Brookshaw
**
**    This program is free software; you can redistribute it and/or modify
**    it under the terms of the GNU General Public License as published by
**    the Free Software Foundation; either version 2 of the License, or
**    (at your option) any later version.
**
**    This program is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**    GNU General Public License for more details.
**
**    You should have received a copy of the GNU General Public License
**    along with this program; if not, write to the Free Software
**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**************************************************************************
**
**    This is a simple applet that creates a Scroll Chart using the 
**    Graph2D class library and double buffering
**
*************************************************************************/

public class example2a extends Applet implements Runnable {

      Graph2D graph;
      Label title;
      DataSet data1 = new DataSet();

      Axis    yaxis_right;

      Image    osi = null;
      Graphics osg = null;
      int iwidth  = 0;
      int iheight = 0;

      Thread runner = null;
      Random random = new Random();
      int count = 0;



/*
**    In milliseconds how often do we want to add a new data point.
*/
      int period      = 500;
/*
**    Maximum number of points to display before scrolling the data
*/
      int maximum        = 25;
      URL markersURL;
/*
**    Initialize the applet. The Parameters passed are the title of the plot
**    the marker file to use and the update period in milliseconds
*/
      public void init() {
        int i;
        int j;

/*
**      Get the passed parameters
*/
        String st       = "TITLE";
        String mfile    = "marker.txt";
        period   = 10;
/*
**      Create the Graph instance and modify the default behaviour
*/
        graph = new Graph2D();
        graph.zerocolor = new Color(0,255,0);
        graph.borderTop    = 50;
        graph.borderBottom = 50;
        graph.setDataBackground(Color.black);
/*
**      Create the Title
*/
        title = new Label(st, Label.CENTER);
        title.setFont(new Font("TimesRoman",Font.PLAIN,25));

        setLayoutnew BorderLayout() );
        add("North",  title);
        add("Center", graph);
/*
**      Load a file containing Marker definitions
*/
        try {
           markersURL = this.getClass().getResource(mfile);
           graph.setMarkers(new Markers(markersURL));
        catch(Exception e) {
           System.out.println("Failed to create Marker URL!");
        }
 

/*
**      Modify the default Data behaviour
*/
        data1.linecolor   = new Color(255,0,0);
        data1.marker      = 1;
        data1.markercolor = new Color(100,100,255);
/*
**      Setup the Axis. Attach it to the Graph2D instance, and attach the data
**      to it.
*/
        yaxis_right = graph.createAxis(Axis.RIGHT);
        yaxis_right.attachDataSet(data1);
        yaxis_right.setLabelFont(new Font("Helvetica",Font.PLAIN,20));

        graph.attachDataSet(data1);


      }

      public void start() {
  if(runner == null) {
          runner = new Thread(this);
          runner.start();
        }
      }


      public void stop() {
  if(runner != null) {
          runner.stop();
          runner = null;
        }
      }




        public void run() {
              int i =0;
              double data[] new double[2];
              Graphics g;

              while(true) {


                   count++;

                   if(count >= maximumdata1.delete(0,0);

                   data[1(2.0*random.nextDouble()-1.0)*50.0;
                   data[0= count;

                   try {
                        data1.append(data,1);
          }
                   catch (Exception e) {
                        System.out.println("Error appending Data!");
                   }

                   data1.yaxis.maximum =  50.0;
                   data1.yaxis.minimum = -50.0;

                   
                   g = graph.getGraphics();
       ifosi == null || iwidth != graph.size().width
                                   || iheight != graph.size().height  ) {
                       iwidth = graph.size().width;
                       iheight = graph.size().height;
                       osi = graph.createImage(iwidth,iheight);
                       osg = osi.getGraphics();
                   }

                   osg.setColor(this.getBackground());
                   osg.fillRect(0,0,iwidth,iheight);
                   osg.setColor(g.getColor());

                   osg.clipRect(0,0,iwidth,iheight);


                   graph.update(osg);

                   g.drawImage(osi,0,0,graph);



                   try {  Thread.sleep(period)}
                   catch(Exception e) { }

       }

  }
      public static void main(String[] a){
         javax.swing.JFrame f = new javax.swing.JFrame();
         Applet app = new example2();
         app.init();
         
         f.getContentPane().add (app);

         f.pack();
         f.setSize (new Dimension (500500));
         f.setVisible(true);
      }


}



           
       
Graph-Scroll-Chart.zip( 198 k)
Related examples in the same category
1. Chart based on Graph libraryChart based on Graph library
2. Animation Line ChartAnimation Line Chart
3. Pie ChartPie Chart
4. A rudimentary chart libraryA rudimentary chart library
5. A rudimentory bar chart classA rudimentory bar chart class
ww_w__.__j___av__a_2s___.___c_om_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.