本文介绍了JavaFx 2.x:如何绘制小网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法绘制较小的网格线,在JavaFx 2.2中可以这样做吗?在我的情况下,网格和图形会移动,因此我无法使用静态图像生成次要网格(实时图形如本例所示)。
I'm unable to draw minor grid lines, it is possible to do so in JavaFx 2.2? In my case the grid and the graph moves so I cannot use a static image to generate the minor grid (live graph as shown in this example here).
目前我看到这个
Currently I see this
我正在寻找的一个例子。
an example of what I'm looking for.
推荐答案
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:如何绘制小网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!