Javafx 2.2:如何实现扩展LineChart的新图表

时间:2014-10-23 15:48:42

标签: java charts javafx javafx-2 linechart

我正在尝试实现一个支持绘制次要网格线的新图表。之前我尝试通过绘制线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()));
        }
    }
}
}

我无法弄明白的事情

  1. 我是朝着正确的方向前进吗?
  2. 如何获取MoveTo和LineTo API的X,Y坐标?
  3. 如何呈现/哪些代码呈现次要网格线?
  4. 一切都在构造函数中吗?

1 个答案:

答案 0 :(得分:0)

  1. yourObject.setOnMouseMoved(event - &gt; {         double x = event.getX();         double y = event.getY(); }

  2. Example。在CSS中使用它:

    .chart-alternative-row-fill {   -fx-fill:透明;   -fx-stroke:透明;   -fx-stroke-width:0; }

  3. 设置LineChart的属性必须在构造函数中。添加系列不必在构造函数中。