JFreeChart动态仪表盘的问题
用JFreeChart写了个仪表盘但是是静态的怎么使其指针动起来,在线等,求详细代码public class Dial extends ApplicationFrame {
public Dial(String title) {
super(title);
JPanel chartPanel = createDemoPanel();
chartPanel.setPreferredSize(new Dimension(1200, 400));
setContentPane(chartPanel);
}
public static void main(String[] args) {
Dial demo = new Dial("三个仪表");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
public static JPanel createDemoPanel() {
JPanel panel = new JPanel(new GridLayout(1, 3));
JPanel panel1 = new ChartPanel(createChart("第一个仪表"));
JPanel panel2 = new ChartPanel(createChart("第二个仪表"));
JPanel panel3 = new ChartPanel(createChart("第三个仪表"));
panel.add(panel1);
panel.add(panel2);
panel.add(panel3);
return panel;
}
private static JFreeChart createChart(String title) {
//设置指针数据
DefaultValueDataset dataset = new DefaultValueDataset();
dataset.setValue((int)(Math.random()*60));
DefaultValueDataset dataset2 = new DefaultValueDataset();
dataset2.setValue((int)(Math.random()*100));
//设置表框样式
StandardDialFrame dialFrame = new StandardDialFrame();
dialFrame.setBackgroundPaint(Color.lightGray);
dialFrame.setForegroundPaint(Color.darkGray);
//设置表背景颜色
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));
//设置表中文本样式
DialTextAnnotation dialtextannotation = new DialTextAnnotation("km/h");
dialtextannotation.setFont(new Font("Dialog", 1, 14));
dialtextannotation.setRadius(0.69999999999999996D);
//将指针指向的数值用文本显示出来
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);
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);
//绘制刻度
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
dialScale1.setTickLabelFont(new Font("Dialog", 0, 14)); // 刻度盘刻度字体
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.setMinorTickPaint(new Color(255,0,0)); //设置刻度盘小刻度颜色为red
dialScale2.setMajorTickPaint(new Color(255,0,0)); //设置刻度盘大刻度颜色为red
//绘制指针
Pointer pointer = new Pointer(0); // 内部内
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); //设置指针半径,也就是指针长短
//绘制表盘心
DialCap dialcap = new DialCap();
dialcap.setRadius(0.0700000000000001D);// 0.10000000000000001D
//创建表
DialPlot dialplot = new DialPlot();
dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
dialplot.setDataset(0, dataset);
dialplot.setDataset(1, dataset2);
dialplot.setDialFrame(dialFrame);
dialplot.setBackground(dialbackground);
dialplot.addLayer(dialtextannotation);
dialplot.addLayer(dvi);
dialplot.addLayer(dvi2);
dialplot.addScale(0, dialScale1);
dialplot.addScale(1, dialScale2);
dialplot.addPointer(pointer); // addLayer(pointer);
dialplot.mapDatasetToScale(0, 0); //Scale与Dataset对应
dialplot.addPointer(pin);
dialplot.mapDatasetToScale(1, 1); //Scale与Dataset对应
dialplot.setCap(dialcap);
JFreeChart chart = new JFreeChart(title,
JFreeChart.DEFAULT_TITLE_FONT, dialplot, true);
return chart;
}
} jfreechart java --------------------编程问答-------------------- JFreeChart不太了解,关注一下 --------------------编程问答-------------------- JFreeChart 生成的图表是png或JPEG格式的图片,没有动态的
补充:Java , Java相关