JFreeChart 보고서 구현 계기판

import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Point;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.dial.DialBackground;
import org.jfree.chart.plot.dial.DialCap;
import org.jfree.chart.plot.dial.DialPlot;
import org.jfree.chart.plot.dial.DialTextAnnotation;
import org.jfree.chart.plot.dial.DialValueIndicator;
import org.jfree.chart.plot.dial.StandardDialFrame;
import org.jfree.chart.plot.dial.StandardDialScale;
import org.jfree.chart.plot.dial.DialPointer.Pin;
import org.jfree.chart.plot.dial.DialPointer.Pointer;
import org.jfree.data.general.DefaultValueDataset;
import org.jfree.ui.GradientPaintTransformType;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.StandardGradientPaintTransformer;

/**
 *      
 * 
 * @author Administrator
 * 
 */
public class DialDemo3 {
	public static void main(String[] args) {
		// 1,          DefaultValueDataset
		DefaultValueDataset dataset = new DefaultValueDataset();
		//          , :         
		dataset.setValue(10D);
		DefaultValueDataset dataset2 = new DefaultValueDataset();
		dataset2.setValue(20D);
		/**
		 *         
		 * 
		 * A. setDataSet(int index, DataSet dataSet);
		 *            ,               ,                    。                   。
		 */
		DialPlot dialplot = new DialPlot();
		dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
		dialplot.setDataset(0, dataset);
		dialplot.setDataset(1, dataset2);
		// System.out.println("dataset count:"+dialplot.getDatasetCount());
		/**
		 *            B. setDailFrame(DailFrame dailFrame);
		 *            ,             。
		 */
		StandardDialFrame dialFrame = new StandardDialFrame();
        dialFrame.setBackgroundPaint(Color.lightGray);
        dialFrame.setForegroundPaint(Color.darkGray);
		dialplot.setDialFrame(dialFrame);
		/**
		 *            C. setBackground(Color color);
		 *        ,    Java               。
		 */
		GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(
				255, 255, 255), new Point(), new Color(170, 170, 220));
		DialBackground dialbackground = new DialBackground(gradientpaint);
		dialbackground
				.setGradientPaintTransformer(new StandardGradientPaintTransformer(
						GradientPaintTransformType.VERTICAL));
		dialplot.setBackground(dialbackground);
		
		//               
		DialTextAnnotation dialtextannotation = new DialTextAnnotation("km/h");
		dialtextannotation.setFont(new Font("Dialog", 1, 14));
		dialtextannotation.setRadius(0.69999999999999996D);
		dialplot.addLayer(dialtextannotation);
		
		/**
		 *        ,       ,        
		 * DialValueIndicator dialvalueindicator = new DialValueIndicator(0);
		 * dialplot.addLayer(dialvalueindicator);
		 */
        DialValueIndicator dvi = new DialValueIndicator(0);
        dvi.setFont(new Font("Dialog", Font.PLAIN, 10));
        dvi.setOutlinePaint(Color.darkGray);
        dvi.setRadius(0.60);
        dvi.setAngle(-103.0);
        dialplot.addLayer(dvi);
        
        DialValueIndicator dvi2 = new DialValueIndicator(1);
        dvi2.setFont(new Font("Dialog", Font.PLAIN, 10));
        dvi2.setOutlinePaint(Color.red);
        dvi2.setRadius(0.60);
        dvi2.setAngle(-77.0);
        dialplot.addLayer(dvi2);
		//          (0.75),       
		/**
		 * F. addScale(int index, DailScale dailScale);
		 *           ,index                   , DailScale        ,           。
		 * 
		 * StandardDialScale(double lowerBound, double upperBound, double
		 * startAngle, double extent, double majorTickIncrement, int
		 * minorTickCount) new StandardDialScale(-40D, 60D, -120D, -300D,30D);
		 */
		//   pointer
		StandardDialScale dialScale1 = new StandardDialScale();
		dialScale1.setLowerBound(-40D); //       
		dialScale1.setUpperBound(60D); //       
		dialScale1.setStartAngle(-120D); //    120,           
		dialScale1.setExtent(-300D); //    300,           
		dialScale1.setTickRadius(0.88D); //    ,          
		dialScale1.setTickLabelOffset(0.14999999999999999D); //    ,        0
																// .14999999999999999D
		dialScale1.setTickLabelFont(new Font("Dialog", 0, 14)); //        
		dialplot.addScale(0, dialScale1);
		//   pin
		StandardDialScale dialScale2 = new StandardDialScale();
		dialScale2.setLowerBound(0D);
		dialScale2.setUpperBound(100D);
		dialScale2.setStartAngle(-120D);
		dialScale2.setExtent(-300D);
		dialScale2.setTickRadius(0.52D);
		dialScale2.setTickLabelOffset(0.1D);
		dialScale2.setTickLabelFont(new Font("Dialog", 0, 10));  //         
		//dialScale2.setTickLabelPaint(new Color(255,0,0));  //         
		dialScale2.setMinorTickPaint(new Color(255,0,0));  //           red
		dialScale2.setMajorTickPaint(new Color(255,0,0));  //           red
		dialplot.addScale(1, dialScale2);
		/**
		 *      G. addPointer(DailPointer dailPointer);
		 *              ,JFreeChart            ,
		 *           ,     DailPoint          
		 */
		//    
		Pointer pointer = new Pointer(0); //    
		dialplot.addPointer(pointer); // addLayer(pointer);
		dialplot.mapDatasetToScale(0, 0);   //Scale Dataset  
		//    
		Pin pin = new Pin(1);
		pin.setPaint(new GradientPaint(new Point(), new Color(255, 0, 0),
				new Point(), new Color(170, 170, 220)));   //      
		pin.setRadius(0.50);   //      ,       
		dialplot.addPointer(pin);	
		dialplot.mapDatasetToScale(1, 1);   //Scale Dataset  
		/**
		 *    DialCap H. setCap(DailCap dailCap); 1,            。 2,            
		 */
		DialCap dialcap = new DialCap();
		dialcap.setRadius(0.0700000000000001D);// 0.10000000000000001D
		dialplot.setCap(dialcap);
		//   chart  
		JFreeChart jfreechart = new JFreeChart(dialplot);
		//     
		jfreechart.setTitle("   ");
		ChartFrame frame = new ChartFrame("   ", jfreechart,
				true);
		frame.pack();
		//     
		RefineryUtilities.centerFrameOnScreen(frame);
		frame.setVisible(true);
	}
}

좋은 웹페이지 즐겨찾기