Chart -fx-background-color: rgba(0,168,355,0.05); : CSS « JavaFX « Java






Chart -fx-background-color: rgba(0,168,355,0.05);

 
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Main extends Application {
    
    final static String itemA = "A";
    final static String itemB = "B";
    final static String itemC = "F";
    @Override
    public void start(Stage stage) {
        final NumberAxis xAxis = new NumberAxis();
        final CategoryAxis yAxis = new CategoryAxis();
        final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis);
        bc.setTitle("Summary");
        bc.setStyle("-fx-background-color: rgba(0,168,355,0.05);-fx-background-radius: 10;");
        
        
        xAxis.setLabel("Value");
        xAxis.setTickLabelRotation(90);
        yAxis.setLabel("Item");
        

        XYChart.Series series1 = new XYChart.Series();
        series1.setName("2003");
        series1.getData().add(new XYChart.Data(2, itemA));
        series1.getData().add(new XYChart.Data(20, itemB));
        series1.getData().add(new XYChart.Data(10, itemC));

        XYChart.Series series2 = new XYChart.Series();
        series2.setName("2004");
        series2.getData().add(new XYChart.Data(50, itemA));
        series2.getData().add(new XYChart.Data(41, itemB));
        series2.getData().add(new XYChart.Data(45, itemC));

        XYChart.Series series3 = new XYChart.Series();
        series3.setName("2005");
        series3.getData().add(new XYChart.Data(45, itemA));
        series3.getData().add(new XYChart.Data(44, itemB));
        series3.getData().add(new XYChart.Data(18, itemC));

        Scene scene = new Scene(bc, 800, 600);
        bc.getData().addAll(series1, series2, series3);
        stage.setScene(scene);
        stage.show();
    }

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

   
  








Related examples in the same category

1.Using CSS to style the border
2.Connect to CSS Style Sheet in same Package
3.Connect to CSS Style Sheet in another Package
4.Set CSS style
5.-fx-stroke: green;
6.-fx-stroke-width: 5;
7.-fx-stroke-dash-array: 12 2 4 2;
8.-fx-stroke-dash-offset: 6;
9.-fx-stroke-line-cap: butt;
10.-fx-background-color: transparent;
11.-fx-border-color: white;
12.-fx-background-radius: 30;
13.-fx-border-radius: 30;
14.-fx-text-fill: white;
15.-fx-font-weight: bold;
16.-fx-font-size: 14px;
17.-fx-padding: 10 20 10 20;
18.Chart -fx-border-color: rgba(0,16,35,0.5) rgba(0,68,55,0.6) transparent rgba(0,68,55,0.7);
19.Set css file to Scene
20.Use addAll() to attach several stylesheets.
21.Set Control Id and use it in css
22.Sample application that shows the use of CSS with the different layout panes provided by the JavaFX layout API.
23.-fx-fill: red;