title: JavaFX, Stacked Bar Charts and CSS
body: <p>I've been using JavaFX now for a few months and have a question regarding CSS and Charts.  I have a stacked bar chart and I have several series I use - lets say they're series A, B, C, D and E.  When I generate the chart not all of the series will be in the chart, for example some charts may have A, B and C, others will have just B and E where another could have all 5.  Basically I am programmatically generating the series based upon the dataset I am working with.</p>
  
  <p>So in this case I want the color of the series to be the same on each chart.  When I generate these, if I only have B and E the css class names that reflect the colors of these are:</p>
  
  <p>.default-color0.chart-bar and .default-color1.chart-bar - and here these simply set the color of the series order - so series 1 will get the "..color0.chart.." definition, series 2 "..color1.chart.." etc.  And when I don't know before I process the data which one will be first I will need to set these dynamically in the code.</p>
  
  <p>The only solution I've found for this is to set the stylesheet of the stacked bar chart to a CSS file I created pre-compile.  And this works well, and below is an example of how I would do this in code.</p>
  
  <pre><code>myStackedBarChart.getStylesheets().add("/myapp/chartSeriesColors.css");
  </code></pre>
  
  <p>The only problem is because a series in position 1 is not known, I would have to create CSS files of each permutation of possible series and I know this is a bad solution.</p>
  
  <p>I've looked everywhere on a way to set the series CSS dynamically at run-time but have not found this - is there way to do this.  Basically wanting to set the following CSS class definitions as so:</p>
  
  <pre><code>.default-color0.chart-bar { -fx-bar-fill: #&lt;a color I would set at runtime&gt;; }
  .default-color1.chart-bar { -fx-bar-fill: #&lt;a color I would set at runtime&gt;; }
  </code></pre>
  
  <p>Any help would be appreciated.</p>