码迷,mamicode.com
首页 > 编程语言 > 详细

基于javaFX的动态线性表创建

时间:2015-09-08 11:59:13      阅读:520      评论:0      收藏:0      [点我收藏+]

标签:

javaFX中文资料较少,不少网友由于这个原因学习缓慢,在这里我发表我的一些学习成果,供大家讨论学习。基于javaFX的动态线性表创建

下面来看一看几个效果图:

技术分享

技术分享

接下来来看看代码:

void check3_controller_show() {
 
    xAxis = new NumberAxis(0, 60, 5);
 
    final NumberAxis yAxis = new NumberAxis(160, 300, 10);
    final NumberAxis yAxis1 = new NumberAxis(160, 300, 10);
    yAxis1.setSide(Side.RIGHT);
    final LineChart<Number, Number> lc = new LineChart<Number, Number>(
            xAxis, yAxis);
    lc.setCreateSymbols(false);
    lc.setAnimated(false);
    lc.setLegendVisible(false);
    lc.setBlendMode(BlendMode.GREEN);
    lc.setTitle("U / T图");
 
    xAxis.setLabel("Time / S");
 
    xAxis.setForceZeroInRange(false);
 
    yAxis.setLabel("U /  V");
 
    xAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(xAxis, null,
            "s"));
 
    // add starting data
 
    lineChart_U = new XYChart.Series<Number, Number>();
 
     lineChart_U.getData().add(
            new XYChart.Data<Number, Number>(timeInHours, prevY));
 
    for (double m = 0; m < (60); m++) {
 
        nextTime();
 
        plotTime();
 
    }
    // create timeline to add new data every 60th of second
 
    animation = new Timeline();
 
    animation.getKeyFrames().add(
            new KeyFrame(Duration.millis(1000 / 100),
                    new EventHandler<ActionEvent>() {
 
                        @Override
                        public void handle(ActionEvent actionEvent) {
 
                            // 6 minutes data per frame
 
                            for (int count = 0; count < 6; count++) {
 
                                nextTime();
 
                                plotTime();
 
                            }
 
                        }
 
                    }));
 
    animation.setCycleCount(Animation.INDEFINITE);
    animation.play();
    lc.getData().add(lineChart_U);
 
     
    lc.setPrefSize(1000, 550);
    AnchorPane page = new AnchorPane(lc);
    page.setPrefSize(1000, 550);
    rootLayout.setCenter(page);
    stage.sizeToScene();
    stage.show();
}
private void plotTime() {
    if ((timeInHours % 1) == 0) {
        prevY=Math.random()*40+200;
        lineChart_U.getData().add(
                new XYChart.Data<Number, Number>(timeInHours, prevY));
        if (timeInHours > 60)
            lineChart_U.getData().remove(0);
        if (timeInHours > 59) {
            xAxis.setLowerBound(xAxis.getLowerBound() + 1);
            xAxis.setUpperBound(xAxis.getUpperBound() + 1);
        }
    }
}
 
private void nextTime() {
    if (minutes == 59) {
        hours++;
        minutes = 0;
    } else {
        minutes++;
    }
    timeInHours = hours + ((1d / 60d) * minutes);
}

基于javaFX的动态线性表创建

标签:

原文地址:http://www.cnblogs.com/0x1E04/p/4790887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!