Simplest "Hello Word" example chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Maxwell987
Posts: 3
Joined: Sun Jun 17, 2018 1:49 pm
antibot: No, of course not.

Simplest "Hello Word" example chart

Post by Maxwell987 » Sun Jun 17, 2018 5:13 pm

Could someone post a simple "Hello World" example chart?
As simple and small as possible!

Only to test if it works. So far, no code with jfreeChart has worked for me in Eclipse.
If possible under 50 lines.

Thank you!

Maxwell987
Posts: 3
Joined: Sun Jun 17, 2018 1:49 pm
antibot: No, of course not.

Re: Simplest "Hello Word" example chart

Post by Maxwell987 » Sun Jun 17, 2018 10:18 pm

Ok, thanks a lot, it's even easier without JFreeChart:


import java.awt.Graphics;
import java.util.ArrayList;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class Chart
{

public static void main(String [] args)
{
JFrame myframe = new JFrame();
myframe.setSize(1500,1000);
myframe.setLocation(100, 100);
myframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Zufall z = new Zufall();
myframe.getContentPane().add(z);
myframe.setVisible(true);


for(int i=0; i<800; i++)
{
Zufall.liste.add(((int) (Math.random()*30)-15));
z.repaint();
try {Thread.sleep(20);}
catch (InterruptedException e) {e.printStackTrace();}
}
}
}


class Zufall extends JComponent
{
public static ArrayList<Integer> liste = new ArrayList<Integer>();

@Override
protected void paintComponent(Graphics g)
{
int oldx = 0;
int oldy = 500;
for(int wert : liste)
{
g.drawLine(oldx, oldy, oldx+4, oldy+wert);
oldy = oldy+wert;
oldx += 4;
}
}
}

Locked