I am new to Java and so to JavaFX. I am trying to build a dynamic graph that displays live data using JavaFx LineChart.
I noticed in the oracle documentation http://docs.oracle.com/javafx/2/charts/css-styles.htm#CIHGIAGE that diagrams can be styled using CSS.
Can I programmatically change the color of a series?
public Node addLineChart(){ //final NumberAxis yAxis = new NumberAxis(-80,60,20); final NumberAxis yAxis; final CategoryAxis xAxis; if(firingOrderSelectionIndex >= 0){ String selectedFiringOrder = firingOrders[cylselectionIndex][firingOrderSelectionIndex]; String[] currentFiringOrder = selectedFiringOrder.split("-"); xAxis = new CategoryAxis(FXCollections.observableArrayList(currentFiringOrder)); xAxis.setAutoRanging(false); if(selectionIndex > 1){ yAxis = new NumberAxis(-60,40,20); }else{ yAxis = new NumberAxis(-75,50,15); } }else{ xAxis = new CategoryAxis(); yAxis = new NumberAxis(0,0,0); } xAxis.setLabel("Order"); xAxis.setStyle("-fx-font-size: 14;-fx-font-weight: bolder;"); //xAxis.setAutoRanging(false); //If you are manually setting values in the constructor you can do this. //otherwise if this is done, the graph will crash. So, while using constructor with no values leave this config as default. //xAxis.setLowerBound(1); //xAxis.setUpperBound(4); //xAxis.setTickUnit(1); yAxis.setMinorTickVisible(false); final LineChart<String,Number> lineChart = new LineChart<String,Number>(xAxis,yAxis); lineChart.setTitle("Graph"); lineChart.setLegendVisible(false); lineChart.setStyle(".default-color0.chart-series-line { -fx-stroke: #f0e68c; }"); //series.setName("Live"); series.getData().add(new XYChart.Data("1", 5)); series.getData().add(new XYChart.Data("2", 5)); lineChart.getData().add(series); xAxis.setVisible(false); return lineChart; }
source share