javaFX的StackedBarGraph值介于0.0和1.0之间,仅使用最近添加的系列。由于某种原因,它忘记了之前添加的系列。我该如何解决?
应该是这样(注意相对比例而不是实际值):
但实际上看起来像是:
Oracle网站(https://docs.oracle.com/javafx/2/charts/bar-chart.htm)的示例代码已修改为使用介于0.0和1.0之间的值:
package main;
import java.util.Arrays;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class Test extends Application {
final static String austria = "Austria";
final static String brazil = "Brazil";
final static String france = "France";
final static String italy = "Italy";
final static String usa = "USA";
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
final StackedBarChart<String, Number> sbc = new StackedBarChart<String, Number>(
xAxis, yAxis);
final XYChart.Series<String, Number> series1 = new XYChart.Series<String, Number>();
final XYChart.Series<String, Number> series2 = new XYChart.Series<String, Number>();
final XYChart.Series<String, Number> series3 = new XYChart.Series<String, Number>();
@Override
public void start(Stage stage) {
stage.setTitle("Bar Chart Sample");
sbc.setTitle("Country Summary");
xAxis.setLabel("Country");
xAxis.setCategories(FXCollections.<String> observableArrayList(Arrays.asList(austria, brazil, france, italy, usa)));
yAxis.setLabel("Value");
series1.setName("2003");
series1.getData().add(new XYChart.Data<String, Number>(austria, 0.02560134));
series1.getData().add(new XYChart.Data<String, Number>(brazil, 0.02014882));
series1.getData().add(new XYChart.Data<String, Number>(france, 0.01000000));
series1.getData().add(new XYChart.Data<String, Number>(italy, 0.03540715));
series1.getData().add(new XYChart.Data<String, Number>(usa, 0.01200000));
series2.setName("2004");
series2.getData().add(new XYChart.Data<String, Number>(austria, 0.05740185));
series2.getData().add(new XYChart.Data<String, Number>(brazil, 0.04194119));
series2.getData().add(new XYChart.Data<String, Number>(france, 0.04526337));
series2.getData().add(new XYChart.Data<String, Number>(italy, 0.11732016));
series2.getData().add(new XYChart.Data<String, Number>(usa, 0.01484527));
series3.setName("2005");
series3.getData().add(new XYChart.Data<String, Number>(austria, 0.4500065));
series3.getData().add(new XYChart.Data<String, Number>(brazil, 0.4483576));
series3.getData().add(new XYChart.Data<String, Number>(france, 0.1872218));
series3.getData().add(new XYChart.Data<String, Number>(italy, 0.1755731));
series3.getData().add(new XYChart.Data<String, Number>(usa, 0.9263368));
Scene scene = new Scene(sbc, 800, 600);
sbc.getData().addAll(series1, series2, series3);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
答案 0 :(得分:0)
看起来此问题与:JavaFx StackedBar Chart Issue
有关该文章的修复也适用于此问题。不幸的是,该修复涉及导入Oracle的一个私有软件包,这会限制解决方案的可移植性。
在那篇文章中,问题是负值。在我的帖子中,值介于0.0和1.0之间。