2.X了JavaFx:如何画次要网格线(JavaFx 2.x: How to draw minor

2019-10-20 17:45发布

我无法得出次要网格线,可以在JavaFX 2.2这样做呢? 在我的情况下,电网和图移动,所以我不能用静态图像,生成较小的网格(实时图所示,这个例子在这里 )。

目前我看到这个

什么我正在寻找一个例子。

Answer 1:

正如@colti和模块逻辑的一点点建议我想出了这个解决方案

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;

public class Axis extends Application
{

    public static void main(final String[] args)
    {
        launch(args);
    }

    @Override
    public void start(final Stage stage) throws Exception
    {
        final NumberAxis x = new NumberAxis();
        final NumberAxis y = new NumberAxis();
        x.setAutoRanging(false);
        y.setAutoRanging(false);

        final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(x, y);
        lineChart.setPrefSize(900, 900);
        lineChart.setLegendVisible(false);
        lineChart.setCreateSymbols(false);
        lineChart.setAlternativeColumnFillVisible(false);
        lineChart.setAlternativeRowFillVisible(false);

        final XYChart.Series seriesX = new XYChart.Series();

        for (int i = 1; i < 100; i++) {
            if ((i % 2) != 0) {
                seriesX.getData().add(new XYChart.Data(i, 0));
                seriesX.getData().add(new XYChart.Data(i, 100));
            }
            else {
                seriesX.getData().add(new XYChart.Data(i, 100));
                seriesX.getData().add(new XYChart.Data(i, 0));
            }

        }

        final XYChart.Series seriesY = new XYChart.Series();

        for (int i = 1; i < 100; i++) {
            if ((i % 2) != 0) {
                seriesY.getData().add(new XYChart.Data(0, i));
                seriesY.getData().add(new XYChart.Data(100, i));
            }
            else {
                seriesY.getData().add(new XYChart.Data(100, i));
                seriesY.getData().add(new XYChart.Data(0, i));
            }

        }

        lineChart.getData().add(seriesX);
        lineChart.getData().add(seriesY);
        lineChart.getStylesheets().add("site.css");
        final Scene scene = new Scene(lineChart);
        stage.setScene(scene);
        stage.show();
    }
}

CSS

.chart-series-line{    
-fx-stroke-width: 1px;
-fx-stroke:#eedede;
-fx-effect: null;
}
.chart-vertical-grid-lines {
    -fx-stroke: #cccccc;
}
.chart-horizontal-grid-lines {
    -fx-stroke: #cccccc;
}


文章来源: JavaFx 2.x: How to draw minor grid lines