gpt4 book ai didi

css - 如何在 Javafx 中将 CSS 用于图表栏颜色

转载 作者:太空宇宙 更新时间:2023-11-04 12:08:29 25 4
gpt4 key购买 nike

我创建了一个图表栏,我希望根据值的名称更改栏的颜色。它有两个系列,一个显示应该为绿色的绿色值的数量,另一个显示黄色。我还创建了一个 css 文件,但第一个问题是 css 中 -fx-bar-fill 的获取未知属性错误。另外我不知道创建系列后如何调用合适的颜色?我当时面临这个警告:

Mar 23, 2015 8:50:02 AM com.sun.javafx.css.parser.CSSParser parse
WARNING: CSS Error parsing file:/home/iman/workspace/AddNodeDynamicly /bin/application/chart.css: Expected LBRACE at [1,9]

我在这里创建图表

public class MostComputerizedController {
@FXML
private BarChart<String, Number> barChart;
@FXML
private CategoryAxis orgNameAxis;
@FXML
private NumberAxis yAxis;

private ObservableList<String> orgNames = FXCollections
.observableArrayList();

private DataConstructor dc = new DataConstructor();

@FXML
private void initialize() {

orgNames.addAll(dc.getSortedAssignedOrg().values());
orgNameAxis.setCategories(orgNames);
orgNameAxis.setLabel("Name of Organizations");
orgNameAxis.tickLabelFontProperty().set(Font.font(10));
yAxis.setLabel("Saturation");
orgNameAxis.getStylesheets().add(
getClass().getResource("/application/application.css").toExternalForm());

}

/*
* *
* Sets the organization to show the statistics for.
*
* @param
*/
public void setPersonData() {

XYChart.Series<String, Number> series = new XYChart.Series<>();
XYChart.Series<String, Number> seriesy = new XYChart.Series<>();
series.setName("Green");
seriesy.setName("Yellow");

for (String entryOrg : dc.getSortedAssignedOrg().values()) {
for (List<String> entryfuncType : dc.getFuncTypeOrg().values()) {
if (entryOrg.equals(entryfuncType.get(5))
&& entryfuncType.contains("hasType")) {

int yellow = Collections.frequency(entryfuncType, "yellow");
int green = Collections.frequency(entryfuncType, "Green");
int typeNumber = Collections.frequency(entryfuncType,
"hasType");

series.getData().add(
new XYChart.Data<String, Number>(entryOrg, green));
seriesy.getData().add(
new XYChart.Data<String, Number>(entryOrg, yellow));


}
}

}

barChart.getData().addAll(series,seriesy);
}
}

在 main 中,我将它添加到舞台:

public class Main extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
private Model model = new Model();

@Override
public void start(Stage primaryStage) {

this.primaryStage = primaryStage;
this.primaryStage.setTitle("IT-Saturation");
initRootLayout();
showOverView();

}

private void showOverView() {
try {
FXMLLoader loader = new FXMLLoader();

loader.setLocation(Main.class.getResource("/view/OverView.fxml"));
loader.setController(new OverViewController(model));

AnchorPane overView = (AnchorPane) loader.load();
rootLayout.setCenter(overView);

} catch (IOException e) {
e.printStackTrace();
}
}

private void initRootLayout() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("/view/RootLayout.fxml"));
loader.setController(new RootLayoutController(model));

rootLayout = (BorderPane) loader.load();
// show scene containing the root layout
Scene scene = new Scene(rootLayout);
scene.getStylesheets().add(
getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
RootLayoutController controller = loader.getController();
controller.setMainApp(this);
primaryStage.show();

} catch (IOException e) {

e.printStackTrace();
}

public void showMostComputerizedStatistics() {
try {
// Load the fxml file and create a new stage for the popup.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class
.getResource("/view/MostComputerized.fxml"));
AnchorPane page = (AnchorPane) loader.load();
Stage dialogStage = new Stage();

dialogStage.setTitle("Saturation in Organizations");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
dialogStage.getScene().getStylesheets().add(
getClass().getResource("chart.css").toExternalForm());
MostComputerizedController controller = loader.getController();
controller.setPersonData();
dialogStage.show();

} catch (IOException e) {
e.printStackTrace();
}
}
}

这是css文件:

@CHARSET "UTF-8";

.default-color0.chart-bar {
-fx-bar-fill: green;
}

.default-color1.chart-bar {
-fx-bar-fill: yellow;
}

最佳答案

如果可以通过使用 -fx-background-color 来消除 css 警告

.default-color0.chart-bar { -fx-background-color: rgb(146,208,80); }

关于css - 如何在 Javafx 中将 CSS 用于图表栏颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29205511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com