JavaFX XYChart.Series - 无法在数据点上设置特定颜色/大小

我在 JavaFX 项目中使用 LineChart 和几个系列。 我有一个 XYChart.Series,我想更改系列中数据点(符号)的大小/颜色。 (我必须使用 LineChart)

由于某种原因,我能够控制线条的宽度和颜色,但我无法控制数据点(符号)的参数。

我添加了一部分有效的代码:线条颜色随我的需要而变化:

   LineChart myChart;
   xAxis = new NumberAxis();
   yAxis = new NumberAxis();
   normalSeries = new XYChart.Series();
   anomalySeries = new XYChart.Series();
   lineseries = new XYChart.Series();
   myChart = new LineChart(xAxis,yAxis);
   myChart.setanimated(false);
   myChart.setLegendVisible(false);

     for(int i=0;i<len;i++){
        normalSeries.getData().add(new XYChart.Data<>(xValues.get(i),yValues.get(i)));
    }
    myChart.getData().add(normalSeries);

   for(int i=0;i<len;i++){
        anomalySeries.getData().add(new XYChart.Data<>(pointsX.get(i),pointsY.get(i)));
    }
    myChart.getData().add(anomalySeries);

    lineseries.getData().add(new XYChart.Data<>(min,line.f(min)));
    lineseries.getData().add(new XYChart.Data<>(max,line.f(max)));
    myChart.getData().add(lineseries);

    Node node =myChart.lookup(".series0.chart-series-line");
    node.setStyle("-fx-stroke: transparent;");

    Node node1 =myChart.lookup(".series1.chart-series-line");
    node1.setStyle("-fx-stroke: transparent;");

    Node node2=myChart.lookup(".series2.chart-series-line");
    node2.setStyle("-fx-stroke: grey;");

我的这部分代码不起作用:点(符号)根本没有改变(甚至一个点都没有):

    Node node3 =myChart.lookup(".series0.chart-line-symbol");
    node3.setStyle("-fx-background-color: black,black; -fx-background-radius: 1px;");
    
    Node node4 =myChart.lookup(".series1.chart-line-symbol");
    node4.setStyle("-fx-background-color: red,red;");

这里有什么问题? 谢谢

zqnboy88 回答:JavaFX XYChart.Series - 无法在数据点上设置特定颜色/大小

我不知道怎么改大小,但我一直在用这个

.default-color0.chart-line-symbol { -fx-background-color: #5697ff,#5697ff55; }

在 css 中更改颜色。

本文链接:https://www.f2er.com/223794.html

大家都在问