我有一张图表,其中的数据堆叠在 (-,+)Y 轴上。
使用 JfreeChart,所有这些都可以顺利进行,并且数据在每个柱上完美显示而不会丢失。
但是当使用 javafx StackedBar Chart 时,当条形系列具有(正负)数据堆积条损坏和丢失数据时。
if (plusValue > 0) { series.getData().add(new XYChart.Data<String, Number>(xPoint, plusValue)); } if (minusValue > 0) { series.getData().add(new XYChart.Data<String, Number>(xPoint, -minusValue)); }
更新 :
- Oracle StackedBarChart 示例 - “我更改系列值”
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 StackedBarChartSample 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");
// plus value
series1.getData().add(new XYChart.Data<String, Number>(austria, 200));
series1.getData().add(new XYChart.Data<String, Number>(brazil, 300));
series1.getData().add(new XYChart.Data<String, Number>(france, 400));
series1.getData().add(new XYChart.Data<String, Number>(italy, 500));
series1.getData().add(new XYChart.Data<String, Number>(usa, 600));
// minus value
series1.getData().add(new XYChart.Data<String, Number>(austria, -200));
series1.getData().add(new XYChart.Data<String, Number>(brazil, -300));
series1.getData().add(new XYChart.Data<String, Number>(france, -400));
series1.getData().add(new XYChart.Data<String, Number>(italy, -500));
series1.getData().add(new XYChart.Data<String, Number>(usa, -600));
series2.setName("2004");
series2.getData().add(new XYChart.Data<String, Number>(austria, 200));
series2.getData().add(new XYChart.Data<String, Number>(brazil, 300));
series2.getData().add(new XYChart.Data<String, Number>(france, 400));
series2.getData().add(new XYChart.Data<String, Number>(italy, 500));
series2.getData().add(new XYChart.Data<String, Number>(usa, 600));
// minus value
series2.getData().add(new XYChart.Data<String, Number>(austria, -200));
series2.getData().add(new XYChart.Data<String, Number>(brazil, -300));
series2.getData().add(new XYChart.Data<String, Number>(france, -400));
series2.getData().add(new XYChart.Data<String, Number>(italy, -500));
series2.getData().add(new XYChart.Data<String, Number>(usa, -600));
series3.setName("2005");
series3.getData().add(new XYChart.Data<String, Number>(austria, 200));
series3.getData().add(new XYChart.Data<String, Number>(brazil, 300));
series3.getData().add(new XYChart.Data<String, Number>(france, 400));
series3.getData().add(new XYChart.Data<String, Number>(italy, 500));
series3.getData().add(new XYChart.Data<String, Number>(usa, 600));
// minus value
series3.getData().add(new XYChart.Data<String, Number>(austria, -200));
series3.getData().add(new XYChart.Data<String, Number>(brazil, -300));
series3.getData().add(new XYChart.Data<String, Number>(france, -400));
series3.getData().add(new XYChart.Data<String, Number>(italy, -500));
series3.getData().add(new XYChart.Data<String, Number>(usa, -600));
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);
}
}
- 无负值。
- 负值数据已损坏。