I've created my custom PieChart class to make my own Legend, in my program the pieChart as to be updated runtime and so as the Legend too, I know my code isn't well designed and I've used bad to solution to gain what I want but it works, and it's a private project so it don't need to be perfect. Anyway this is my code:
public class CustomPieChart extends PieChart {
public ScrollPane scrollPane = new ScrollPane();
public Legend theLegend;
public CustomPieChart(ObservableList<PieChart.Data> data){
super(data);
setTitle("MyTitle");
setLegendSide(Side.RIGHT);
setLabelsVisible(false);
((Legend)getLegend()).setVertical(true);
((Legend)getLegend()).setPrefColumns(1);
}
private void createScrollableLegend(){
setStartAngle(180);
setLabelLineLength(20);
if(getLegend()!= null){
theLegend=(Legend) getLegend();
theLegend.setPrefWidth(130);
scrollPane.setContent(theLegend);
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.maxHeightProperty().bind(heightProperty());
setLegend(scrollPane);
}
}
public void refreshChart(ObservableList<PieChart.Data> data){
if(getData()!=null){
getData().clear();
}
//This is the only way I found to "refresh" the values of the legend
CustomPieChart tmp = new CustomPieChart(data);
setLegend((Legend)tmp.getLegend());
setData(data);
createScrollableLegend();
}
}
What I'm trying to achieve is a scrollable Legend that goes vertical only instead this is what I got :
As you can see some of the element are displayed outside the Pane...
Be gentle I'm pretty noob ^^
