Kröw
Kröw

Reputation: 322

Set JavaFX PieChart label color via css

I have a PieChart in my Java application which looks just like this:

PieChartFullImage

A picture of a label (very hard to see):

The Label

Since the pie chart is rendered on a solid gray background, (which is basically the same color as the labels' text) the labels are virtually invisible. So, my question is, is there any CSS code that would change the color of a PieChart label's text, and if so, what is it?

Upvotes: 2

Views: 3641

Answers (2)

Kröw
Kröw

Reputation: 322

So, the labels of a pie chart are Text objects, meaning that the CSS property -fx-text-fill does not work for them. Instead, the -fx-fill property changes their color.

Here is a screenshot of my Pie Chart with colored labels:

Colored Pie Chart

A simple line of CSS does the trick...

.chart-pie-label {-fx-fill: #ff4f0a;}

Upvotes: 3

GOXR3PLUS
GOXR3PLUS

Reputation: 7255

For any future users below is answer with css code:

You can find more here : http://docs.oracle.com/javafx/2/charts/css-styles.htm

.chart-pie-label-line {
    -fx-stroke: #8b4513;
    -fx-fill: #8b4513;
}

.chart-pie-label { /*this is what you need for labels*/
    -fx-fill: #8b4513;
    -fx-font-size: 1em;
} 
.chart-legend {
   -fx-background-color:  #fafad2;
   -fx-stroke: #daa520;
}

enter image description here

Upvotes: 5

Related Questions