用JFreeChart实现仪表盘

JFreeChart是一个报表框架,可以实现各种各样的图表,例如:饼形图,柱形图,折线图,区域图,时序图,组合图,仪表盘等等

在这里我只实现几种不同的仪表盘

1,时钟


 import java.awt.*;
 import javax.swing.*;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import org.jfree.chart.ChartPanel;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.plot.dial.*;
 import org.jfree.data.general.DefaultValueDataset;
 import org.jfree.ui.GradientPaintTransformType;
 import org.jfree.ui.StandardGradientPaintTransformer;
 /**
  * 用JfreeChart实现时钟
  * @author Administrator
  *
  */
 @SuppressWarnings("serial")
 public class DialDemo4 extends JFrame {
     static class DemoPanel extends JPanel implements ChangeListener{
         public void stateChanged(ChangeEvent changeevent){
             hoursDataset.setValue(new Integer(slider1.getValue()));
             dataset2.setValue(new Integer(slider2.getValue()));
         }
 
         DefaultValueDataset hoursDataset;
         DefaultValueDataset dataset2;
         JSlider slider1;
         JSlider slider2;
 
         public DemoPanel(){
             super(new BorderLayout());
             hoursDataset = new DefaultValueDataset(6D);
             dataset2 = new DefaultValueDataset(15D);
             DialPlot dialplot = new DialPlot();
             dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
             dialplot.setDataset(0, hoursDataset);
             dialplot.setDataset(1, dataset2);
              
             StandardDialFrame standarddialframe = new StandardDialFrame();
             standarddialframe.setBackgroundPaint(Color.lightGray);
             standarddialframe.setForegroundPaint(Color.darkGray);
             dialplot.setDialFrame(standarddialframe);
              
             DialBackground dialbackground = new DialBackground(Color.white);
             dialbackground.setGradientPaintTransformer(
                     new StandardGradientPaintTransformer(
                             GradientPaintTransformType.VERTICAL));
             dialplot.setBackground(dialbackground);
             
             StandardDialScale standarddialscale =  
                 new StandardDialScale(0.0D, 12D, 90D, -360D, 10D, 4);
             standarddialscale.setFirstTickLabelVisible(false); //刻度盘刻度为隐藏
             standarddialscale.setMajorTickIncrement(1.0D);
             standarddialscale.setTickRadius(0.88D);
             standarddialscale.setTickLabelOffset(0.14999999999999999D);
             standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14));
             dialplot.addScale(0, standarddialscale);
              
             StandardDialScale standarddialscale1 =  
                 new StandardDialScale(0.0D, 60D, 90D, -360D, 10D, 4);
             standarddialscale1.setVisible(false);
             standarddialscale1.setMajorTickIncrement(5D);
             standarddialscale1.setTickRadius(0.68000000000000005D);
             standarddialscale1.setTickLabelOffset(0.14999999999999999D);
             standarddialscale1.setTickLabelFont(new Font("Dialog", 0, 14));
             dialplot.addScale(1, standarddialscale1);
              
             org.jfree.chart.plot.dial.DialPointer.Pointer pointer =  
                 new org.jfree.chart.plot.dial.DialPointer.Pointer(0);
             pointer.setRadius(0.55000000000000004D);
             dialplot.addLayer(pointer);
             dialplot.mapDatasetToScale(1,
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值