【发布时间】:2015-04-28 13:37:49
【问题描述】:
我应该怎么做才能改变条形图的颜色。
谁能给我一个线索:
- 如何为折线图设置颜色?
- 如何将 css 类设置为系列?
public class hmw3 extends Application {
@Override public void start(Stage stage) throws Exception{
stage.setTitle("HİSTOGRAM");
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis(0,50,10);
final BarChart<String,Number> bc =
new BarChart<String,Number>(xAxis,yAxis);
bc.setTitle("HİSTOGRAM");
final VBox verticalbox = new VBox();
final HBox horizontalbox = new HBox();
final Button draw = new Button("DRAW");
CheckBox red = new CheckBox("RED");
red.setSelected(true);
CheckBox blue = new CheckBox("BLUE");
final TextField textfield = new TextField();
horizontalbox.setAlignment(Pos.BOTTOM_RIGHT);
horizontalbox.setSpacing(46);
String filename = textfield.getText();
XYChart.Series series1 = new XYChart.Series();
bc.setPrefSize(800, 600);
horizontalbox.getChildren().addAll(draw, red, blue,textfield);
verticalbox.getChildren().addAll(bc, horizontalbox);
horizontalbox.setPadding(new Insets(10, 10, 10, 50));
Scene scene = new Scene(new Group());
((Group)scene.getRoot()).getChildren().add(verticalbox);
stage.setScene(scene);
stage.show();
//Setting the button on action if its clicked
draw.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
hmw34.occur(textfield.getText(), series1);
bc.getData().add(series1);
bc.setLegendVisible(false);
} catch (FileNotFoundException e) {
System.out.println("Error : No such file");
}
}
});
// rengini düzenleyecek.
/** if (red.isSelected())
bc.setStyle("-fx-bar-fill: #000080;"); // red box checked
else if (blue.isSelected())
bc.setStyle("-fx-bar-fill: #b22222;");// The Blue check box checked*/
}
public static void main(String[] args) {
launch(args);
}
}
【问题讨论】:
-
您看过 Oracle 使用 JavaFX 图表的教程吗?
-
是的,我看。他们只给它;图表系列线 { -fx-stroke-width: 2px; -fx-效果:空; } .default-color0.chart-series-line { -fx-stroke: #e9967a; } .default-color1.chart-series-line { -fx-stroke: #f0e68c; } .default-color2.chart-series-line { -fx-stroke: #dda0dd; } 但我不知道如何在我的代码中使用。
-
您是否熟悉使用 CSS 为您的应用程序设置皮肤,如 link 中所述?
-
link 我没有这样做。一切看起来都很清楚,但它不起作用
标签: java css charts javafx bar-chart