Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove PieChart white border between slices? [closed]

Is it possible to remove this white border between PieChart slices in JavaFX? White border

I can't achieve it with the following style:

.chart-pie {
    -fx-border-width: 0px;
}
like image 565
TheZopo Avatar asked Jan 03 '23 09:01

TheZopo


2 Answers

It seems that the PieChart has an inset, i achieve it with :

.chart-pie {
    -fx-background-insets: 0;
    -fx-border-width: 0;
}

Pie Chart

It's not perfect but enought for me.

like image 170
TheZopo Avatar answered Jan 05 '23 16:01

TheZopo


By default, there is a gap between the parts and unfortunately, I haven't found how to change its width. However, you can create a border to fill the empty space (-fx-border-width: 1px) around the part using its color (-fx-border-color: derive(-fx-pie-color, 0%)). Create this stylesheet file.

.chart-pie {
    -fx-border-color: derive(-fx-pie-color, 0%);
    -fx-border-width: 1px;
}

Include it in the Scene.

Scene scene = new Scene(new Group());
scene.getStylesheets().add("style.css");

The result is displayed in the following picture. Feel free to adjust values to get the best result.

enter image description here

Edit: I have found that the -fx-background-insets controls the size between values separated by commas, as the documentation sais:

A series of size values or sets of four size values, separated by commas. A single size value means all insets are the same. Otherwise, the four values for each inset are given in the order top, right, bottom, left. Each comma-separated value or set of values in the series applies to the corresponding background color.

Thus the following style should give you the very same result:

.chart-pie {
    -fx-background-insets: 0;
    -fx-border-width: 0;
}

Edit2: Seems @TheZopo was a bit faster.

like image 35
Nikolas Charalambidis Avatar answered Jan 05 '23 16:01

Nikolas Charalambidis