Ikuti Langkah-Langkah Dibawah ini Untuk Membuat Coulumn Chart Menggunakan Java NetBeans :
1. Buatlah project baru di NetBeans, Pilih File > New Project
2. Pilih kategori di Java NetBeans, Pilih Java dan klik project Java Aplication
3. Klik Tombol Next
4. Setelah melakukan Langkah ke 3 buatlah project dengan nama "CoulumnChart" lalu klik Finish
5. Lalu copy script dibawah ini dan masukan ke project yang telah kalian buat tadi
import
java.awt.*;
import
java.awt.event.WindowAdapter;
import
java.awt.event.WindowEvent;
import
java.awt.geom.*;
import
javax.swing.*;
/**
*
* @author Asus
*/
public
class ColumnChart extends JPanel{
public ColumnChart() {
this.setPreferredSize(new Dimension(450,
340));
this.setBackground(Color.WHITE);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO);
gp.moveTo(30, 50);
gp.lineTo(370,50);
gp.moveTo(30,50);
gp.lineTo(30, 290);
gp.moveTo(30,290);
gp.lineTo(370, 290);
gp.moveTo(30,90);
gp.lineTo(370, 90);
gp.moveTo(30, 130);
gp.lineTo(370, 130);
gp.moveTo(30, 170);
gp.lineTo(370, 170);
gp.moveTo(30, 210);
gp.lineTo(370, 210);
gp.moveTo(30, 250);
gp.lineTo(370, 250);
gp.closePath();
g2.draw(gp);
g2.drawString("120",7,50);
//g2.drawString("110",5,70);
g2.drawString("100",7,90);
//g2.drawString("90",13,110);
g2.drawString("80",13,130);
//g2.drawString("70",13,150);
g2.drawString("60",13,170);
//g2.drawString("50",13,190);
g2.drawString("40",13,210);
//g2.drawString("30",13,230);
g2.drawString("20",13,250);
//g2.drawString("10", 13,
270);
g2.drawString("0",20,290);
g2.drawString("N01",40,310);
g2.drawString("N02",75,310);
g2.drawString("N03",110,310);
g2.drawString("N04",145,310);
g2.drawString("N05",180,310);
g2.drawString("N06",215,310);
g2.drawString("N07",250,310);
g2.drawString("N08",285,310);
g2.drawString("N09",320,310);
g2.drawString("N10",355,310);
Shape kotak1 = new
Rectangle2D.Double(45,230,10,60); //30
Shape kotak2 = new
Rectangle2D.Double(80,192,10,98); //51
Shape kotak3 = new
Rectangle2D.Double(115,90,10,200); //100
Shape kotak4 = new
Rectangle2D.Double(150,130,10,160); //80
Shape kotak5 = new
Rectangle2D.Double(185,122,10,168); //84
Shape kotak6 = new Rectangle2D.Double(220,94,10,196);
//98
Shape kotak7 = new
Rectangle2D.Double(255,144,10,146); // 73
Shape kotak8 = new
Rectangle2D.Double(290,72,10,218); // 109
Shape kotak9 = new
Rectangle2D.Double(325,218,10,72); //36
Shape kotak10 = new
Rectangle2D.Double(360,218,10,72); //36
g2.setColor(Color.BLUE);
g2.fill(kotak1);
g2.fill(kotak2);
g2.fill(kotak3);
g2.fill(kotak4);
g2.fill(kotak5);
g2.fill(kotak6);
g2.fill(kotak7);
g2.fill(kotak8);
g2.fill(kotak9);
g2.fill(kotak10);
}
/**
*
* @author Asus
*/
public static void main(String[] args) {
// TODO code application logic here
JFrame frame = new JFrame("Column
Charts");
frame.setSize(600,800);
frame.addWindowListener(new
WindowAdapter()
{
@Override
public void
windowClosing(WindowEvent e)
{ System.exit(0); }
});
//tambahkan panel
ColumnChart canvas = new ColumnChart();
frame.getContentPane().add(canvas);
frame.pack();
frame.setVisible(true);
}
}
Hasil :
SELAMAT MENCOBA!
No comments:
Post a Comment