How to combine scatter chart with line chart to show line of regression? JavaFX

后端 未结 4 733
小蘑菇
小蘑菇 2020-12-06 01:44

I\'ve created a scatter chart with two sets of data; the first set is the actual data (x = year and y = pence) and the second set produces the same points but for the line o

4条回答
  •  离开以前
    2020-12-06 02:18

    I add to Pane the two ScatterChart and i have set Opacity at (0.5) try it.

    I hope I have helped.

    final ScatterChart sc = new
        ScatterChart(xAxis,yAxis);
    final LineChart lc = new
        LineChart(xAxis,yAxis);
    
    XYChart.Series series1 = new XYChart.Series();
    series1.setName("Equities");
    series1.getData().add(new XYChart.Data(4.2, 193.2));
    series1.getData().add(new XYChart.Data(2.8, 33.6));
    
    XYChart.Series series2 = new XYChart.Series();
    series2.setName("Mutual funds");
    series2.getData().add(new XYChart.Data(5.2, 229.2));
    series2.getData().add(new XYChart.Data(2.4, 37.6));
    
    sc.getData().addAll(series1);
    lc.getData().addAll(series2);
    
    Pane pane=new Pane();
    pane.getChildren().add(sc);
    pane.getChildren().add(lc);
    
    lc.setOpacity(0.5);
    
    Scene scene  = new Scene(pane, 500, 400);
    stage.setScene(scene);
    stage.show();
    }
    
    public static void main(String[] args) {
      launch(args);
    }
    

提交回复
热议问题