JavaFx adds text label on top of StackedBarChart

After search

  • I found this sample how to display the value of a bar on top of the javafx bar , but this is when the bar is divided on the category axis, so each category data has a single barand Listener can be added to this data (category).

  • But with StackedBarCharteach category consists of a StackedBar.

  • I will try code simple based on @jewelsea code.

  • This solution works as a prefect if all rows are symmetrical and contain all categories. symmetric Series

  • But with an asymmetric row

        ObservableList<StackedBarChart.Series> barChartData = FXCollections.observableArrayList(
            new StackedBarChart.Series("Region 1", FXCollections.observableArrayList(
            new StackedBarChart.Data(years[0], 567d),
            new StackedBarChart.Data(years[1], 1292d),
            new StackedBarChart.Data(years[2], 1292d))),
            new StackedBarChart.Series("Region 2", FXCollections.observableArrayList(
            new StackedBarChart.Data(years[0], 956),
            new StackedBarChart.Data(years[1], 1665),
            new StackedBarChart.Data(years[2], 2559))),
            new StackedBarChart.Series("Region 3", FXCollections.observableArrayList(
            new StackedBarChart.Data(years[0], 1154),
            //new StackedBarChart.Data(years[1], 1927),// series names Region 3(which is the last series on the chart data) doesn't exist category years[1] "2008".
            new StackedBarChart.Data(years[2], 2774))));
    
  • We will skip the text on top of the 2008 category . non-symmetric series miss text on the missing categories

  • Any help is appreciated.

+1
source share
1 answer

, :

    //new StackedBarChart.Data(years[1], 1927),// series names Region 3(which is the last series on the chart data) doesn't exist category years[1] "2008".

"1927". Y. , , "1927". API:

http://docs.oracle.com/javafx/2/api/javafx/scene/chart/StackedBarChart.html

, "" -. StackedBarChart.Series.

0

Source: https://habr.com/ru/post/1531071/


All Articles