title: How set color of BarChart in Javafx
body: <p>I have an app that reads file and shows a chart of number of occurrences of each letter in file (In my app file must be located at "C:/new1.txt").</p>
  
  <p>I want to set the color of bar depending on selected Radio Button but it does not change the colour.How can i set colour and where do i make mistake?</p>
  
  <p><a href="https://github.com/berkkarabacak/odevyeni/tree/master/src/sample" rel="nofollow">Github Link</a></p>
  
  <p>Controller Class:</p>
  
  <pre><code>package sample;
  
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.scene.Node;
  import javafx.scene.chart.BarChart;
  import javafx.scene.chart.CategoryAxis;
  import javafx.scene.chart.XYChart;
  import javafx.scene.control.RadioButton;
  import javafx.scene.control.ToggleGroup;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.Scanner;
  
  public class Controller {
      @FXML
      public BarChart&lt;String,Number&gt; barchart;
  
  
      @FXML
      RadioButton redbutton=new RadioButton("Red");
  
      @FXML
      RadioButton bluebutton=new RadioButton("Blue");
  
  
      @FXML
      ToggleGroup group=new ToggleGroup();
      public void selam(ActionEvent a){
  
          //Array to store number of occurrences of each letter in file
          //Ex = if exist 2 "a" and 4 "d" then counter[0]=2  and counter[3]=4
          int[] counter = new int[26];
  
  
          //Read file
          try {
              File file = new File("C:/new1.txt");
              Scanner scanner = new Scanner(file,"utf-8");
              while (scanner.hasNext()) {
                  char[] chars = scanner.nextLine().toLowerCase().toCharArray();
  
                  for (Character karakter : chars) {
                      if(Character.isLetter(karakter)) {
                          //add to array
                          counter[karakter - 'a']++;
                      }
                  }
              }
          } catch (FileNotFoundException e) {
  
              System.out.println("File does not exist");
  
          }
  
          char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
          int orderofletter=0;
          XYChart.Series series1 = new XYChart.Series();
          //Add number of occurrences of each letter to XY chart
          for (char c:alphabet){
              series1.getData().add(new XYChart.Data(String.valueOf(c), counter[orderofletter]));
              orderofletter++;
          }
  
  
          // CHANGE COLOR
          if(redbutton.isSelected()){
              barchart.setStyle("-fx-bar-fill: red;");
              System.out.println("Red");
  }
  
          if(bluebutton.isSelected()){
             barchart.setStyle("-fx-bar-fill: blue;");
          }
          //Add xychart to barchart
          barchart.getData().addAll(series1);
              }
  }
  </code></pre>
  
  <p>FXML class:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?import javafx.scene.chart.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  
  &lt;Pane id="mainpane" fx:id="mainpane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="590.0" prefWidth="1085.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller"&gt;
      &lt;children&gt;
          &lt;TextField layoutY="517.0" prefHeight="67.0" prefWidth="309.0" /&gt;
          &lt;BarChart fx:id="barchart" barGap="2.0" layoutY="8.0" prefHeight="498.0" prefWidth="1085.0" style="-fx-border-color: chartreuse;"&gt;
              &lt;xAxis&gt;
                  &lt;CategoryAxis endMargin="0.0" side="BOTTOM" startMargin="0.0" /&gt;
              &lt;/xAxis&gt;
              &lt;yAxis&gt;
                  &lt;NumberAxis prefHeight="364.0" prefWidth="33.0" side="LEFT" upperBound="0.0" /&gt;
              &lt;/yAxis&gt;
          &lt;/BarChart&gt;
          &lt;Button layoutX="447.0" layoutY="512.0" mnemonicParsing="false" onAction="#selam" prefHeight="67.0" prefWidth="139.0" text="Draw" /&gt;
        &lt;RadioButton fx:id="bluebutton" layoutX="324.0" layoutY="551.0" mnemonicParsing="false" text="Blue"&gt;
           &lt;toggleGroup&gt;
              &lt;ToggleGroup fx:id="group" /&gt;
           &lt;/toggleGroup&gt;
        &lt;/RadioButton&gt;
        &lt;RadioButton fx:id="redbutton" layoutX="324.0" layoutY="517.0" mnemonicParsing="false" text="Red" toggleGroup="$group" /&gt;
      &lt;/children&gt;
  &lt;/Pane&gt;
  </code></pre>