tests.Graph.java Source code

Java tutorial

Introduction

Here is the source code for tests.Graph.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tests;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author stjohn
 */
public class Graph extends javax.swing.JInternalFrame {

    private static JFreeChart objChart;

    public static JFreeChart getObjChart() {
        return objChart;
    }

    public static void setObjChart(JFreeChart objChart) {
        Graph.objChart = objChart;
    }

    /**
     * Creates new form Graph
     */
    public Graph() {
        initComponents();
        DefaultPieDataset objDataset = new DefaultPieDataset();
        objDataset.setValue("Apple", 29);
        objDataset.setValue("HTC", 15);
        objDataset.setValue("Samsung", 24);
        objDataset.setValue("LG", 7);
        objDataset.setValue("Motorola", 10);

        objChart = ChartFactory.createPieChart("Demo Pie Chart", //Chart title
                objDataset, //Chart Data 
                true, // include legend?
                true, // include tooltips?
                false // include URLs?
        );

        ChartPanel frame = new ChartPanel(objChart);
        this.setContentPane(frame);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}