Charts JavaFX图表水平列表

Charts JavaFX图表水平列表,charts,scroll,javafx,Charts,Scroll,Javafx,我正在开发一个软件,用于比较不同数量的数据,我想用图表以水平方式显示它们。 对我来说重要的是在一边只显示3个图表。如果有超过3个图表,用户应滚动至其他图表 它看起来不像那张图片,我太懒了,不喜欢css。其想法是将所有图表放在滚动窗格内的网格窗格中。绑定图表,使宽度正好为选项卡窗格宽度的1/3 我使用FXML,因为它更容易制作场景 FXMLDocument.fxml <?xml version="1.0" encoding="UTF-8"?> <?import java.lan

我正在开发一个软件,用于比较不同数量的数据,我想用图表以水平方式显示它们。 对我来说重要的是在一边只显示3个图表。如果有超过3个图表,用户应滚动至其他图表


它看起来不像那张图片,我太懒了,不喜欢css。其想法是将所有图表放在滚动窗格内的网格窗格中。绑定图表,使宽度正好为选项卡窗格宽度的1/3

我使用FXML,因为它更容易制作场景

FXMLDocument.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<TabPane fx:id="tabPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="horizcharts.FXMLDocumentController">
  <tabs>
    <Tab text="Main View">
      <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
               <children>
                  <Button layoutX="181.0" layoutY="112.0" mnemonicParsing="false" onAction="#addChart" text="Add Chart" />
               </children></AnchorPane>
      </content>
    </Tab>
    <Tab text="Compare">
         <content>
            <ScrollPane maxWidth="1.7976931348623157E308">
               <content>
                  <GridPane fx:id="grid" gridLinesVisible="true">
                  </GridPane>
               </content>
            </ScrollPane>
         </content>
    </Tab>
  </tabs>
</TabPane>

你的问题在哪里?很好的照片。这让我想试着做一个。非常感谢!这正是我要找的!
package horizcharts;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.control.Label;
import javafx.scene.control.TabPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;


public class FXMLDocumentController implements Initializable {

    @FXML GridPane grid;
    @FXML TabPane tabPane;
    private int numCharts = 0;

    @FXML private void addChart(ActionEvent event) {
        VBox vb = randChart(numCharts);
        GridPane.setConstraints(vb, numCharts++,0);
        grid.getChildren().add(vb);
    }

    private VBox randChart(int num){
        CategoryAxis xAxis = new CategoryAxis();
        NumberAxis yAxis = new NumberAxis();
        BarChart<String, Number> bc = new BarChart(xAxis, yAxis);
        BarChart.Series<String, Number> series = new BarChart.Series<>();
        series.setName("Bar Chart "+num);
        bc.getData().add(series);
        for (int i = 0; i<5; i++){
            series.getData().add(new BarChart.Data("cat "+i, Math.random()*10*i));
        }
        bc.prefWidthProperty().bind(tabPane.widthProperty().subtract(6).divide(3));
        bc.prefHeightProperty().bind(tabPane.heightProperty().subtract(180));//guess heights
        VBox vb = new VBox(5,new Label("Version "+num), bc, new Label("precision"), new Label("recall"));
        return vb;
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    }    

}
package horizcharts;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class HorizCharts extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) { launch(args); }
}