不是那么优雅,硬编码但直接的方式似乎再次与 CSS 一起玩:
/* The default css of chart legend in caspian. */
.chart-legend {
-fx-background-color: #cccccc, #eeeeee;
-fx-background-insets: 0,1;
-fx-background-radius: 6,5;
-fx-padding: 6px;
}
/* We customize the above default background-color to transparent for
the chart legend on the right side, in our own CSS file. */
#my-legend-on-the-right-side .chart-legend {
-fx-background-color: transparent;
-fx-background-insets: 0,1;
-fx-background-radius: 6,5;
-fx-padding: 6px;
}
/* Then we customize the legend on the left side by padding
it to the left while its background covers the legend on the right. */
#my-legend-on-the-left-side .chart-legend {
-fx-background-color: #cccccc, #eeeeee;
-fx-background-insets: 0,1;
-fx-background-radius: 6,5;
-fx-padding: 6px 300px 6px 6px;
}
通过设置 id 来使用它们:
barChartTotal.setId("my-legend-on-the-left-side");
barChartPhases.setId("my-legend-on-the-right-side");