我正在尝试实现一个支持绘制次要网格线的新图表。之前我尝试通过绘制线JavaFx 2.x: How to draw minor grid lines来实现它。我想去绘制Path的原生路线,而不是绘制线条。
我是JavaFx的新手,我们将不胜感激任何帮助/指导。当前的代码只专注于绘制次要的水平网格线。
public class CTChart extends LineChart
{
private final Path horizontalMinorGridLines = new Path();
public CTChart(final NumberAxis xAxis, final NumberAxis yAxis)
{
super(xAxis, yAxis);
this.setAnimated(false);
this.setCreateSymbols(false);
this.setAlternativeRowFillVisible(false);
this.setLegendVisible(false);
this.setHorizontalGridLinesVisible(true);
this.setVerticalGridLinesVisible(true);
getPlotChildren().add(horizontalMinorGridLines);
horizontalMinorGridLines.getStyleClass().setAll("chart-horizontal-minor-grid-lines");
int lowerBound = (int) yAxis.getLowerBound();
int upperBound = (int) yAxis.getUpperBound();
int tickUnit = (int) yAxis.getTickUnit();
int minorTickCount = yAxis.getMinorTickCount();
int minorTickUnit = tickUnit / minorTickCount;
horizontalMinorGridLines.getElements().clear();
for (int i = lowerBound; i < upperBound; i = i + minorTickUnit) {
ObservableList<TickMark<Number>> tickMarks = yAxis.getTickMarks();
for (TickMark<Number> tickMark : tickMarks) {
tickMark.getPosition();
// horizontalMinorGridLines.getElements().add(new MoveTo(zero, tickMark.getPosition()));
// horizontalMinorGridLines.getElements().add(new LineTo(zero + xAxis.getWidth(), tickMark.getPosition()));
}
}
}
}
我无法弄明白的事情
答案 0 :(得分:0)
yourObject.setOnMouseMoved(event - &gt; { double x = event.getX(); double y = event.getY(); }
Example。在CSS中使用它:
.chart-alternative-row-fill { -fx-fill:透明; -fx-stroke:透明; -fx-stroke-width:0; }
LineChart
的属性必须在构造函数中。添加系列不必在构造函数中。