Package demo

Source Code of demo.MainLayout

package demo;

import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.tabbedui.VerticalLayout;

import java.awt.Color;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

@SuppressWarnings({ "serial", "unused" })
public class MainLayout extends JFrame {


  public MainLayout() {
    getContentPane().setBackground(new Color(10, 210, 230));
    getContentPane().setForeground(new Color(10, 210, 230));
    DBConnect db=new DBConnect();
    final CategoryDataset dataset = createDataset(db.graphdata());
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(500, 270));
   
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(300, 50, 700, 600);

   
    JMenuBar menuBar = new JMenuBar();
    menuBar.setBounds(0, 0, 800, 21);
//    contentPane.add(menuBar);
   
    JMenu mnFile = new JMenu("File");
    menuBar.add(mnFile);
   
    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        System.exit(0);
      }
    });
    mnFile.add(mntmExit);
   
    JMenu mnOperations = new JMenu("Operations");
    menuBar.add(mnOperations);
   
    JMenuItem mntmAdditems = new JMenuItem("Product Mgmt");
    mntmAdditems.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
       
        ProductFrame prod = new ProductFrame();
        prod.setVisible(true);
      }
    });
    mnOperations.add(mntmAdditems);
   
    JMenuItem mntmCategoryManagm = new JMenuItem("Category Mgmt");
    mntmCategoryManagm.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        CategoryFrame cm = new CategoryFrame();
        cm.setVisible(true);
      }
    });
    mnOperations.add(mntmCategoryManagm);
   
    this.getContentPane().add(menuBar);
    this.getContentPane().add(chartPanel);
        this.getContentPane().setLayout(new VerticalLayout());
    this.setTitle("Dashboard");
//    setVisible(true);
  }
 
  
   private CategoryDataset createDataset(Map<String,List<Count>> data) {
      final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
     for(Entry<String, List<Count>> entry: data.entrySet()){
       for(Count count:entry.getValue()){
          dataset.addValue(count.getCount(), entry.getKey(),count.getMonth() );
       }
     }
       // row keys...
    

       return dataset;
              
   }
  
 
   private JFreeChart createChart(final CategoryDataset dataset) {
      
       // create the chart...
       final JFreeChart chart = ChartFactory.createLineChart(
           "No Of Item Vs Category",       // chart title
           "Month",                    // domain axis label
           "unit of Items",                   // range axis label
           dataset,                   // data
           PlotOrientation.VERTICAL,  // orientation
           true,                      // include legend
           true,                      // tooltips
           false                      // urls
       );

       chart.setBackgroundPaint(Color.white);

       final CategoryPlot plot = (CategoryPlot) chart.getPlot();
       plot.setBackgroundPaint(Color.lightGray);
       plot.setRangeGridlinePaint(Color.white);

       // customise the range axis...
       final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
       rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
       rangeAxis.setAutoRangeIncludesZero(true);

       return chart;
   }
}
TOP

Related Classes of demo.MainLayout

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.